ENH: Test export/import of link interface languages

This extends the ExportImport test.  The Export project creates a C++
static library and exports it.  Then the Import project links the
library into a C executable.  On most platforms the executable will link
only if the C++ linker is chosen correctly.
This commit is contained in:
Brad King 2009-07-11 10:10:51 -04:00
parent 28b1912aa3
commit 3621e073a8
7 changed files with 42 additions and 22 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 2.6) cmake_minimum_required (VERSION 2.7.20090711)
project(ExportImport C) project(ExportImport C CXX)
# Wipe out the install tree to make sure the exporter works. # Wipe out the install tree to make sure the exporter works.
add_custom_command( add_custom_command(
@ -22,6 +22,21 @@ else(CMAKE_CONFIGURATION_TYPES)
endif(CMAKE_BUILD_TYPE) endif(CMAKE_BUILD_TYPE)
endif(CMAKE_CONFIGURATION_TYPES) endif(CMAKE_CONFIGURATION_TYPES)
set(SAME_COMPILER
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
-DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
-DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}
-DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
-DCMAKE_CXX_FLAGS_DEBUG:STRING=${CMAKE_CXX_FLAGS_DEBUG}
-DCMAKE_CXX_FLAGS_RELEASE:STRING=${CMAKE_CXX_FLAGS_RELEASE}
-DCMAKE_CXX_FLAGS_MINSIZEREL:STRING=${CMAKE_CXX_FLAGS_MINSIZEREL}
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_CXX_FLAGS_RELWITHDEBINFO}
)
# Build and install the exporter. # Build and install the exporter.
add_custom_command( add_custom_command(
OUTPUT ${ExportImport_BINARY_DIR}/ExportProject OUTPUT ${ExportImport_BINARY_DIR}/ExportProject
@ -34,13 +49,7 @@ add_custom_command(
--build-target install --build-target install
--build-generator ${CMAKE_GENERATOR} --build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options --build-options ${SAME_COMPILER}
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
-DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
-DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}
-DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
-DCMAKE_INSTALL_PREFIX:STRING=${ExportImport_BINARY_DIR}/Root -DCMAKE_INSTALL_PREFIX:STRING=${ExportImport_BINARY_DIR}/Root
-DCMAKE_SKIP_RPATH:BOOL=ON -DCMAKE_SKIP_RPATH:BOOL=ON
) )
@ -62,13 +71,7 @@ add_custom_command(
--build-project Import --build-project Import
--build-generator ${CMAKE_GENERATOR} --build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options --build-options ${SAME_COMPILER}
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
-DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
-DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}
-DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
-DCMAKE_INSTALL_PREFIX:STRING=${ExportImport_BINARY_DIR}/Root -DCMAKE_INSTALL_PREFIX:STRING=${ExportImport_BINARY_DIR}/Root
-DCMAKE_SKIP_RPATH:BOOL=ON -DCMAKE_SKIP_RPATH:BOOL=ON
) )

View File

@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 2.6) cmake_minimum_required (VERSION 2.7.20090711)
project(Export C) project(Export C CXX)
# Pretend that RelWithDebInfo should link to debug libraries to test # Pretend that RelWithDebInfo should link to debug libraries to test
# the DEBUG_CONFIGURATIONS property. # the DEBUG_CONFIGURATIONS property.
@ -45,6 +45,8 @@ set_property(TARGET testLib4 PROPERTY FRAMEWORK 1)
add_library(testLib5 SHARED testLib5.c) add_library(testLib5 SHARED testLib5.c)
add_library(testLib6 STATIC testLib6.cxx testLib6.c)
# Work-around: Visual Studio 6 does not support per-target object files. # Work-around: Visual Studio 6 does not support per-target object files.
set(VS6) set(VS6)
if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6") if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6")
@ -76,6 +78,7 @@ install(
TARGETS TARGETS
testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3 testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3
testExe2lib testLib4lib testLib4libdbg testLib4libopt testExe2lib testLib4lib testLib4libdbg testLib4libopt
testLib6
EXPORT exp EXPORT exp
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
LIBRARY DESTINATION lib NAMELINK_SKIP LIBRARY DESTINATION lib NAMELINK_SKIP
@ -111,7 +114,7 @@ export(TARGETS testExe1 testLib1 testLib2 testLib3
NAMESPACE bld_ NAMESPACE bld_
FILE ExportBuildTree.cmake FILE ExportBuildTree.cmake
) )
export(TARGETS testExe2 testLib4 testLib5 testExe3 testExe2lib export(TARGETS testExe2 testLib4 testLib5 testLib6 testExe3 testExe2lib
testLib4lib testLib4libdbg testLib4libopt testLib4lib testLib4libdbg testLib4libopt
NAMESPACE bld_ NAMESPACE bld_
APPEND FILE ExportBuildTree.cmake APPEND FILE ExportBuildTree.cmake

View File

@ -0,0 +1,5 @@
extern int testLib6cxx(void);
int testLib6(void)
{
return testLib6cxx();
}

View File

@ -0,0 +1,6 @@
extern "C" int testLib6cxx(void)
{
// Reference C++ standard library symbols.
delete new int;
return 0;
}

View File

@ -28,6 +28,7 @@ target_link_libraries(imp_testExe1
exp_testLib3 exp_testLib3
exp_testLib4 exp_testLib4
exp_testLib5 exp_testLib5
exp_testLib6
) )
# Try building a plugin to an executable imported from the install tree. # Try building a plugin to an executable imported from the install tree.
@ -58,6 +59,7 @@ target_link_libraries(imp_testExe1b
bld_testLib3 bld_testLib3
bld_testLib4 bld_testLib4
bld_testLib5 bld_testLib5
bld_testLib6
) )
# Try building a plugin to an executable imported from the build tree. # Try building a plugin to an executable imported from the build tree.

View File

@ -5,6 +5,7 @@ extern int testLib3();
extern int testLib4(); extern int testLib4();
extern int testLib4lib(); extern int testLib4lib();
extern int testLib5(); extern int testLib5();
extern int testLib6();
/* Switch a symbol between debug and optimized builds to make sure the /* Switch a symbol between debug and optimized builds to make sure the
proper library is found from the testLib4 link interface. */ proper library is found from the testLib4 link interface. */
@ -18,6 +19,6 @@ extern testLib4libcfg(void);
int main() int main()
{ {
return (testLib2() + generated_by_testExe1() + testLib3() + testLib4() return (testLib2() + generated_by_testExe1() + testLib3() + testLib4()
+ testLib5() + testLib5() + testLib6()
+ generated_by_testExe3() + testLib4lib() + testLib4libcfg()); + generated_by_testExe3() + testLib4lib() + testLib4libcfg());
} }

View File

@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 2.6) cmake_minimum_required (VERSION 2.7.20090711)
project(Import C) project(Import C CXX)
# Import everything in a subdirectory. # Import everything in a subdirectory.
add_subdirectory(A) add_subdirectory(A)