mirror of
https://github.com/reactos/CMake.git
synced 2024-11-24 03:59:58 +00:00
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.
This commit is contained in:
parent
02db43239b
commit
bb18790397
@ -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)
|
||||
|
47
Tests/LinkDirectory/CMakeLists.txt
Normal file
47
Tests/LinkDirectory/CMakeLists.txt
Normal file
@ -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)
|
14
Tests/LinkDirectory/External/CMakeLists.txt
vendored
Normal file
14
Tests/LinkDirectory/External/CMakeLists.txt
vendored
Normal file
@ -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)
|
3
Tests/LinkDirectory/External/myexe.c
vendored
Normal file
3
Tests/LinkDirectory/External/myexe.c
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
extern int mylibA(void);
|
||||
extern int mylibB(void);
|
||||
int main(void) { return mylibA() + mylibB(); }
|
1
Tests/LinkDirectory/mylibA.c
Normal file
1
Tests/LinkDirectory/mylibA.c
Normal file
@ -0,0 +1 @@
|
||||
int mylibA(void) { return 0; }
|
1
Tests/LinkDirectory/mylibB.c
Normal file
1
Tests/LinkDirectory/mylibB.c
Normal file
@ -0,0 +1 @@
|
||||
int mylibB(void) { return 0; }
|
Loading…
Reference in New Issue
Block a user