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 fdd49dad034e99e44a3bd3ab35aa714704af27ff (commit) via 1e55661e64562fa95e02933294f954434ed6463a (commit) via ef6c2add38cf1b26a259bfa955a607bfe98612c8 (commit) from 3ad0dfff40aefe84216190fefb66d9e7b0374343 (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=fdd49dad034e99e44a3bd3ab35aa714704af27ff commit fdd49dad034e99e44a3bd3ab35aa714704af27ff Merge: 3ad0dff 1e55661 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Tue Oct 25 16:42:53 2011 -0400 Commit: CMake Topic Stage <kwro...@kitware.com> CommitDate: Tue Oct 25 16:42:53 2011 -0400 Merge topic 'test-target_link_libraries' into next 1e55661 Fail softly instead of fatally. ef6c2ad Add some unit tests for the target_link_libraries command http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1e55661e64562fa95e02933294f954434ed6463a commit 1e55661e64562fa95e02933294f954434ed6463a Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Tue Oct 25 22:17:33 2011 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Tue Oct 25 22:21:13 2011 +0200 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 a6cf552..fdd53eb 100644 --- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt +++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt @@ -13,6 +13,17 @@ add_executable( "${CMAKE_CURRENT_BINARY_DIR}/main.cxx" ) +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}) @@ -67,9 +78,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=ef6c2add38cf1b26a259bfa955a607bfe98612c8 commit ef6c2add38cf1b26a259bfa955a607bfe98612c8 Author: Stephen Kelly <steve...@gmail.com> AuthorDate: Tue Oct 25 22:16:31 2011 +0200 Commit: Stephen Kelly <steve...@gmail.com> CommitDate: Tue Oct 25 22:21:13 2011 +0200 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 new file mode 100644 index 0000000..a6cf552 --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt @@ -0,0 +1,271 @@ +cmake_minimum_required(VERSION 2.8) + +project(target_link_libraries) + +file(WRITE + "${CMAKE_CURRENT_BINARY_DIR}/main.cxx" + "int main() { return 0; } +" +) + +add_executable( + target_link_libraries + "${CMAKE_CURRENT_BINARY_DIR}/main.cxx" +) + +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}") diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 78db39d..44ed2f5 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1574,6 +1574,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ -P "${CMake_SOURCE_DIR}/Tests/CMakeCommands/build_command/RunCMake.cmake" ) + ADD_TEST_MACRO(CMakeCommands.target_link_libraries target_link_libraries) + CONFIGURE_FILE( "${CMake_SOURCE_DIR}/Tests/CTestTestCrash/test.cmake.in" "${CMake_BINARY_DIR}/Tests/CTestTestCrash/test.cmake" ----------------------------------------------------------------------- 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