Merge topic 'test-export-iface-genex'

1d74ba2 Test evaluation target via export for generator expressions
522bdac Export the INTERFACE_PIC property.
4ee872c Make the BUILD_INTERFACE of export()ed targets work.
1d47cd9 Add a test for the interfaces in targets exported from the build tree.
6c828f9 Move the exported check for file existence.
cfd4f0a Move the exported check for dependencies of targets
d8fe1fc Only generate one check per missing target.
f623d37 Don't write a comment in the export file without the code.
b279f2b Strip consecutive semicolons when preprocessing genex strings.
This commit is contained in:
Brad King
2013-01-15 14:43:05 -05:00
committed by CMake Topic Stage
16 changed files with 216 additions and 66 deletions
+9 -2
View File
@@ -162,6 +162,10 @@ include(GenerateExportHeader)
add_library(testSharedLibRequired SHARED testSharedLibRequired.cpp)
generate_export_header(testSharedLibRequired)
set_property(TARGET testSharedLibRequired
PROPERTY
INTERFACE_POSITION_INDEPENDENT_CODE ON
)
set_property(TARGET testSharedLibRequired APPEND PROPERTY
INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}"
)
@@ -182,7 +186,7 @@ set_property(TARGET testSharedLibDepends APPEND PROPERTY
)
set_property(TARGET testSharedLibDepends APPEND PROPERTY
LINK_INTERFACE_LIBRARIES
$<1:$<TARGET_NAME:testSharedLibRequired>>
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:$<TARGET_NAME:testSharedLibRequired>>
)
# LINK_PRIVATE because the LINK_INTERFACE_LIBRARIES is specified above.
@@ -247,9 +251,12 @@ if(WIN32)
install(TARGETS testLib5 RUNTIME DESTINATION bin)
endif()
add_subdirectory(sublib) # For CMAKE_BUILD_INTERFACE_INCLUDES test.
# Export from build tree.
export(TARGETS testExe1 testLib1 testLib2 testLib3
testExe2libImp testLib3Imp testLib3ImpDep
testExe2libImp testLib3Imp testLib3ImpDep subdirlib
testSharedLibRequired testSharedLibDepends
NAMESPACE bld_
FILE ExportBuildTree.cmake
)
@@ -0,0 +1,6 @@
set(CMAKE_BUILD_INTERFACE_INCLUDES ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_library(subdirlib SHARED subdir.cpp)
generate_export_header(subdirlib)
@@ -0,0 +1,7 @@
#include "subdir.h"
int SubDirObject::foo()
{
return 0;
}
+12
View File
@@ -0,0 +1,12 @@
#ifndef SUBDIR_H
#define SUBDIR_H
#include "subdirlib_export.h"
struct SUBDIRLIB_EXPORT SubDirObject
{
int foo();
};
#endif
+32 -15
View File
@@ -159,22 +159,39 @@ endif()
add_executable(deps_iface deps_iface.c)
target_link_libraries(deps_iface testLibDepends)
set_property(TARGET deps_iface APPEND PROPERTY
COMPILE_DEFINITIONS
$<TARGET_PROPERTY:testLibDepends,INTERFACE_COMPILE_DEFINITIONS>
)
set_property(TARGET deps_iface APPEND PROPERTY
INCLUDE_DIRECTORIES
$<TARGET_PROPERTY:testLibDepends,INTERFACE_INCLUDE_DIRECTORIES>
)
target_include_directories(deps_iface PRIVATE testLibDepends)
target_compile_definitions(deps_iface PRIVATE testLibDepends)
add_executable(deps_shared_iface deps_shared_iface.cpp)
target_link_libraries(deps_shared_iface testSharedLibDepends)
set_property(TARGET deps_shared_iface APPEND PROPERTY
COMPILE_DEFINITIONS
$<TARGET_PROPERTY:testSharedLibDepends,INTERFACE_COMPILE_DEFINITIONS>
)
set_property(TARGET deps_shared_iface APPEND PROPERTY
INCLUDE_DIRECTORIES
$<TARGET_PROPERTY:testSharedLibDepends,INTERFACE_INCLUDE_DIRECTORIES>
target_include_directories(deps_shared_iface PRIVATE testSharedLibDepends)
target_compile_definitions(deps_shared_iface PRIVATE testSharedLibDepends)
if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fPIE run_pic_test)
else()
if (CMAKE_CXX_COMPILER_ID MATCHES "PGI"
OR CMAKE_CXX_COMPILER_ID MATCHES "PathScale"
OR CMAKE_SYSTEM_NAME MATCHES "IRIX64"
OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(run_pic_test 0)
else()
set(run_pic_test 1)
endif()
endif()
if (run_pic_test)
target_compile_definitions(deps_shared_iface PRIVATE CHECK_PIC_WORKS)
endif()
#-----------------------------------------------------------------------------
# Test that targets imported from the build tree have their dependencies
# evaluated correctly. The above already tests the same for the install tree.
add_executable(deps_shared_iface2 deps_shared_iface.cpp)
target_link_libraries(deps_shared_iface2 bld_testSharedLibDepends bld_subdirlib)
target_include_directories(deps_shared_iface2 PRIVATE bld_testSharedLibDepends bld_subdirlib)
target_compile_definitions(deps_shared_iface2
PRIVATE bld_testSharedLibDepends TEST_SUBDIR_LIB
)
@@ -2,10 +2,28 @@
#include "testSharedLibDepends.h"
#ifdef CHECK_PIC_WORKS
#if defined(__ELF__) && !defined(__PIC__) && !defined(__PIE__)
#error Expected by INTERFACE_POSITION_INDEPENDENT_CODE property of dependency
#endif
#endif
#ifdef TEST_SUBDIR_LIB
#include "subdir.h"
#endif
int main(int,char **)
{
TestSharedLibDepends dep;
TestSharedLibRequired req;
return dep.foo() + req.foo();
#ifdef TEST_SUBDIR_LIB
SubDirObject sdo;
#endif
return dep.foo() + req.foo()
#ifdef TEST_SUBDIR_LIB
+ sdo.foo()
#endif
;
}