This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake".
The branch, next has been updated via 9e7fde55127cb2bd1e9ab52d97b43db09ad89a16 (commit) via e3b6c57ed92b5e48babd9bf245c46f7df830b97a (commit) via 42e749c53f466f6d1246f37fbfeb9aa371cd270f (commit) from 8129c3296c615adab5538dbc171c5364a04d50f5 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9e7fde55127cb2bd1e9ab52d97b43db09ad89a16 commit 9e7fde55127cb2bd1e9ab52d97b43db09ad89a16 Merge: 8129c32 e3b6c57 Author: Brad King <brad.k...@kitware.com> AuthorDate: Wed Nov 23 08:33:27 2011 -0500 Commit: CMake Topic Stage <kwro...@kitware.com> CommitDate: Wed Nov 23 08:33:27 2011 -0500 Merge topic 'test-target_link_libraries' into next e3b6c57 Fail softly instead of fatally. 42e749c Add some unit tests for the target_link_libraries command http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e3b6c57ed92b5e48babd9bf245c46f7df830b97a commit e3b6c57ed92b5e48babd9bf245c46f7df830b97a Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Tue Oct 25 22:17:33 2011 +0200 Commit: Brad King <brad.k...@kitware.com> CommitDate: Wed Nov 23 08:27:24 2011 -0500 Fail softly instead of fatally. On some platforms LINK_INTERFACE_LIBRARIES does not work. Don't run the unit tests if so. diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt index e98734a..6df1b4c 100644 --- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt +++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt @@ -57,6 +57,17 @@ target_link_libraries(targetA depB depC) assert_property(targetA LINK_INTERFACE_LIBRARIES "") +try_compile(LINK_INTERFACE_LIBRARIES_FAILS + "${CMAKE_CURRENT_BINARY_DIR}/control_point" + "${CMAKE_CURRENT_SOURCE_DIR}/control_point" + control_point +) + +if (LINK_INTERFACE_LIBRARIES_FAILS) + message("\n\n#######################\nTHIS PLATFORM DOES NOT SUPPORT LINK_INTERFACE_LIBRARIES\n\n") + return() +endif() + set(Bools True False) foreach(B1 ${Bools}) @@ -111,9 +122,10 @@ foreach(B1 ${Bools}) OUTPUT_VARIABLE Out ) if (NOT Result) - message(SEND_ERROR "Could not build shared library - Libs CLEAR_LINK_INTERFACE_LIBRARIES: ${B1} - Libs SPECIFY_LINK_INTERFACE_LIBRARIES: ${B2}\n\n\n${Out}") + message("Libs CLEAR_LINK_INTERFACE_LIBRARIES: ${B1}\n" + "Libs SPECIFY_LINK_INTERFACE_LIBRARIES: ${B2}\n\n\n${Out}") + message("\n\n#######################\nTHIS PLATFORM DOES NOT SUPPORT LINK_INTERFACE_LIBRARIES\n\n") + return() endif() endforeach() endforeach() diff --git a/Tests/CMakeCommands/target_link_libraries/control_point/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/control_point/CMakeLists.txt new file mode 100644 index 0000000..e41c3f1 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/control_point/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 2.8) + +project(src) + +include(CheckCXXCompilerFlag) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_VERBOSE_MAKEFILE ON) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + +add_subdirectory(lib) + +include_directories( + "${CMAKE_CURRENT_SOURCE_DIR}/lib" + "${CMAKE_CURRENT_BINARY_DIR}/lib" +) + + +add_executable(exec + "main.cpp" +) + +target_link_libraries(exec libB ) diff --git a/Tests/CMakeCommands/target_link_libraries/control_point/lib/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/control_point/lib/CMakeLists.txt new file mode 100644 index 0000000..c0d1353 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/control_point/lib/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 2.8) + +project(libs) + +include(CheckCXXCompilerFlag) +include(GenerateExportHeader) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_VERBOSE_MAKEFILE ON) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + +add_library(libA SHARED classA.cpp) +add_library(libB SHARED classB.cpp) + +generate_export_header(libA) +generate_export_header(libB) + +target_link_libraries(libB libA) + +target_link_libraries(libA LINK_INTERFACE_LIBRARIES "") +target_link_libraries(libB LINK_INTERFACE_LIBRARIES "") diff --git a/Tests/CMakeCommands/target_link_libraries/control_point/lib/classA.cpp b/Tests/CMakeCommands/target_link_libraries/control_point/lib/classA.cpp new file mode 100644 index 0000000..f5e7106 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/control_point/lib/classA.cpp @@ -0,0 +1,7 @@ + +#include "classA.h" + +classA::classA() +{ + +} diff --git a/Tests/CMakeCommands/target_link_libraries/control_point/lib/classA.h b/Tests/CMakeCommands/target_link_libraries/control_point/lib/classA.h new file mode 100644 index 0000000..4d568e3 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/control_point/lib/classA.h @@ -0,0 +1,13 @@ + +#ifndef CLASS_A_H +#define CLASS_A_H + +#include "liba_export.h" + +class LIBA_EXPORT classA +{ +public: + classA(); +}; + +#endif diff --git a/Tests/CMakeCommands/target_link_libraries/control_point/lib/classB.cpp b/Tests/CMakeCommands/target_link_libraries/control_point/lib/classB.cpp new file mode 100644 index 0000000..e309586 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/control_point/lib/classB.cpp @@ -0,0 +1,13 @@ + +#include "classB.h" + +#include "classA.h" + +classB::classB() +{ +} + +classA* classB::a() const +{ + return new classA(); +} diff --git a/Tests/CMakeCommands/target_link_libraries/control_point/lib/classB.h b/Tests/CMakeCommands/target_link_libraries/control_point/lib/classB.h new file mode 100644 index 0000000..e0baed6 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/control_point/lib/classB.h @@ -0,0 +1,17 @@ + +#ifndef CLASS_B_H +#define CLASS_B_H + +#include "libb_export.h" + +class classA; + +class LIBB_EXPORT classB +{ +public: + classB(); + + classA* a() const; +}; + +#endif diff --git a/Tests/CMakeCommands/target_link_libraries/control_point/main.cpp b/Tests/CMakeCommands/target_link_libraries/control_point/main.cpp new file mode 100644 index 0000000..e5472cf --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/control_point/main.cpp @@ -0,0 +1,10 @@ +#include "classB.h" +#include "classA.h" + +int main(int, char **) { + + classB classB_; + classA classA_; + + return 0; +} http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=42e749c53f466f6d1246f37fbfeb9aa371cd270f commit 42e749c53f466f6d1246f37fbfeb9aa371cd270f Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Tue Oct 25 22:16:31 2011 +0200 Commit: Brad King <brad.k...@kitware.com> CommitDate: Wed Nov 23 08:26:57 2011 -0500 Add some unit tests for the target_link_libraries command diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt index 1faa888..e98734a 100644 --- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt +++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt @@ -56,3 +56,260 @@ assert_property(targetA LINK_INTERFACE_LIBRARIES "") target_link_libraries(targetA depB depC) assert_property(targetA LINK_INTERFACE_LIBRARIES "") + +set(Bools True False) + +foreach(B1 ${Bools}) + foreach(B2 ${Bools}) + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}/libs" + "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}" + ) + endforeach() +endforeach() + +foreach(B1 ${Bools}) + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_True_${B1}/CMakeLists.txt" + "set(CMAKE_LINK_INTERFACE_LIBRARIES \"\")\n" + ) +endforeach() + +foreach(B1 ${Bools}) + foreach(B2 ${Bools}) + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}/CMakeLists.txt" + + "add_library(libA SHARED classA.cpp)\n" + "add_library(libB SHARED classB.cpp)\n" + "add_library(libC SHARED classC.cpp)\n" + + "generate_export_header(libA)\n" + "generate_export_header(libB)\n" + "generate_export_header(libC)\n" + + "target_link_libraries(libB libA)\n" + "target_link_libraries(libC libA libB)\n" + ) + endforeach() +endforeach() + +foreach(B1 ${Bools}) + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_True/CMakeLists.txt" + "target_link_libraries(libB LINK_INTERFACE_LIBRARIES libA)\n" + "target_link_libraries(libC LINK_INTERFACE_LIBRARIES libA)\n" + ) +endforeach() + +foreach(B1 ${Bools}) + foreach(B2 ${Bools}) + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}/CMakeLists.txt" + "export(TARGETS libA libB libC FILE Targets.cmake)\n" + ) + + try_compile(Result "${CMAKE_CURRENT_BINARY_DIR}/libs_build_${B1}_${B2}" + "${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}" + libs + OUTPUT_VARIABLE Out + ) + if (NOT Result) + message(SEND_ERROR "Could not build shared library + Libs CLEAR_LINK_INTERFACE_LIBRARIES: ${B1} + Libs SPECIFY_LINK_INTERFACE_LIBRARIES: ${B2}\n\n\n${Out}") + endif() + endforeach() +endforeach() + + +set (COUNT 0) +macro(_do_build CLEAR_LINK_INTERFACE_LIBRARIES + SPECIFY_LINK_INTERFACE_LIBRARIES) + math(EXPR COUNT "${COUNT} + 1" ) + + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}/src" + "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}" + ) + + # Set local short variables to avoid long lines + set(B1 ${CLEAR_LINK_INTERFACE_LIBRARIES}) + set(B2 ${SPECIFY_LINK_INTERFACE_LIBRARIES}) + set(Libs_Build_Dir "${CMAKE_CURRENT_BINARY_DIR}/libs_build_${B1}_${B2}") + + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt" + "include_directories(\"${CMAKE_CURRENT_BINARY_DIR}/libs_${B1}_${B2}\"\n" + " \"${Libs_Build_Dir}\"\n" + ")\n" + "include(\"${Libs_Build_Dir}/Targets.cmake\")\n" + ) + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp" + "" + ) + + foreach(klass ${ARGN}) + if (klass STREQUAL "LIBS") + break() + endif() + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp" + "#include \"${klass}.h\"\n" + ) + endforeach() + + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp" + "int main(int, char **) {" + ) + + foreach(klass ${ARGN}) + if (klass STREQUAL "LIBS") + break() + endif() + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp" + "${klass} ${klass}_;\n" + ) + endforeach() + + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp" + "return 0;" + "}\n" + ) + + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt" + + "add_executable(exec \n" + "\"${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/main.cpp\")\n" + ) + + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt" + "target_link_libraries(exec " + ) + + set(continue True) + foreach(klass ${ARGN}) + if (klass STREQUAL "LIBS") + # CMake has no continue() command + set(continue False) + endif() + if (NOT continue AND NOT klass STREQUAL "LIBS") + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt" + "${klass} " + ) + endif() + endforeach() + + file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}/CMakeLists.txt" + ")\n" + ) + + try_compile(Result "${CMAKE_CURRENT_BINARY_DIR}/fail${COUNT}" + "${CMAKE_CURRENT_BINARY_DIR}/test${COUNT}" + src + OUTPUT_VARIABLE Out + ) +endmacro() + +macro(EXPECT_PASS) + _do_build(${ARGN}) + if (NOT ${Result}) + message(SEND_ERROR "Failed! \n\n${Out}") + endif() +endmacro() + +macro(EXPECT_FAIL) + _do_build(${ARGN}) + if (${Result}) + message(SEND_ERROR "Failed! \n\n${Out}") + endif() +endmacro() + +macro(all_pass) + expect_pass(False False ${ARGN}) + expect_pass(True False ${ARGN}) + expect_pass(False True ${ARGN}) + expect_pass(True True ${ARGN}) +endmacro() + +# If we specify all libs to the executable, it will always pass +all_pass( + classA + LIBS + libA +) + +all_pass( + classA classB + LIBS + libA libB +) + +all_pass( + classA classC + LIBS + libA libC +) + +all_pass( + classA classB classC + LIBS + libA libB libC +) + +# If we don't set the CMAKE_LINK_INTERFACE_LIBRARIES to empty and +# we don't explicitly specify the LINK_INTERFACE_LIBRARIES, the +# executable can use all classes if linked +# indirectly to them +expect_pass(False False + classA classB + LIBS + libB +) + +# Although libC is linked to libA, libA is not part of the link interface of +# libC. +# Because we don't clear the CMAKE_LINK_INTERFACE_LIBRARIES it still works. +expect_pass(False False + classA classC + LIBS + libC +) + +# However, if we do clear it and don't explicitly link the executable to it, +# it fails, +# whether we specify the link_interface_libraries properly or not. +if (NOT APPLE) + expect_fail(True False + classB classC + LIBS + libC + ) + expect_fail(True True + classB classC + LIBS + libC + ) +endif() + + +# Then we can still link the executable to libA directly of course to pass +expect_pass(True False + classA classC + LIBS + libC libA +) +expect_pass(True True + classA classC + LIBS + libC libA +) + +# Also, if we clear and specify the link interface, we can use classes defined +# in that interface without linking to the library directly +expect_pass(True True + classA classB + LIBS + libB +) + +expect_pass(True True + classA classC + LIBS + libC +) diff --git a/Tests/CMakeCommands/target_link_libraries/libs/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/libs/CMakeLists.txt new file mode 100644 index 0000000..8bac943 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/libs/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8) + +project(libs) + +include(CheckCXXCompilerFlag) +include(GenerateExportHeader) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_VERBOSE_MAKEFILE ON) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/Tests/CMakeCommands/target_link_libraries/libs/classA.cpp b/Tests/CMakeCommands/target_link_libraries/libs/classA.cpp new file mode 100644 index 0000000..f5e7106 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/libs/classA.cpp @@ -0,0 +1,7 @@ + +#include "classA.h" + +classA::classA() +{ + +} diff --git a/Tests/CMakeCommands/target_link_libraries/libs/classA.h b/Tests/CMakeCommands/target_link_libraries/libs/classA.h new file mode 100644 index 0000000..4d568e3 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/libs/classA.h @@ -0,0 +1,13 @@ + +#ifndef CLASS_A_H +#define CLASS_A_H + +#include "liba_export.h" + +class LIBA_EXPORT classA +{ +public: + classA(); +}; + +#endif diff --git a/Tests/CMakeCommands/target_link_libraries/libs/classB.cpp b/Tests/CMakeCommands/target_link_libraries/libs/classB.cpp new file mode 100644 index 0000000..e309586 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/libs/classB.cpp @@ -0,0 +1,13 @@ + +#include "classB.h" + +#include "classA.h" + +classB::classB() +{ +} + +classA* classB::a() const +{ + return new classA(); +} diff --git a/Tests/CMakeCommands/target_link_libraries/libs/classB.h b/Tests/CMakeCommands/target_link_libraries/libs/classB.h new file mode 100644 index 0000000..e0baed6 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/libs/classB.h @@ -0,0 +1,17 @@ + +#ifndef CLASS_B_H +#define CLASS_B_H + +#include "libb_export.h" + +class classA; + +class LIBB_EXPORT classB +{ +public: + classB(); + + classA* a() const; +}; + +#endif diff --git a/Tests/CMakeCommands/target_link_libraries/libs/classC.cpp b/Tests/CMakeCommands/target_link_libraries/libs/classC.cpp new file mode 100644 index 0000000..6d15259 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/libs/classC.cpp @@ -0,0 +1,15 @@ + +#include "classC.h" + +#include "classA.h" +#include "classB.h" + +classC::classC() +{ + classB b; +} + +classA* classC::a() const +{ + return new classA(); +} diff --git a/Tests/CMakeCommands/target_link_libraries/libs/classC.h b/Tests/CMakeCommands/target_link_libraries/libs/classC.h new file mode 100644 index 0000000..0135f65 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/libs/classC.h @@ -0,0 +1,17 @@ + +#ifndef CLASS_C_H +#define CLASS_C_H + +#include "libc_export.h" + +class classA; + +class LIBC_EXPORT classC +{ +public: + classC(); + + classA* a() const; +}; + +#endif diff --git a/Tests/CMakeCommands/target_link_libraries/src/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/src/CMakeLists.txt new file mode 100644 index 0000000..29f0986 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/src/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 2.8) + +project(src) + +include(CheckCXXCompilerFlag) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_VERBOSE_MAKEFILE ON) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") ----------------------------------------------------------------------- Summary of changes: hooks/post-receive -- CMake _______________________________________________ Cmake-commits mailing list Cmake-commits@cmake.org http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-commits