diff options
Diffstat (limited to 'Tests/ExportImport/Import')
17 files changed, 184 insertions, 42 deletions
diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 01960ea19..b5df96168 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -1,3 +1,9 @@ +# Prepare imported targets that the exported project itself imported. +add_library(SubDirLinkAImported IMPORTED INTERFACE) +target_compile_definitions(SubDirLinkAImported INTERFACE DEF_SubDirLinkAImportedForImport) +add_library(SubDirLinkBImported IMPORTED INTERFACE) +target_compile_definitions(SubDirLinkBImported INTERFACE DEF_SubDirLinkBImportedForImport) + # Import targets from the exported build tree. include(${Import_BINARY_DIR}/../Export/ExportBuildTree.cmake) @@ -32,6 +38,20 @@ add_executable(imp_testExe1 ${Import_BINARY_DIR}/exp_generated4.c ) +function(checkForProperty _TARGET _PROP _EXPECTED) + get_target_property(EXPORTED_PROPERTY ${_TARGET} "${_PROP}") + if (NOT EXPORTED_PROPERTY STREQUAL "${_EXPECTED}") + message(SEND_ERROR "${_TARGET} was expected to export \"${_PROP}\" with value \"${_EXPECTED}\" but got \"${EXPORTED_PROPERTY}\"") + endif() +endfunction() + +checkForProperty(bld_testLib3 "EXPORTED_PROPERTY1" "EXPORTING_TESTLIB3") +checkForProperty(exp_testLib3 "EXPORTED_PROPERTY1" "EXPORTING_TESTLIB3") +checkForProperty(bld_testLib4 "EXPORTED_PROPERTY2" "EXPORTING_TESTLIB4_1") +checkForProperty(exp_testLib4 "EXPORTED_PROPERTY2" "EXPORTING_TESTLIB4_1") +checkForProperty(bld_testLib4 "EXPORTED_PROPERTY3" "EXPORTING_TESTLIB4_2") +checkForProperty(exp_testLib4 "EXPORTED_PROPERTY3" "EXPORTING_TESTLIB4_2") + # Try linking to a library imported from the install tree. target_link_libraries(imp_testExe1 exp_testLib2 @@ -144,6 +164,11 @@ target_link_libraries(cmp0022OLD_exp_test exp_cmp0022OLD) add_executable(cmp0022NEW_exp_test cmp0022NEW_test_vs6_2.cpp) target_link_libraries(cmp0022NEW_exp_test exp_cmp0022NEW) +add_executable(SubDirLink_bld SubDirLink.c) +target_link_libraries(SubDirLink_bld PRIVATE bld_TopDirLib bld_SubDirLinkA) +add_executable(SubDirLink_exp SubDirLink.c) +target_link_libraries(SubDirLink_exp PRIVATE exp_TopDirLib exp_SubDirLinkA) + # Try building a plugin to an executable imported from the build tree. add_library(imp_mod1b MODULE imp_mod1.c) target_link_libraries(imp_mod1b bld_testExe2) @@ -229,15 +254,44 @@ add_library(imp_lib1b STATIC imp_lib1.c) target_link_libraries(imp_lib1b bld_testLib2) if(NOT CMAKE_GENERATOR STREQUAL "Xcode" OR NOT CMAKE_OSX_ARCHITECTURES MATCHES "[;$]") - # Create a executable that is using objects imported from the install tree - add_executable(imp_testLib8 imp_testLib8.c $<TARGET_OBJECTS:exp_testLib8>) + set(bld_objlib_type OBJECT_LIBRARY) + + # Create executables using objects imported from the install tree + add_executable(imp_testLib8_src imp_testLib8.c $<TARGET_OBJECTS:exp_testLib8>) + add_executable(imp_testLib8_link imp_testLib8.c) + target_link_libraries(imp_testLib8_link exp_testLib8) if(NOT CMAKE_GENERATOR STREQUAL "Xcode" OR NOT XCODE_VERSION VERSION_LESS 5) - # Create a executable that is using objects imported from the build tree - add_executable(imp_testLib8b imp_testLib8.c $<TARGET_OBJECTS:bld_testLib8>) + # Create executables using objects imported from the build tree + add_executable(imp_testLib8b_src imp_testLib8.c $<TARGET_OBJECTS:bld_testLib8>) + add_executable(imp_testLib8b_link imp_testLib8.c) + target_link_libraries(imp_testLib8b_link bld_testLib8) endif() +else() + set(bld_objlib_type INTERFACE_LIBRARY) endif() +# Create an executable that uses a library imported from the install tree +# that itself was built using an object library. Verify we get the usage +# requirements. +add_executable(imp_testLib9 imp_testLib9.c) +target_link_libraries(imp_testLib9 exp_testLib9) +# Similarly for importing from the build tree. +add_executable(imp_testLib9b imp_testLib9.c) +target_link_libraries(imp_testLib9b bld_testLib9) + +# Check that object libraries were transformed on export as expected. +foreach(vis Pub Priv Iface) + get_property(type TARGET exp_testLib9Obj${vis} PROPERTY TYPE) + if(NOT type STREQUAL INTERFACE_LIBRARY) + message(FATAL_ERROR "exp_testLib9Obj${vis} type is '${type}', not 'INTERFACE_LIBRARY'") + endif() + get_property(type TARGET bld_testLib9Obj${vis} PROPERTY TYPE) + if(NOT type STREQUAL "${bld_objlib_type}") + message(FATAL_ERROR "bld_testLib9Obj${vis} type is '${type}', not '${bld_objlib_type}'") + endif() +endforeach() + #----------------------------------------------------------------------------- # Test that handling imported targets, including transitive dependencies, # works in CheckFunctionExists (...and hopefully all other try_compile() checks @@ -278,7 +332,6 @@ if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") 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() @@ -354,7 +407,7 @@ endforeach() unset(_configs) if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4) - OR CMAKE_C_COMPILER_ID STREQUAL Clang) + OR (CMAKE_C_COMPILER_ID STREQUAL Clang AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")) AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "Ninja")) include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test) @@ -429,3 +482,20 @@ if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREA endif() endif() endif() + +#--------------------------------------------------------------------------------- +# check that imported libraries have the expected INTERFACE_LINK_OPTIONS property +checkForProperty(bld_testLinkOptions "INTERFACE_LINK_OPTIONS" "INTERFACE_FLAG") +checkForProperty(Req::testLinkOptions "INTERFACE_LINK_OPTIONS" "INTERFACE_FLAG") + +#--------------------------------------------------------------------------------- +# check that imported libraries have the expected INTERFACE_LINK_DIRECTORIES property +checkForProperty(bld_testLinkDirectories "INTERFACE_LINK_DIRECTORIES" "/interface/build") +checkForProperty(Req::testLinkDirectories "INTERFACE_LINK_DIRECTORIES" "${CMAKE_INSTALL_PREFIX}/interface/install") + +#--------------------------------------------------------------------------------- +# check that imported libraries have the expected INTERFACE_LINK_DEPENDS property +if(CMAKE_GENERATOR MATCHES "Make|Ninja") + checkForProperty(bld_testLinkDepends "INTERFACE_LINK_DEPENDS" "BUILD_LINK_DEPENDS") + checkForProperty(Req::testLinkDepends "INTERFACE_LINK_DEPENDS" "${CMAKE_INSTALL_PREFIX}/INSTALL_LINK_DEPENDS") +endif() diff --git a/Tests/ExportImport/Import/A/SubDirLink.c b/Tests/ExportImport/Import/A/SubDirLink.c new file mode 100644 index 000000000..eb4b8609a --- /dev/null +++ b/Tests/ExportImport/Import/A/SubDirLink.c @@ -0,0 +1,14 @@ +#ifndef DEF_SubDirLinkAImportedForImport +# error "DEF_SubDirLinkAImportedForImport is not defined but should be!" +#endif +#ifndef DEF_SubDirLinkBImportedForImport +# error "DEF_SubDirLinkBImportedForImport is not defined but should be!" +#endif + +extern int testTopDirLib(void); +extern int testSubDirLinkA(void); + +int main(void) +{ + return (testTopDirLib() + testSubDirLinkA() + 0); +} diff --git a/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp b/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp index 587834987..778b8287e 100644 --- a/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp +++ b/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp @@ -1,9 +1,9 @@ #ifndef USING_TESTLIB2 -#error Expected USING_TESTLIB2 +# error Expected USING_TESTLIB2 #endif #ifdef USING_TESTLIB3 -#error Unexpected USING_TESTLIB3 +# error Unexpected USING_TESTLIB3 #endif int main(void) diff --git a/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp b/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp index e50158b76..9eaaee9b4 100644 --- a/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp +++ b/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp @@ -1,9 +1,9 @@ #ifdef USING_TESTLIB2 -#error Unexpected USING_TESTLIB2 +# error Unexpected USING_TESTLIB2 #endif #ifndef USING_TESTLIB3 -#error Expected USING_TESTLIB3 +# error Expected USING_TESTLIB3 #endif int main(void) diff --git a/Tests/ExportImport/Import/A/deps_iface.c b/Tests/ExportImport/Import/A/deps_iface.c index 1539bcb68..afb1af01f 100644 --- a/Tests/ExportImport/Import/A/deps_iface.c +++ b/Tests/ExportImport/Import/A/deps_iface.c @@ -1,9 +1,4 @@ -#include "testLibIncludeRequired1.h" -#include "testLibIncludeRequired2.h" -#include "testLibIncludeRequired6.h" -#include "testLibIncludeRequired7.h" - #include "installIncludesTest.h" #include "installIncludesTest2.h" #include "installIncludesTest3.h" @@ -12,17 +7,21 @@ #include "installIncludesTest6.h" #include "installIncludesTest7.h" #include "installIncludesTest8.h" +#include "testLibIncludeRequired1.h" +#include "testLibIncludeRequired2.h" +#include "testLibIncludeRequired6.h" +#include "testLibIncludeRequired7.h" #ifndef testLibRequired_IFACE_DEFINE -#error Expected testLibRequired_IFACE_DEFINE +# error Expected testLibRequired_IFACE_DEFINE #endif #ifdef BuildOnly_DEFINE -#error Unexpected BuildOnly_DEFINE +# error Unexpected BuildOnly_DEFINE #endif #ifndef InstallOnly_DEFINE -#error Expected InstallOnly_DEFINE +# error Expected InstallOnly_DEFINE #endif extern int testLibDepends(void); diff --git a/Tests/ExportImport/Import/A/deps_shared_iface.cpp b/Tests/ExportImport/Import/A/deps_shared_iface.cpp index 3658ab548..d239fb418 100644 --- a/Tests/ExportImport/Import/A/deps_shared_iface.cpp +++ b/Tests/ExportImport/Import/A/deps_shared_iface.cpp @@ -3,32 +3,32 @@ #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 +# if defined(__ELF__) && !defined(__PIC__) && !defined(__PIE__) +# error Expected by INTERFACE_POSITION_INDEPENDENT_CODE property of dependency +# endif #endif #ifndef PIC_PROPERTY_IS_ON -#error Expected PIC_PROPERTY_IS_ON +# error Expected PIC_PROPERTY_IS_ON #endif #ifndef CUSTOM_PROPERTY_IS_ON -#error Expected CUSTOM_PROPERTY_IS_ON +# error Expected CUSTOM_PROPERTY_IS_ON #endif #ifndef CUSTOM_STRING_IS_MATCH -#error Expected CUSTOM_STRING_IS_MATCH +# error Expected CUSTOM_STRING_IS_MATCH #endif #ifdef TEST_SUBDIR_LIB -#include "renamed.h" -#include "subdir.h" +# include "renamed.h" +# include "subdir.h" #endif #ifdef DO_GNU_TESTS -#ifndef CUSTOM_COMPILE_OPTION -#error Expected CUSTOM_COMPILE_OPTION -#endif +# ifndef CUSTOM_COMPILE_OPTION +# error Expected CUSTOM_COMPILE_OPTION +# endif #endif int main(int, char**) diff --git a/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp b/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp index 357f64f02..ddb8c4b35 100644 --- a/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp +++ b/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp @@ -2,5 +2,5 @@ #include <testLib4/testLib4.h> #ifndef TESTLIB4_H -#error Expected define TESTLIB4_H +# error Expected define TESTLIB4_H #endif diff --git a/Tests/ExportImport/Import/A/iface_test.cpp b/Tests/ExportImport/Import/A/iface_test.cpp index fa4474bdb..4428c1c50 100644 --- a/Tests/ExportImport/Import/A/iface_test.cpp +++ b/Tests/ExportImport/Import/A/iface_test.cpp @@ -1,6 +1,6 @@ #ifndef USING_TESTSHAREDLIBREQUIRED -#error Expected USING_TESTSHAREDLIBREQUIRED +# error Expected USING_TESTSHAREDLIBREQUIRED #endif #include "excludedFromAll.h" diff --git a/Tests/ExportImport/Import/A/imp_mod1.c b/Tests/ExportImport/Import/A/imp_mod1.c index 89d754595..9385d5519 100644 --- a/Tests/ExportImport/Import/A/imp_mod1.c +++ b/Tests/ExportImport/Import/A/imp_mod1.c @@ -1,7 +1,7 @@ #if defined(_WIN32) || defined(__CYGWIN__) -#define testExe2_IMPORT __declspec(dllimport) +# define testExe2_IMPORT __declspec(dllimport) #else -#define testExe2_IMPORT +# define testExe2_IMPORT #endif testExe2_IMPORT int testExe2Func(void); diff --git a/Tests/ExportImport/Import/A/imp_testExe1.c b/Tests/ExportImport/Import/A/imp_testExe1.c index 348843928..8173557cd 100644 --- a/Tests/ExportImport/Import/A/imp_testExe1.c +++ b/Tests/ExportImport/Import/A/imp_testExe1.c @@ -14,9 +14,9 @@ extern int testLibPerConfigDest(void); /* Switch a symbol between debug and optimized builds to make sure the proper library is found from the testLib4 link interface. */ #ifdef EXE_DBG -#define testLib4libcfg testLib4libdbg +# define testLib4libcfg testLib4libdbg #else -#define testLib4libcfg testLib4libopt +# define testLib4libcfg testLib4libopt #endif extern testLib4libcfg(void); diff --git a/Tests/ExportImport/Import/A/imp_testExeAbs1.c b/Tests/ExportImport/Import/A/imp_testExeAbs1.c index 629b891f1..fd0524206 100644 --- a/Tests/ExportImport/Import/A/imp_testExeAbs1.c +++ b/Tests/ExportImport/Import/A/imp_testExeAbs1.c @@ -2,10 +2,10 @@ #include "testLibAbs1a.h" #include "testLibAbs1b.h" #ifndef testLibAbs1a -#error "testLibAbs1a not defined" +# error "testLibAbs1a not defined" #endif #ifndef testLibAbs1b -#error "testLibAbs1b not defined" +# error "testLibAbs1b not defined" #endif int main() { diff --git a/Tests/ExportImport/Import/A/imp_testLib9.c b/Tests/ExportImport/Import/A/imp_testLib9.c new file mode 100644 index 000000000..e014857ec --- /dev/null +++ b/Tests/ExportImport/Import/A/imp_testLib9.c @@ -0,0 +1,16 @@ +#ifndef testLib9ObjPub_USED +# error "testLib9ObjPub_USED not defined!" +#endif +#ifdef testLib9ObjPriv_USED +# error "testLib9ObjPriv_USED defined but should not be!" +#endif +#ifndef testLib9ObjIface_USED +# error "testLib9ObjIface_USED not defined!" +#endif + +int testLib9(void); + +int main() +{ + return testLib9(); +} diff --git a/Tests/ExportImport/Import/A/imp_testLinkOptions.cpp b/Tests/ExportImport/Import/A/imp_testLinkOptions.cpp new file mode 100644 index 000000000..2b18b2e09 --- /dev/null +++ b/Tests/ExportImport/Import/A/imp_testLinkOptions.cpp @@ -0,0 +1,8 @@ + +#include "testSharedLibRequired.h" + +int foo() +{ + TestSharedLibRequired req; + return req.foo(); +} diff --git a/Tests/ExportImport/Import/Interface/CMakeLists.txt b/Tests/ExportImport/Import/Interface/CMakeLists.txt index c850508e5..ef666b1a7 100644 --- a/Tests/ExportImport/Import/Interface/CMakeLists.txt +++ b/Tests/ExportImport/Import/Interface/CMakeLists.txt @@ -98,6 +98,17 @@ set_property(TARGET exp::sharediface APPEND PROPERTY INTERFACE_LINK_LIBRARIES de add_executable(interfacetest_exp interfacetest.cpp) target_link_libraries(interfacetest_exp exp::sharediface) +if(NOT CMAKE_OSX_ARCHITECTURES MATCHES "[;$]" OR CMAKE_GENERATOR STREQUAL "Xcode") + add_executable(pch_iface_test_bld pch_iface_test.cpp) + target_link_libraries(pch_iface_test_bld bld::pch_iface) + add_executable(pch_iface_test_exp pch_iface_test.cpp) + target_link_libraries(pch_iface_test_exp exp::pch_iface) + if(CMAKE_CXX_COMPILE_OPTIONS_USE_PCH) + target_compile_definitions(pch_iface_test_bld PRIVATE EXPECT_PCH) + target_compile_definitions(pch_iface_test_exp PRIVATE EXPECT_PCH) + endif() +endif() + do_try_compile(exp) foreach(ns exp bld) @@ -109,4 +120,12 @@ foreach(ns exp bld) "not\n" " " [[DEF="\"\$\B"]] "\n") endif() + get_property(custom TARGET ${ns}::cmakeonly PROPERTY custom_property) + if(NOT custom STREQUAL "CustomPropertyValue") + message(SEND_ERROR + "${ns}::cmakeonly property custom_property is:\n" + " ${custom}\n" + "not\n" + " CustomPropertyValue\n") + endif() endforeach() diff --git a/Tests/ExportImport/Import/Interface/headeronlytest.cpp b/Tests/ExportImport/Import/Interface/headeronlytest.cpp index 0e754e9e3..7b63a0496 100644 --- a/Tests/ExportImport/Import/Interface/headeronlytest.cpp +++ b/Tests/ExportImport/Import/Interface/headeronlytest.cpp @@ -2,11 +2,11 @@ #include "headeronly.h" #ifndef HEADERONLY_DEFINE -#error Expected HEADERONLY_DEFINE +# error Expected HEADERONLY_DEFINE #endif #ifdef SHAREDLIB_DEFINE -#error Unexpected SHAREDLIB_DEFINE +# error Unexpected SHAREDLIB_DEFINE #endif int main(int, char**) diff --git a/Tests/ExportImport/Import/Interface/interfacetest.cpp b/Tests/ExportImport/Import/Interface/interfacetest.cpp index 7be816286..c1e29c246 100644 --- a/Tests/ExportImport/Import/Interface/interfacetest.cpp +++ b/Tests/ExportImport/Import/Interface/interfacetest.cpp @@ -2,15 +2,15 @@ #include "sharedlib.h" #ifndef SHAREDLIB_DEFINE -#error Expected SHAREDLIB_DEFINE +# error Expected SHAREDLIB_DEFINE #endif #ifdef HEADERONLY_DEFINE -#error Unexpected HEADERONLY_DEFINE +# error Unexpected HEADERONLY_DEFINE #endif #ifndef DEFINE_IFACE_DEFINE -#error Expected DEFINE_IFACE_DEFINE +# error Expected DEFINE_IFACE_DEFINE #endif int main(int, char**) diff --git a/Tests/ExportImport/Import/Interface/pch_iface_test.cpp b/Tests/ExportImport/Import/Interface/pch_iface_test.cpp new file mode 100644 index 000000000..a18bbde23 --- /dev/null +++ b/Tests/ExportImport/Import/Interface/pch_iface_test.cpp @@ -0,0 +1,16 @@ +#ifdef EXPECT_PCH +// Verify that pch/pch.h was included via '-include ...' or equivalent. +# ifndef PCH_PCH_H_INCLUDED +# error "Expected PCH_PCH_H_INCLUDED." +# endif +#elif defined(__PGIC__) || defined(__ibmxl__) || defined(_CRAYC) +// No PCH expected but these compilers define macros below. +#elif defined(__GNUC__) || defined(__clang__) || defined(_INTEL_COMPILER) || \ + defined(_MSC_VER) +# error "Expected EXPECT_PCH for this compiler." +#endif + +int main() +{ + return 0; +} |