diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2020-07-29 18:19:56 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-08-12 15:31:07 (GMT) |
commit | 2e42651dff43c4e962f03fc24281cbf446880ded (patch) | |
tree | 5a1fa6f2098d9cb5bdc04c7f9285dc454c3a5ebf /Tests/RunCMake | |
parent | 0cd3b5d0ca8d541fc3769f467db71a07a95be7f6 (diff) | |
download | CMake-2e42651dff43c4e962f03fc24281cbf446880ded.zip CMake-2e42651dff43c4e962f03fc24281cbf446880ded.tar.gz CMake-2e42651dff43c4e962f03fc24281cbf446880ded.tar.bz2 |
Add option to optimize link dependencies for static libraries
Add an `OPTIMIZE_DEPENDENCIES` target property and supporting
`CMAKE_OPTIMIZE_DEPENDENCIES` variable to optionally enable pruning and
flattening of outgoing dependencies from static libraries. Since they
do not actually link, they only depend on side effects of their
dependencies. Therefore we can drop dependencies that contribute no
side effects.
Diffstat (limited to 'Tests/RunCMake')
37 files changed, 296 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index e08b30a..98a1f87 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -401,6 +401,7 @@ add_RunCMake_test(no_install_prefix) add_RunCMake_test(configure_file) add_RunCMake_test(CTestTimeout -DTIMEOUT=${CTestTestTimeout_TIME}) add_RunCMake_test(CTestTimeoutAfterMatch) +add_RunCMake_test(DependencyGraph -DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER}) # ctresalloc links against CMakeLib and CTestLib, which means it can't be built # if CMake_TEST_EXTERNAL_CMAKE is activated (the compiler might be different.) diff --git a/Tests/RunCMake/DependencyGraph/CMakeLists.txt b/Tests/RunCMake/DependencyGraph/CMakeLists.txt new file mode 100644 index 0000000..b646c4a --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.18) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeCommon.cmake b/Tests/RunCMake/DependencyGraph/OptimizeCommon.cmake new file mode 100644 index 0000000..4954bc4 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeCommon.cmake @@ -0,0 +1,40 @@ +enable_language(C) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY out) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY out) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY out) + +add_library(SharedTop SHARED mylib.c) +add_library(StaticTop STATIC mylib.c) +add_library(StaticMiddle STATIC mylib.c) + +add_library(StaticNone STATIC mylib.c) +add_library(StaticPreBuild STATIC mylib.c) +add_library(StaticPreLink STATIC mylib.c) +add_library(StaticPostBuild STATIC mylib.c) +add_library(StaticCc STATIC mylibcc.c) + +add_custom_command(TARGET StaticPreBuild PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E true) +add_custom_command(TARGET StaticPreLink PRE_LINK + COMMAND ${CMAKE_COMMAND} -E true) +add_custom_command(TARGET StaticPostBuild POST_BUILD + COMMAND ${CMAKE_COMMAND} -E true) +add_custom_command(OUTPUT mylibcc.c + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/mylib.c ${CMAKE_BINARY_DIR}/mylibcc.c) + +target_link_libraries(SharedTop PRIVATE StaticMiddle) +target_link_libraries(StaticTop PRIVATE StaticMiddle) +target_link_libraries(StaticMiddle PRIVATE StaticNone StaticPreBuild StaticPreLink StaticPostBuild StaticCc) + +if(OPTIMIZE_TOP) + set_target_properties(SharedTop StaticTop PROPERTIES + OPTIMIZE_DEPENDENCIES TRUE) +endif() +if(OPTIMIZE_MIDDLE) + set_target_properties(StaticMiddle PROPERTIES + OPTIMIZE_DEPENDENCIES TRUE) +endif() + +include(WriteTargets.cmake) +write_targets() diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-both-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeFortran-both-build-check.cmake new file mode 100644 index 0000000..1020cb3 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-both-build-check.cmake @@ -0,0 +1,5 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${FortranTop_TARGET_FILE} + ${FortranBottom_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-both-build-stderr.txt b/Tests/RunCMake/DependencyGraph/OptimizeFortran-both-build-stderr.txt new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-both-build-stderr.txt @@ -0,0 +1 @@ +.* diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-both.cmake b/Tests/RunCMake/DependencyGraph/OptimizeFortran-both.cmake new file mode 100644 index 0000000..581fd46 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-both.cmake @@ -0,0 +1 @@ +include(OptimizeFortranCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-middle-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeFortran-middle-build-check.cmake new file mode 100644 index 0000000..5c7e8cd --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-middle-build-check.cmake @@ -0,0 +1,6 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${FortranTop_TARGET_FILE} + ${CMiddle_TARGET_FILE} + ${FortranBottom_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-middle-build-stderr.txt b/Tests/RunCMake/DependencyGraph/OptimizeFortran-middle-build-stderr.txt new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-middle-build-stderr.txt @@ -0,0 +1 @@ +.* diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-middle.cmake b/Tests/RunCMake/DependencyGraph/OptimizeFortran-middle.cmake new file mode 100644 index 0000000..581fd46 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-middle.cmake @@ -0,0 +1 @@ +include(OptimizeFortranCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-none-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeFortran-none-build-check.cmake new file mode 100644 index 0000000..5c7e8cd --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-none-build-check.cmake @@ -0,0 +1,6 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${FortranTop_TARGET_FILE} + ${CMiddle_TARGET_FILE} + ${FortranBottom_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-none-build-stderr.txt b/Tests/RunCMake/DependencyGraph/OptimizeFortran-none-build-stderr.txt new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-none-build-stderr.txt @@ -0,0 +1 @@ +.* diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-none.cmake b/Tests/RunCMake/DependencyGraph/OptimizeFortran-none.cmake new file mode 100644 index 0000000..581fd46 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-none.cmake @@ -0,0 +1 @@ +include(OptimizeFortranCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-top-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeFortran-top-build-check.cmake new file mode 100644 index 0000000..1020cb3 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-top-build-check.cmake @@ -0,0 +1,5 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${FortranTop_TARGET_FILE} + ${FortranBottom_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-top-build-stderr.txt b/Tests/RunCMake/DependencyGraph/OptimizeFortran-top-build-stderr.txt new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-top-build-stderr.txt @@ -0,0 +1 @@ +.* diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortran-top.cmake b/Tests/RunCMake/DependencyGraph/OptimizeFortran-top.cmake new file mode 100644 index 0000000..581fd46 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortran-top.cmake @@ -0,0 +1 @@ +include(OptimizeFortranCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeFortranCommon.cmake b/Tests/RunCMake/DependencyGraph/OptimizeFortranCommon.cmake new file mode 100644 index 0000000..354d3fc --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeFortranCommon.cmake @@ -0,0 +1,25 @@ +enable_language(C) +enable_language(Fortran) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY out) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY out) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY out) + +add_library(FortranTop STATIC mylib.f90) +add_library(CMiddle STATIC mylib.c) +add_library(FortranBottom STATIC mylib.f90) + +target_link_libraries(FortranTop PRIVATE CMiddle) +target_link_libraries(CMiddle PRIVATE FortranBottom) + +if(OPTIMIZE_TOP) + set_target_properties(FortranTop PROPERTIES + OPTIMIZE_DEPENDENCIES TRUE) +endif() +if(OPTIMIZE_MIDDLE) + set_target_properties(CMiddle PROPERTIES + OPTIMIZE_DEPENDENCIES TRUE) +endif() + +include(WriteTargets.cmake) +write_targets() diff --git a/Tests/RunCMake/DependencyGraph/OptimizeShared-both-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeShared-both-build-check.cmake new file mode 100644 index 0000000..312de04 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeShared-both-build-check.cmake @@ -0,0 +1,11 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${SharedTop_TARGET_FILE} + ${SharedTop_TARGET_LINKER_FILE} + ${StaticMiddle_TARGET_FILE} + ${StaticNone_TARGET_FILE} + ${StaticPreBuild_TARGET_FILE} + ${StaticPreLink_TARGET_FILE} + ${StaticPostBuild_TARGET_FILE} + ${StaticCc_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeShared-both.cmake b/Tests/RunCMake/DependencyGraph/OptimizeShared-both.cmake new file mode 100644 index 0000000..c150e62 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeShared-both.cmake @@ -0,0 +1 @@ +include(OptimizeCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeShared-middle-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeShared-middle-build-check.cmake new file mode 100644 index 0000000..312de04 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeShared-middle-build-check.cmake @@ -0,0 +1,11 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${SharedTop_TARGET_FILE} + ${SharedTop_TARGET_LINKER_FILE} + ${StaticMiddle_TARGET_FILE} + ${StaticNone_TARGET_FILE} + ${StaticPreBuild_TARGET_FILE} + ${StaticPreLink_TARGET_FILE} + ${StaticPostBuild_TARGET_FILE} + ${StaticCc_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeShared-middle.cmake b/Tests/RunCMake/DependencyGraph/OptimizeShared-middle.cmake new file mode 100644 index 0000000..c150e62 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeShared-middle.cmake @@ -0,0 +1 @@ +include(OptimizeCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeShared-none-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeShared-none-build-check.cmake new file mode 100644 index 0000000..312de04 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeShared-none-build-check.cmake @@ -0,0 +1,11 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${SharedTop_TARGET_FILE} + ${SharedTop_TARGET_LINKER_FILE} + ${StaticMiddle_TARGET_FILE} + ${StaticNone_TARGET_FILE} + ${StaticPreBuild_TARGET_FILE} + ${StaticPreLink_TARGET_FILE} + ${StaticPostBuild_TARGET_FILE} + ${StaticCc_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeShared-none.cmake b/Tests/RunCMake/DependencyGraph/OptimizeShared-none.cmake new file mode 100644 index 0000000..c150e62 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeShared-none.cmake @@ -0,0 +1 @@ +include(OptimizeCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeShared-top-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeShared-top-build-check.cmake new file mode 100644 index 0000000..312de04 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeShared-top-build-check.cmake @@ -0,0 +1,11 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${SharedTop_TARGET_FILE} + ${SharedTop_TARGET_LINKER_FILE} + ${StaticMiddle_TARGET_FILE} + ${StaticNone_TARGET_FILE} + ${StaticPreBuild_TARGET_FILE} + ${StaticPreLink_TARGET_FILE} + ${StaticPostBuild_TARGET_FILE} + ${StaticCc_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeShared-top.cmake b/Tests/RunCMake/DependencyGraph/OptimizeShared-top.cmake new file mode 100644 index 0000000..c150e62 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeShared-top.cmake @@ -0,0 +1 @@ +include(OptimizeCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeStatic-both-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeStatic-both-build-check.cmake new file mode 100644 index 0000000..5222ed7 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeStatic-both-build-check.cmake @@ -0,0 +1,8 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${StaticTop_TARGET_FILE} + ${StaticPreBuild_TARGET_FILE} + ${StaticPreLink_TARGET_FILE} + ${StaticPostBuild_TARGET_FILE} + ${StaticCc_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeStatic-both.cmake b/Tests/RunCMake/DependencyGraph/OptimizeStatic-both.cmake new file mode 100644 index 0000000..c150e62 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeStatic-both.cmake @@ -0,0 +1 @@ +include(OptimizeCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeStatic-middle-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeStatic-middle-build-check.cmake new file mode 100644 index 0000000..5cba223 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeStatic-middle-build-check.cmake @@ -0,0 +1,10 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${StaticTop_TARGET_FILE} + ${StaticMiddle_TARGET_FILE} + ${StaticNone_TARGET_FILE} + ${StaticPreBuild_TARGET_FILE} + ${StaticPreLink_TARGET_FILE} + ${StaticPostBuild_TARGET_FILE} + ${StaticCc_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeStatic-middle.cmake b/Tests/RunCMake/DependencyGraph/OptimizeStatic-middle.cmake new file mode 100644 index 0000000..c150e62 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeStatic-middle.cmake @@ -0,0 +1 @@ +include(OptimizeCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeStatic-none-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeStatic-none-build-check.cmake new file mode 100644 index 0000000..5cba223 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeStatic-none-build-check.cmake @@ -0,0 +1,10 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${StaticTop_TARGET_FILE} + ${StaticMiddle_TARGET_FILE} + ${StaticNone_TARGET_FILE} + ${StaticPreBuild_TARGET_FILE} + ${StaticPreLink_TARGET_FILE} + ${StaticPostBuild_TARGET_FILE} + ${StaticCc_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeStatic-none.cmake b/Tests/RunCMake/DependencyGraph/OptimizeStatic-none.cmake new file mode 100644 index 0000000..c150e62 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeStatic-none.cmake @@ -0,0 +1 @@ +include(OptimizeCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeStatic-top-build-check.cmake b/Tests/RunCMake/DependencyGraph/OptimizeStatic-top-build-check.cmake new file mode 100644 index 0000000..5222ed7 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeStatic-top-build-check.cmake @@ -0,0 +1,8 @@ +include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake) +check_files(${RunCMake_TEST_BINARY_DIR}/out + ${StaticTop_TARGET_FILE} + ${StaticPreBuild_TARGET_FILE} + ${StaticPreLink_TARGET_FILE} + ${StaticPostBuild_TARGET_FILE} + ${StaticCc_TARGET_FILE} + ) diff --git a/Tests/RunCMake/DependencyGraph/OptimizeStatic-top.cmake b/Tests/RunCMake/DependencyGraph/OptimizeStatic-top.cmake new file mode 100644 index 0000000..c150e62 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/OptimizeStatic-top.cmake @@ -0,0 +1 @@ +include(OptimizeCommon.cmake) diff --git a/Tests/RunCMake/DependencyGraph/Property.cmake b/Tests/RunCMake/DependencyGraph/Property.cmake new file mode 100644 index 0000000..08fdd2b --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/Property.cmake @@ -0,0 +1,24 @@ +enable_language(C) + +add_library(Unset STATIC mylib.c) + +set(CMAKE_OPTIMIZE_DEPENDENCIES TRUE) +add_library(SetTrue STATIC mylib.c) + +set(CMAKE_OPTIMIZE_DEPENDENCIES FALSE) +add_library(SetFalse STATIC mylib.c) + +get_property(_set TARGET Unset PROPERTY OPTIMIZE_DEPENDENCIES SET) +if(_set) + message(SEND_ERROR "OPTIMIZE_DEPENDENCIES property should not be set on Unset target") +endif() + +get_property(_true TARGET SetTrue PROPERTY OPTIMIZE_DEPENDENCIES) +if(NOT _true STREQUAL "TRUE") + message(SEND_ERROR "OPTIMIZE_DEPENDENCIES property should be TRUE on SetTrue target") +endif() + +get_property(_false TARGET SetFalse PROPERTY OPTIMIZE_DEPENDENCIES) +if(NOT _false STREQUAL "FALSE") + message(SEND_ERROR "OPTIMIZE_DEPENDENCIES property should be FALSE on SetFalse target") +endif() diff --git a/Tests/RunCMake/DependencyGraph/RunCMakeTest.cmake b/Tests/RunCMake/DependencyGraph/RunCMakeTest.cmake new file mode 100644 index 0000000..cb0d541 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/RunCMakeTest.cmake @@ -0,0 +1,60 @@ +include(RunCMake) + +function(check_files dir) + set(expected ${ARGN}) + list(FILTER expected EXCLUDE REGEX "^$") + list(REMOVE_DUPLICATES expected) + list(SORT expected) + + file(GLOB_RECURSE glob "${dir}/*") + set(actual) + foreach(i IN LISTS glob) + if(NOT i MATCHES "(\\.manifest$)|(\\.exp$)|(\\.tds$)") + list(APPEND actual ${i}) + endif() + endforeach() + list(REMOVE_DUPLICATES actual) + list(SORT actual) + + if(NOT "${expected}" STREQUAL "${actual}") + string(REPLACE ";" "\n " expected_formatted "${expected}") + string(REPLACE ";" "\n " actual_formatted "${actual}") + string(APPEND RunCMake_TEST_FAILED "Actual files did not match expected\nExpected:\n ${expected_formatted}\nActual:\n ${actual_formatted}\n") + endif() + + set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE) +endfunction() + +function(run_cmake_build name) + set(RunCMake_TEST_NO_CLEAN TRUE) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${name}-build) + file(REMOVE_RECURSE ${RunCMake_TEST_BINARY_DIR}) + if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) + list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release) + endif() + run_cmake(${name}) + set(RunCMake_TEST_OPTIONS) + run_cmake_command(${name}-build ${CMAKE_COMMAND} + --build ${RunCMake_TEST_BINARY_DIR} + --config Release + --target ${ARGN}) +endfunction() + +function(run_optimize_test name) + set(RunCMake_TEST_OPTIONS) + run_cmake_build(${name}-none ${ARGN}) + set(RunCMake_TEST_OPTIONS -DOPTIMIZE_TOP=TRUE) + run_cmake_build(${name}-top ${ARGN}) + set(RunCMake_TEST_OPTIONS -DOPTIMIZE_MIDDLE=TRUE) + run_cmake_build(${name}-middle ${ARGN}) + set(RunCMake_TEST_OPTIONS -DOPTIMIZE_TOP=TRUE -DOPTIMIZE_MIDDLE=TRUE) + run_cmake_build(${name}-both ${ARGN}) +endfunction() + +run_cmake(Property) + +run_optimize_test(OptimizeShared SharedTop) +run_optimize_test(OptimizeStatic StaticTop) +if(CMAKE_Fortran_COMPILER) + run_optimize_test(OptimizeFortran FortranTop) +endif() diff --git a/Tests/RunCMake/DependencyGraph/WriteTargets.cmake b/Tests/RunCMake/DependencyGraph/WriteTargets.cmake new file mode 100644 index 0000000..e1012c1 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/WriteTargets.cmake @@ -0,0 +1,16 @@ +function(write_targets) + set(_input "") + + get_property(_targets DIRECTORY . PROPERTY BUILDSYSTEM_TARGETS) + foreach(_t IN LISTS _targets) + get_property(_type TARGET "${_t}" PROPERTY TYPE) + if(_type STREQUAL "SHARED_LIBRARY") + string(APPEND _input "set(${_t}_TARGET_FILE [==[$<TARGET_FILE:${_t}>]==])\n") + string(APPEND _input "set(${_t}_TARGET_LINKER_FILE [==[$<TARGET_LINKER_FILE:${_t}>]==])\n") + elseif(_type STREQUAL "STATIC_LIBRARY") + string(APPEND _input "set(${_t}_TARGET_FILE [==[$<TARGET_FILE:${_t}>]==])\n") + endif() + endforeach() + + file(GENERATE OUTPUT target_files.cmake CONTENT "${_input}" CONDITION $<CONFIG:Release>) +endfunction() diff --git a/Tests/RunCMake/DependencyGraph/mylib.c b/Tests/RunCMake/DependencyGraph/mylib.c new file mode 100644 index 0000000..5422fe3 --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/mylib.c @@ -0,0 +1,6 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif + void mylib(void) +{ +} diff --git a/Tests/RunCMake/DependencyGraph/mylib.f90 b/Tests/RunCMake/DependencyGraph/mylib.f90 new file mode 100644 index 0000000..104768f --- /dev/null +++ b/Tests/RunCMake/DependencyGraph/mylib.f90 @@ -0,0 +1,3 @@ +function mylib_fortran() + mylib_fortran = 42 +end function mylib_fortran |