summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2021-04-05 15:28:54 -0400
committerRobert Maynard <rmaynard@nvidia.com>2021-04-05 17:41:10 -0400
commit764606e25616e9f47eceb3227a3b38fcef544820 (patch)
tree7a37b1499cf84a1da7fbae42f84c460f2c645eaf /Modules
parent5d44d73bbeaf04412aa744354cca9de8376cdfed (diff)
downloadcmake-764606e25616e9f47eceb3227a3b38fcef544820.tar.gz
CMakeDetermineCompilerABI: Extract lib arch from implicit object file paths
The NVHPC compiler does not have any implicit link directories that can be used to detect `CMAKE_LIBRARY_ARCHITECTURE`, but it does have implicit object files. Extract implicit object file paths from link lines and check them for the `CMAKE_LIBRARY_ARCHITECTURE` pattern. Issue: #22024
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeDetermineCompilerABI.cmake6
-rw-r--r--Modules/CMakeParseImplicitLinkInfo.cmake49
-rw-r--r--Modules/CMakeParseLibraryArchitecture.cmake13
3 files changed, 57 insertions, 11 deletions
diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake
index cf028f1812..8191d819bf 100644
--- a/Modules/CMakeDetermineCompilerABI.cmake
+++ b/Modules/CMakeDetermineCompilerABI.cmake
@@ -135,11 +135,13 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src)
# Parse implicit linker information for this language, if available.
set(implicit_dirs "")
+ set(implicit_objs "")
set(implicit_libs "")
set(implicit_fwks "")
if(CMAKE_${lang}_VERBOSE_FLAG)
CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs implicit_fwks log
- "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}")
+ "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}"
+ COMPUTE_IMPLICIT_OBJECTS implicit_objs)
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Parsed ${lang} implicit link information from above output:\n${log}\n\n")
endif()
@@ -176,7 +178,7 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src)
set(CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES "${implicit_dirs}" PARENT_SCOPE)
set(CMAKE_${lang}_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "${implicit_fwks}" PARENT_SCOPE)
- cmake_parse_library_architecture("${implicit_dirs}" architecture_flag)
+ cmake_parse_library_architecture(${lang} "${implicit_dirs}" "${implicit_objs}" architecture_flag)
if(architecture_flag)
set(CMAKE_${lang}_LIBRARY_ARCHITECTURE "${architecture_flag}" PARENT_SCOPE)
endif()
diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake
index 04655156e9..e848b55549 100644
--- a/Modules/CMakeParseImplicitLinkInfo.cmake
+++ b/Modules/CMakeParseImplicitLinkInfo.cmake
@@ -5,16 +5,27 @@ cmake_policy(PUSH)
cmake_policy(SET CMP0053 NEW)
cmake_policy(SET CMP0054 NEW)
-# Function parse implicit linker options.
+# Function to parse implicit linker options.
+#
# This is used internally by CMake and should not be included by user
# code.
-
+#
+# Note: this function is leaked/exposed by FindOpenMP and therefore needs
+# to have a stable API so projects that copied `FindOpenMP` for backwards
+# compatibility don't break.
+#
function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj_regex)
set(implicit_libs_tmp "")
+ set(implicit_objs_tmp "")
set(implicit_dirs_tmp)
set(implicit_fwks_tmp)
set(log "")
+ set(keywordArgs)
+ set(oneValueArgs COMPUTE_IMPLICIT_OBJECTS)
+ set(multiValueArgs )
+ cmake_parse_arguments(EXTRA_PARSE "${keywordArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
# Parse implicit linker arguments.
set(linker "CMAKE_LINKER-NOTFOUND")
if(CMAKE_LINKER)
@@ -103,11 +114,15 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj
set(lib "${CMAKE_MATCH_2}")
list(APPEND implicit_libs_tmp ${lib})
string(APPEND log " arg [${arg}] ==> lib [${lib}]\n")
- elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.o$"
- AND obj_regex AND "${arg}" MATCHES "${obj_regex}")
- # Object file full path.
- list(APPEND implicit_libs_tmp ${arg})
- string(APPEND log " arg [${arg}] ==> obj [${arg}]\n")
+ elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.o$")
+ if(EXTRA_PARSE_COMPUTE_IMPLICIT_OBJECTS)
+ list(APPEND implicit_objs_tmp ${arg})
+ string(APPEND log " arg [${arg}] ==> obj [${arg}]\n")
+ endif()
+ if(obj_regex AND "${arg}" MATCHES "${obj_regex}")
+ # Object file full path.
+ list(APPEND implicit_libs_tmp ${arg})
+ endif()
elseif("${arg}" MATCHES "^-Y(P,)?[^0-9]")
# Sun search path ([^0-9] avoids conflict with Mac -Y<num>).
string(REGEX REPLACE "^-Y(P,)?" "" dirs "${arg}")
@@ -170,6 +185,21 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj
endif()
endforeach()
+ if(EXTRA_PARSE_COMPUTE_IMPLICIT_OBJECTS)
+ set(implicit_objs "")
+ foreach(obj IN LISTS implicit_objs_tmp)
+ if(IS_ABSOLUTE "${obj}")
+ get_filename_component(abs "${obj}" ABSOLUTE)
+ if(NOT "x${obj}" STREQUAL "x${abs}")
+ string(APPEND log " collapse obj [${obj}] ==> [${abs}]\n")
+ endif()
+ list(APPEND implicit_objs "${abs}")
+ else()
+ list(APPEND implicit_objs "${obj}")
+ endif()
+ endforeach()
+ endif()
+
# Cleanup list of library and framework directories.
set(desc_dirs "library")
set(desc_fwks "framework")
@@ -191,6 +221,7 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj
# Log results.
string(APPEND log " implicit libs: [${implicit_libs}]\n")
+ string(APPEND log " implicit objs: [${implicit_objs}]\n")
string(APPEND log " implicit dirs: [${implicit_dirs}]\n")
string(APPEND log " implicit fwks: [${implicit_fwks}]\n")
@@ -199,6 +230,10 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj
set(${dir_var} "${implicit_dirs}" PARENT_SCOPE)
set(${fwk_var} "${implicit_fwks}" PARENT_SCOPE)
set(${log_var} "${log}" PARENT_SCOPE)
+
+ if(EXTRA_PARSE_COMPUTE_IMPLICIT_OBJECTS)
+ set(${EXTRA_PARSE_COMPUTE_IMPLICIT_OBJECTS} "${implicit_objs}" PARENT_SCOPE)
+ endif()
endfunction()
cmake_policy(POP)
diff --git a/Modules/CMakeParseLibraryArchitecture.cmake b/Modules/CMakeParseLibraryArchitecture.cmake
index f2bb07a658..6fb9c6bfce 100644
--- a/Modules/CMakeParseLibraryArchitecture.cmake
+++ b/Modules/CMakeParseLibraryArchitecture.cmake
@@ -9,17 +9,26 @@ cmake_policy(SET CMP0054 NEW)
# This is used internally by CMake and should not be included by user
# code.
-function(cmake_parse_library_architecture implicit_dirs output_var)
+function(cmake_parse_library_architecture lang implicit_dirs implicit_objs output_var)
unset(library_arch)
# Detect library architecture directory name.
if(CMAKE_LIBRARY_ARCHITECTURE_REGEX)
- foreach(dir ${implicit_dirs})
+ foreach(dir IN LISTS implicit_dirs)
if("${dir}" MATCHES "/lib/${CMAKE_LIBRARY_ARCHITECTURE_REGEX}$")
get_filename_component(arch "${dir}" NAME)
set(library_arch "${arch}")
break()
endif()
endforeach()
+
+ foreach(obj IN LISTS implicit_objs)
+ get_filename_component(dir "${obj}" DIRECTORY)
+ if("${dir}" MATCHES "(/usr)+/lib/${CMAKE_LIBRARY_ARCHITECTURE_REGEX}$")
+ get_filename_component(arch "${dir}" NAME)
+ set(library_arch "${arch}")
+ break()
+ endif()
+ endforeach()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL QCC)