diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2023-04-19 14:01:10 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2023-05-03 15:08:07 (GMT) |
commit | 375e6fdbbe398921de321216125765ba1917a325 (patch) | |
tree | 43d934f18f4d28a82d5264a0d0fb0301bc0bf7d9 /Tests | |
parent | 24a3e5cda049138ca178216e0d7b02262e4035ed (diff) | |
download | CMake-375e6fdbbe398921de321216125765ba1917a325.zip CMake-375e6fdbbe398921de321216125765ba1917a325.tar.gz CMake-375e6fdbbe398921de321216125765ba1917a325.tar.bz2 |
Link step: use linker dependency linker file
Based on work done by @ben.boeckel (!8051)
Fixes: #22217
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLib/testGccDepfileReader_data/deps1.txt | 30 | ||||
-rw-r--r-- | Tests/CMakeLib/testGccDepfileReader_data/deps3.txt | 8 | ||||
-rw-r--r-- | Tests/RunCMake/BuildDepends/LinkDepends.cmake | 22 | ||||
-rw-r--r-- | Tests/RunCMake/BuildDepends/LinkDepends.step1.cmake | 23 | ||||
-rw-r--r-- | Tests/RunCMake/BuildDepends/LinkDepends.step2.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/BuildDepends/LinkDependsCheck.cmake | 11 | ||||
-rw-r--r-- | Tests/RunCMake/BuildDepends/LinkDependsExternalLibrary.cmake | 13 | ||||
-rw-r--r-- | Tests/RunCMake/BuildDepends/LinkDependsExternalLibrary.step1.cmake | 11 | ||||
-rw-r--r-- | Tests/RunCMake/BuildDepends/RunCMakeTest.cmake | 12 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/TransformDepfile/deps-unix.d.txt | 8 | ||||
-rw-r--r-- | Tests/RunCMake/TransformDepfile/deps-windows.d.txt | 8 |
12 files changed, 124 insertions, 27 deletions
diff --git a/Tests/CMakeLib/testGccDepfileReader_data/deps1.txt b/Tests/CMakeLib/testGccDepfileReader_data/deps1.txt index fd2679f..4207b58 100644 --- a/Tests/CMakeLib/testGccDepfileReader_data/deps1.txt +++ b/Tests/CMakeLib/testGccDepfileReader_data/deps1.txt @@ -1,26 +1,26 @@ --RULES-- main.o --DEPENDENCIES-- -main.cpp +/usr/include/features.h /usr/include/stdc-predef.h /usr/include/stdio.h /usr/include/x86_64-linux-gnu/bits/libc-header-start.h -/usr/include/features.h -/usr/include/x86_64-linux-gnu/sys/cdefs.h -/usr/include/x86_64-linux-gnu/bits/wordsize.h /usr/include/x86_64-linux-gnu/bits/long-double.h -/usr/include/x86_64-linux-gnu/gnu/stubs.h -/usr/include/x86_64-linux-gnu/gnu/stubs-64.h -/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h -/usr/lib/gcc/x86_64-linux-gnu/8/include/stdarg.h +/usr/include/x86_64-linux-gnu/bits/stdio_lim.h +/usr/include/x86_64-linux-gnu/bits/sys_errlist.h /usr/include/x86_64-linux-gnu/bits/types.h -/usr/include/x86_64-linux-gnu/bits/typesizes.h +/usr/include/x86_64-linux-gnu/bits/types/FILE.h +/usr/include/x86_64-linux-gnu/bits/types/__FILE.h +/usr/include/x86_64-linux-gnu/bits/types/__fpos64_t.h /usr/include/x86_64-linux-gnu/bits/types/__fpos_t.h /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h -/usr/include/x86_64-linux-gnu/bits/types/__fpos64_t.h -/usr/include/x86_64-linux-gnu/bits/types/__FILE.h -/usr/include/x86_64-linux-gnu/bits/types/FILE.h -/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h /usr/include/x86_64-linux-gnu/bits/types/cookie_io_functions_t.h -/usr/include/x86_64-linux-gnu/bits/stdio_lim.h -/usr/include/x86_64-linux-gnu/bits/sys_errlist.h +/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h +/usr/include/x86_64-linux-gnu/bits/typesizes.h +/usr/include/x86_64-linux-gnu/bits/wordsize.h +/usr/include/x86_64-linux-gnu/gnu/stubs-64.h +/usr/include/x86_64-linux-gnu/gnu/stubs.h +/usr/include/x86_64-linux-gnu/sys/cdefs.h +/usr/lib/gcc/x86_64-linux-gnu/8/include/stdarg.h +/usr/lib/gcc/x86_64-linux-gnu/8/include/stddef.h +main.cpp diff --git a/Tests/CMakeLib/testGccDepfileReader_data/deps3.txt b/Tests/CMakeLib/testGccDepfileReader_data/deps3.txt index 448f69c..8d82c60 100644 --- a/Tests/CMakeLib/testGccDepfileReader_data/deps3.txt +++ b/Tests/CMakeLib/testGccDepfileReader_data/deps3.txt @@ -1,11 +1,11 @@ --RULES-- main.o --DEPENDENCIES-- -main.cpp -foo#bar.h -foo\#bar.h foo bar.h +foo#bar.h +foo$bar.h foo\ bar.h +foo\#bar.h foo\\ bar.h foo\\\\ -foo$bar.h +main.cpp diff --git a/Tests/RunCMake/BuildDepends/LinkDepends.cmake b/Tests/RunCMake/BuildDepends/LinkDepends.cmake new file mode 100644 index 0000000..a414e03 --- /dev/null +++ b/Tests/RunCMake/BuildDepends/LinkDepends.cmake @@ -0,0 +1,22 @@ + +enable_language(C) + +include("${CMAKE_BINARY_DIR}/../LinkDependsExternalLibrary-build/ExternalLibrary-debug.cmake") +cmake_path(GET EXTERNAL_LIBRARY PARENT_PATH EXTERNAL_DIR) + +add_library(LinkDependsLib SHARED "${CMAKE_CURRENT_BINARY_DIR}/lib_depends.c") +target_link_directories(LinkDependsLib PRIVATE "${EXTERNAL_DIR}") +target_link_libraries(LinkDependsLib PRIVATE External) + +add_executable(LinkDependsExe "${CMAKE_CURRENT_BINARY_DIR}/exe_depends.c") +target_link_directories(LinkDependsExe PRIVATE "${EXTERNAL_DIR}") +target_link_libraries(LinkDependsExe PRIVATE External) + + +file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake" + CONTENT " +set(check_pairs + \"$<TARGET_FILE:LinkDependsLib>|${EXTERNAL_LIBRARY}\" + \"$<TARGET_FILE:LinkDependsExe>|${EXTERNAL_LIBRARY}\" + ) +") diff --git a/Tests/RunCMake/BuildDepends/LinkDepends.step1.cmake b/Tests/RunCMake/BuildDepends/LinkDepends.step1.cmake new file mode 100644 index 0000000..5ce55b0 --- /dev/null +++ b/Tests/RunCMake/BuildDepends/LinkDepends.step1.cmake @@ -0,0 +1,23 @@ + +file(WRITE "${RunCMake_TEST_BINARY_DIR}/lib_depends.c" [[ + +extern void external(void); + +void lib_depends(void) +{ + external(); +} +]]) + + +file(WRITE "${RunCMake_TEST_BINARY_DIR}/exe_depends.c" [[ + +extern void external(void); + +int main(void) +{ + external(); + + return 0; +} +]]) diff --git a/Tests/RunCMake/BuildDepends/LinkDepends.step2.cmake b/Tests/RunCMake/BuildDepends/LinkDepends.step2.cmake new file mode 100644 index 0000000..f2c0067 --- /dev/null +++ b/Tests/RunCMake/BuildDepends/LinkDepends.step2.cmake @@ -0,0 +1,4 @@ + +include ("${RunCMake_TEST_BINARY_DIR}/../LinkDependsExternalLibrary-build/ExternalLibrary-debug.cmake") + +file(TOUCH "${EXTERNAL_LIBRARY}") diff --git a/Tests/RunCMake/BuildDepends/LinkDependsCheck.cmake b/Tests/RunCMake/BuildDepends/LinkDependsCheck.cmake new file mode 100644 index 0000000..a21096b --- /dev/null +++ b/Tests/RunCMake/BuildDepends/LinkDependsCheck.cmake @@ -0,0 +1,11 @@ + +enable_language(C) + +file(WRITE "${CMAKE_BINARY_DIR}/LinkDependsUseLinker.cmake" + "set(CMAKE_C_LINK_DEPENDS_USE_LINKER \"${CMAKE_C_LINK_DEPENDS_USE_LINKER}\")\n") + + +file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake" + CONTENT " +# no required actions +") diff --git a/Tests/RunCMake/BuildDepends/LinkDependsExternalLibrary.cmake b/Tests/RunCMake/BuildDepends/LinkDependsExternalLibrary.cmake new file mode 100644 index 0000000..fe6575c --- /dev/null +++ b/Tests/RunCMake/BuildDepends/LinkDependsExternalLibrary.cmake @@ -0,0 +1,13 @@ + +enable_language(C) + +add_library(External SHARED "${CMAKE_CURRENT_BINARY_DIR}/external.c") + +file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/ExternalLibrary-$<LOWER_CASE:$<CONFIG>>.cmake" + CONTENT "set(EXTERNAL_LIBRARY \"$<TARGET_LINKER_FILE:External>\")\n") + + +file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake" + CONTENT " +# no required actions +") diff --git a/Tests/RunCMake/BuildDepends/LinkDependsExternalLibrary.step1.cmake b/Tests/RunCMake/BuildDepends/LinkDependsExternalLibrary.step1.cmake new file mode 100644 index 0000000..df302f7 --- /dev/null +++ b/Tests/RunCMake/BuildDepends/LinkDependsExternalLibrary.step1.cmake @@ -0,0 +1,11 @@ + +file(WRITE "${RunCMake_TEST_BINARY_DIR}/external.c" [[ + + +#if defined(_WIN32) +__declspec(dllexport) +#endif + void external(void) +{ +} +]]) diff --git a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake index 8099079..b527580 100644 --- a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake +++ b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake @@ -194,3 +194,15 @@ if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 " OR endif() run_BuildDepends(CustomCommandUnityBuild) unset(run_BuildDepends_skip_step_2) + +#if (RunCMake_GENERATOR MATCHES "Make|Ninja" AND CMAKE_C_LINK_DEPENDS_USE_LINKER) +if (RunCMake_GENERATOR MATCHES "Make|Ninja") + set(run_BuildDepends_skip_step_2 1) + run_BuildDepends(LinkDependsCheck) + include("${RunCMake_BINARY_DIR}/LinkDependsCheck-build/LinkDependsUseLinker.cmake") + if (CMAKE_C_LINK_DEPENDS_USE_LINKER) + run_BuildDepends(LinkDependsExternalLibrary) + unset(run_BuildDepends_skip_step_2) + run_BuildDepends(LinkDepends) + endif() +endif() diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 32ccef0..ada9132 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -295,6 +295,7 @@ endif() add_RunCMake_test(BuildDepends -DMSVC_VERSION=${MSVC_VERSION} -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} + -DCMAKE_C_LINK_DEPENDS_USE_COMPILER=${CMAKE_C_LINK_DEPENDS_USE_COMPILER} -DCMake_TEST_BuildDepends_GNU_AS=${CMake_TEST_BuildDepends_GNU_AS} ) if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja") diff --git a/Tests/RunCMake/TransformDepfile/deps-unix.d.txt b/Tests/RunCMake/TransformDepfile/deps-unix.d.txt index fbdecc0..2588181 100644 --- a/Tests/RunCMake/TransformDepfile/deps-unix.d.txt +++ b/Tests/RunCMake/TransformDepfile/deps-unix.d.txt @@ -1,8 +1,8 @@ subdir/out1 \ /home/build/out2: \ - subdir/in1 \ - /home/build/in2 + /home/build/in2 \ + subdir/in1 subdir/out3 \ /home/build/out4: \ - subdir/in3 \ - /home/build/in4 + /home/build/in4 \ + subdir/in3 diff --git a/Tests/RunCMake/TransformDepfile/deps-windows.d.txt b/Tests/RunCMake/TransformDepfile/deps-windows.d.txt index e09ae37..805a4c8 100644 --- a/Tests/RunCMake/TransformDepfile/deps-windows.d.txt +++ b/Tests/RunCMake/TransformDepfile/deps-windows.d.txt @@ -1,8 +1,8 @@ subdir/out1 \ C:/build/out2: \ - subdir/in1 \ - C:/build/in2 + C:/build/in2 \ + subdir/in1 subdir/out3 \ C:/build/out4: \ - subdir/in3 \ - C:/build/in4 + C:/build/in4 \ + subdir/in3 |