diff options
author | Brad King <brad.king@kitware.com> | 2023-05-25 15:59:26 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-05-25 17:42:58 (GMT) |
commit | 023de565d33cdb095c0d5665e408493087e4d458 (patch) | |
tree | 8f52e06801201ec59cb11dab088dbd9a289f1be2 /Tests | |
parent | cf7b7600c669ea162e0c3960c3e4e3a5d04f3274 (diff) | |
download | CMake-023de565d33cdb095c0d5665e408493087e4d458.zip CMake-023de565d33cdb095c0d5665e408493087e4d458.tar.gz CMake-023de565d33cdb095c0d5665e408493087e4d458.tar.bz2 |
Optionally exclude implicit link directories via environment
A misconfigured compiler may pass extraneous implicit link directories
to its linker. If they are in `CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES`,
CMake may generate extra `-L` flags on mixed-language link lines that
break linking. Add an environment variable that users can set to work
around such misconfiguration of their compilers.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/ParseImplicitLinkInfo/ExcludeDirs.cmake | 10 | ||||
-rw-r--r-- | Tests/RunCMake/ParseImplicitLinkInfo/Inspect.cmake | 12 | ||||
-rw-r--r-- | Tests/RunCMake/ParseImplicitLinkInfo/RunCMakeTest.cmake | 8 |
3 files changed, 30 insertions, 0 deletions
diff --git a/Tests/RunCMake/ParseImplicitLinkInfo/ExcludeDirs.cmake b/Tests/RunCMake/ParseImplicitLinkInfo/ExcludeDirs.cmake new file mode 100644 index 0000000..6cece68 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitLinkInfo/ExcludeDirs.cmake @@ -0,0 +1,10 @@ +include("${info}") +list(GET INFO_CMAKE_C_IMPLICIT_LINK_DIRECTORIES -1 last_dir) +set(ENV{CMAKE_C_IMPLICIT_LINK_DIRECTORIES_EXCLUDE} "${last_dir}") +enable_language(C) +message(STATUS "INFO_CMAKE_C_IMPLICIT_LINK_DIRECTORIES=[${INFO_CMAKE_C_IMPLICIT_LINK_DIRECTORIES}]") +message(STATUS "ENV{CMAKE_C_IMPLICIT_LINK_DIRECTORIES_EXCLUDE}=[$ENV{CMAKE_C_IMPLICIT_LINK_DIRECTORIES_EXCLUDE}]") +message(STATUS "CMAKE_C_IMPLICIT_LINK_DIRECTORIES=[${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}]") +if("${last_dir}" IN_LIST CMAKE_C_IMPLICIT_LINK_DIRECTORIES) + message(FATAL_ERROR "${last_dir} was not excluded!") +endif() diff --git a/Tests/RunCMake/ParseImplicitLinkInfo/Inspect.cmake b/Tests/RunCMake/ParseImplicitLinkInfo/Inspect.cmake new file mode 100644 index 0000000..42e1c67 --- /dev/null +++ b/Tests/RunCMake/ParseImplicitLinkInfo/Inspect.cmake @@ -0,0 +1,12 @@ +enable_language(C) + +set(info "") +foreach(var + CMAKE_C_IMPLICIT_LINK_DIRECTORIES + ) + if(DEFINED ${var}) + string(APPEND info "set(INFO_${var} \"${${var}}\")\n") + endif() +endforeach() + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "${info}") diff --git a/Tests/RunCMake/ParseImplicitLinkInfo/RunCMakeTest.cmake b/Tests/RunCMake/ParseImplicitLinkInfo/RunCMakeTest.cmake index 713e2e7..c7655d2 100644 --- a/Tests/RunCMake/ParseImplicitLinkInfo/RunCMakeTest.cmake +++ b/Tests/RunCMake/ParseImplicitLinkInfo/RunCMakeTest.cmake @@ -1,3 +1,11 @@ include(RunCMake) run_cmake(ParseImplicitLinkInfo) + +run_cmake(Inspect) +set(info "${RunCMake_BINARY_DIR}/Inspect-build/info.cmake") +include("${info}") + +if(INFO_CMAKE_C_IMPLICIT_LINK_DIRECTORIES MATCHES ";") + run_cmake_with_options(ExcludeDirs "-Dinfo=${RunCMake_BINARY_DIR}/Inspect-build/info.cmake") +endif() |