diff options
Diffstat (limited to 'Tests/LinkDirectory')
-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 |
5 files changed, 66 insertions, 0 deletions
diff --git a/Tests/LinkDirectory/CMakeLists.txt b/Tests/LinkDirectory/CMakeLists.txt new file mode 100644 index 000000000..7356b27d2 --- /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 000000000..f7c840f9a --- /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 000000000..6ef1ebe59 --- /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 000000000..890a0890e --- /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 000000000..090cc6ce5 --- /dev/null +++ b/Tests/LinkDirectory/mylibB.c @@ -0,0 +1 @@ +int mylibB(void) { return 0; } |