diff options
author | Brad King <brad.king@kitware.com> | 2012-03-14 13:24:26 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2012-03-16 14:12:30 (GMT) |
commit | c3242500b62c3f81af46e086cc2225b53c023167 (patch) | |
tree | 48775b5f5b7bf192b1486cbb336e6e8430921510 /Tests | |
parent | db7ef82402bed3d941bea73d266ac5919f4eee15 (diff) | |
download | CMake-c3242500b62c3f81af46e086cc2225b53c023167.zip CMake-c3242500b62c3f81af46e086cc2225b53c023167.tar.gz CMake-c3242500b62c3f81af46e086cc2225b53c023167.tar.bz2 |
Test OBJECT library use without other sources
Reference OBJECT libraries for inclusion in targets that have no other
sources to verify that the linker language propagates correctly from the
object libraries. Test with a STATIC library, a SHARED library, and an
EXECUTABLE target. Use the static and shared libraries each in
executables that end up using the object library symbols.
In VS 6, 7, and 7.1 add a dummy object file to convince the IDE to build
the targets without sources. In Xcode add a dummy source file to
convince it to build targets without sources.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/ObjectLibrary/AB.def | 5 | ||||
-rw-r--r-- | Tests/ObjectLibrary/CMakeLists.txt | 36 | ||||
-rw-r--r-- | Tests/ObjectLibrary/dummy.c | 1 | ||||
-rw-r--r-- | Tests/ObjectLibrary/dummy.obj | bin | 0 -> 498 bytes | |||
-rw-r--r-- | Tests/ObjectLibrary/mainAB.c | 22 |
5 files changed, 64 insertions, 0 deletions
diff --git a/Tests/ObjectLibrary/AB.def b/Tests/ObjectLibrary/AB.def new file mode 100644 index 0000000..3f2b5c0 --- /dev/null +++ b/Tests/ObjectLibrary/AB.def @@ -0,0 +1,5 @@ +EXPORTS +a1 +a2 +b1 +b2 diff --git a/Tests/ObjectLibrary/CMakeLists.txt b/Tests/ObjectLibrary/CMakeLists.txt index 1a07d1d..8723415 100644 --- a/Tests/ObjectLibrary/CMakeLists.txt +++ b/Tests/ObjectLibrary/CMakeLists.txt @@ -14,3 +14,39 @@ set_property(TARGET UseCshared PROPERTY COMPILE_DEFINITIONS SHARED_C) target_link_libraries(UseCshared Cshared) add_executable(UseCinternal main.c c.c $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>) + +if("${CMAKE_GENERATOR}" MATCHES "^Visual Studio (6|7|7 .NET 2003)$") + # VS 6 and 7 generators do not add objects as sources so we need a + # dummy object to convince the IDE to build the targets below. + set(dummy dummy.obj) # In MinGW: gcc -c dummy.c -o dummy.obj +elseif("${CMAKE_GENERATOR}" MATCHES "Xcode") + # Xcode does not seem to support targets without sources. + set(dummy dummy.c) +endif() + +# Test static library without its own sources. +add_library(ABstatic STATIC ${dummy} $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>) +add_executable(UseABstatic mainAB.c) +target_link_libraries(UseABstatic ABstatic) + +# Test module definition file to export object library symbols in the test +# below if the platform needs and supports it. +set(ABshared_SRCS $<TARGET_OBJECTS:A>) +if(CMAKE_LINK_DEF_FILE_FLAG OR NOT WIN32) + list(APPEND ABshared_SRCS $<TARGET_OBJECTS:B> AB.def) +else() + set(NO_A NO_A) + list(APPEND ABshared_SRCS $<TARGET_OBJECTS:Bexport>) +endif() + +# Test shared library without its own sources. +add_library(ABshared SHARED ${dummy} ${ABshared_SRCS}) +add_executable(UseABshared mainAB.c) +set_property(TARGET UseABshared PROPERTY COMPILE_DEFINITIONS SHARED_B ${NO_A}) +target_link_libraries(UseABshared ABshared) + +# Test executable without its own sources. +add_library(ABmain OBJECT mainAB.c) +add_executable(UseABinternal ${dummy} + $<TARGET_OBJECTS:ABmain> $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B> + ) diff --git a/Tests/ObjectLibrary/dummy.c b/Tests/ObjectLibrary/dummy.c new file mode 100644 index 0000000..2b17d81 --- /dev/null +++ b/Tests/ObjectLibrary/dummy.c @@ -0,0 +1 @@ +int dummy(void) {return 0;} diff --git a/Tests/ObjectLibrary/dummy.obj b/Tests/ObjectLibrary/dummy.obj Binary files differnew file mode 100644 index 0000000..77f6f2f --- /dev/null +++ b/Tests/ObjectLibrary/dummy.obj diff --git a/Tests/ObjectLibrary/mainAB.c b/Tests/ObjectLibrary/mainAB.c new file mode 100644 index 0000000..556898b --- /dev/null +++ b/Tests/ObjectLibrary/mainAB.c @@ -0,0 +1,22 @@ +#if defined(_WIN32) && defined(SHARED_B) +# define IMPORT_B __declspec(dllimport) +#else +# define IMPORT_B +#endif +extern IMPORT_B int b1(void); +extern IMPORT_B int b2(void); +#ifndef NO_A +extern int a1(void); +extern int a2(void); +#endif +int main(void) +{ + return 0 +#ifndef NO_A + + a1() + + a2() +#endif + + b1() + + b2() + ; +} |