diff options
author | Brad King <brad.king@kitware.com> | 2009-11-24 16:17:16 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-11-24 16:17:16 (GMT) |
commit | bb187903979d20c8b8a5ed07276c6af122bad781 (patch) | |
tree | 44f03b45f0c57d718de211bce7a1341d37e5e8b0 | |
parent | 02db43239b7e2fd1f6dede9fb7237470ca51b567 (diff) | |
download | CMake-bb187903979d20c8b8a5ed07276c6af122bad781.zip CMake-bb187903979d20c8b8a5ed07276c6af122bad781.tar.gz CMake-bb187903979d20c8b8a5ed07276c6af122bad781.tar.bz2 |
Test CMP0015 OLD and NEW link_directories behavior
We create a LinkDirectory test to check that the policy OLD and NEW
behaviors work as documented. See issue #9697.
-rw-r--r-- | Tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/LinkDirectory/CMakeLists.txt | 47 | ||||
-rw-r--r-- | Tests/LinkDirectory/External/CMakeLists.txt | 14 | ||||
-rw-r--r-- | Tests/LinkDirectory/External/myexe.c | 3 | ||||
-rw-r--r-- | Tests/LinkDirectory/mylibA.c | 1 | ||||
-rw-r--r-- | Tests/LinkDirectory/mylibB.c | 1 |
6 files changed, 67 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index c49d274..cc7f557 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -122,6 +122,7 @@ IF(BUILD_TESTING) ADD_TEST_MACRO(SetLang SetLang) ADD_TEST_MACRO(ExternalOBJ ExternalOBJ) ADD_TEST_MACRO(LoadCommand LoadedCommand) + ADD_TEST_MACRO(LinkDirectory bin/LinkDirectory) ADD_TEST_MACRO(LinkLanguage LinkLanguage) ADD_TEST_MACRO(LinkLine LinkLine) ADD_TEST_MACRO(MacroTest miniMacroTest) diff --git a/Tests/LinkDirectory/CMakeLists.txt b/Tests/LinkDirectory/CMakeLists.txt new file mode 100644 index 0000000..7356b27 --- /dev/null +++ b/Tests/LinkDirectory/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 2.8) +project(LinkDirectory C) + +# Put the subproject source tree in our build tree so it can refer to +# link directories relative to its source. +if(NOT "${LinkDirectory_SOURCE_DIR}" STREQUAL "${LinkDirectory_BINARY_DIR}") + file(COPY External/ DESTINATION External PATTERN CVS EXCLUDE) +endif() + +# Build a library into the subproject source tree. +add_library(mylibA STATIC mylibA.c) +set_property(TARGET mylibA PROPERTY + ARCHIVE_OUTPUT_DIRECTORY "${LinkDirectory_BINARY_DIR}/External/lib") +get_property(mylibA TARGET mylibA PROPERTY LOCATION) + +# Build a library into our build tree relative to the subproject build tree. +add_library(mylibB STATIC mylibB.c) +set_property(TARGET mylibB PROPERTY + ARCHIVE_OUTPUT_DIRECTORY "${LinkDirectory_BINARY_DIR}/lib") +get_property(mylibB TARGET mylibB PROPERTY LOCATION) + +# Create a custom target to drive the subproject build. +include(ExternalProject) +ExternalProject_Add(ExternalTarget + SOURCE_DIR "${LinkDirectory_BINARY_DIR}/External" + BINARY_DIR "${LinkDirectory_BINARY_DIR}/External-build" + CMAKE_ARGS "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${LinkDirectory_BINARY_DIR}/bin" + PREFIX "${LinkDirectory_BINARY_DIR}/External-build/root" + DOWNLOAD_COMMAND "" + INSTALL_COMMAND "" + ) + +# Add a step to wipe out the subproject executable after our libraries +# change. This is needed because the subproject cannot depend on them +# directly because it does not know the full paths to the libraries. +# (The purpose of this test is to check that link_directories works.) +ExternalProject_Add_Step(ExternalTarget cleanup + COMMAND ${CMAKE_COMMAND} -E remove_directory ${LinkDirectory_BINARY_DIR}/bin + DEPENDEES download + DEPENDERS configure + DEPENDS ${mylibA} ${mylibB} + "${LinkDirectory_BINARY_DIR}/External/CMakeLists.txt" + "${LinkDirectory_BINARY_DIR}/External/myexe.c" + ) + +# Make the subproject build after our targets. +add_dependencies(ExternalTarget mylibA mylibB) diff --git a/Tests/LinkDirectory/External/CMakeLists.txt b/Tests/LinkDirectory/External/CMakeLists.txt new file mode 100644 index 0000000..f7c840f --- /dev/null +++ b/Tests/LinkDirectory/External/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8) +project(LinkDirectoryExternal C) + +# Test CMP0015 OLD behavior: -L../lib +cmake_policy(SET CMP0015 OLD) +link_directories(../lib) + +# Test CMP0015 NEW behavior: -L${CMAKE_CURRENT_SOURCE_DIR}/lib +cmake_policy(SET CMP0015 NEW) +link_directories(lib) + +add_executable(myexe myexe.c) +set_property(TARGET myexe PROPERTY OUTPUT_NAME LinkDirectory) +target_link_libraries(myexe mylibA mylibB) diff --git a/Tests/LinkDirectory/External/myexe.c b/Tests/LinkDirectory/External/myexe.c new file mode 100644 index 0000000..6ef1ebe --- /dev/null +++ b/Tests/LinkDirectory/External/myexe.c @@ -0,0 +1,3 @@ +extern int mylibA(void); +extern int mylibB(void); +int main(void) { return mylibA() + mylibB(); } diff --git a/Tests/LinkDirectory/mylibA.c b/Tests/LinkDirectory/mylibA.c new file mode 100644 index 0000000..890a089 --- /dev/null +++ b/Tests/LinkDirectory/mylibA.c @@ -0,0 +1 @@ +int mylibA(void) { return 0; } diff --git a/Tests/LinkDirectory/mylibB.c b/Tests/LinkDirectory/mylibB.c new file mode 100644 index 0000000..090cc6c --- /dev/null +++ b/Tests/LinkDirectory/mylibB.c @@ -0,0 +1 @@ +int mylibB(void) { return 0; } |