Commit 326cceaa authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'cmake_library_architecture_better_multiarch_support'

657fc3a9

 CMakeDetermineCompilerABI: Parse library arch from versioned paths
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !5773
parents 4b406ead 657fc3a9
Pipeline #213274 failed with stages
in 17 minutes and 4 seconds
......@@ -8,6 +8,7 @@
include(${CMAKE_ROOT}/Modules/CMakeParseImplicitIncludeInfo.cmake)
include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
include(${CMAKE_ROOT}/Modules/CMakeParseLibraryArchitecture.cmake)
include(CMakeTestCompilerCommon)
function(CMAKE_DETERMINE_COMPILER_ABI lang src)
......@@ -175,27 +176,9 @@ 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)
# Detect library architecture directory name.
if(CMAKE_LIBRARY_ARCHITECTURE_REGEX)
foreach(dir ${implicit_dirs})
if("${dir}" MATCHES "/lib/${CMAKE_LIBRARY_ARCHITECTURE_REGEX}$")
get_filename_component(arch "${dir}" NAME)
set(CMAKE_${lang}_LIBRARY_ARCHITECTURE "${arch}" PARENT_SCOPE)
break()
endif()
endforeach()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL QCC)
foreach(dir ${implicit_dirs})
if (dir MATCHES "/lib$")
get_filename_component(assumedArchDir "${dir}" DIRECTORY)
get_filename_component(archParentDir "${assumedArchDir}" DIRECTORY)
if (archParentDir STREQUAL CMAKE_SYSROOT)
get_filename_component(archDirName "${assumedArchDir}" NAME)
set(CMAKE_${lang}_LIBRARY_ARCHITECTURE "${archDirName}" PARENT_SCOPE)
break()
endif()
endif()
endforeach()
cmake_parse_library_architecture("${implicit_dirs}" architecture_flag)
if(architecture_flag)
set(CMAKE_${lang}_LIBRARY_ARCHITECTURE "${architecture_flag}" PARENT_SCOPE)
endif()
else()
......
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
cmake_policy(PUSH)
cmake_policy(SET CMP0053 NEW)
cmake_policy(SET CMP0054 NEW)
# Function parse implicit linker options.
# This is used internally by CMake and should not be included by user
# code.
function(cmake_parse_library_architecture implicit_dirs output_var)
unset(library_arch)
# Detect library architecture directory name.
if(CMAKE_LIBRARY_ARCHITECTURE_REGEX)
foreach(dir ${implicit_dirs})
if("${dir}" MATCHES "/lib/${CMAKE_LIBRARY_ARCHITECTURE_REGEX}$")
get_filename_component(arch "${dir}" NAME)
set(library_arch "${arch}")
break()
endif()
endforeach()
endif()
if(CMAKE_LIBRARY_ARCHITECTURE_REGEX_VERSIONED AND NOT library_arch)
foreach(dir ${implicit_dirs})
if("${dir}" MATCHES "/${CMAKE_LIBRARY_ARCHITECTURE_REGEX_VERSIONED}$")
get_filename_component(arch "${dir}" DIRECTORY)
get_filename_component(arch "${arch}" NAME)
set(library_arch "${arch}")
break()
endif()
endforeach()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL QCC)
foreach(dir ${implicit_dirs})
if (dir MATCHES "/lib$")
get_filename_component(assumedArchDir "${dir}" DIRECTORY)
get_filename_component(archParentDir "${assumedArchDir}" DIRECTORY)
if (archParentDir STREQUAL CMAKE_SYSROOT)
get_filename_component(archDirName "${assumedArchDir}" NAME)
set(library_arch "${archDirName}")
break()
endif()
endif()
endforeach()
endif()
# Return results.
if(library_arch)
set(${output_var} "${library_arch}" PARENT_SCOPE)
endif()
endfunction()
cmake_policy(POP)
......@@ -48,6 +48,7 @@ endif()
# Match multiarch library directory names.
set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-linux-gnu[a-z0-9_]*")
set(CMAKE_LIBRARY_ARCHITECTURE_REGEX_VERSIONED "gcc/[a-z0-9_]+(-[a-z0-9_]+)?-linux(-gnu)?/[0-9]+(\\.[0-9]+\\.[0-9]+)*")
include(Platform/UnixPaths)
......
......@@ -50,6 +50,7 @@ else()
endif()
include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
include(${CMAKE_ROOT}/Modules/CMakeParseLibraryArchitecture.cmake)
#
# load_compiler_info: read infile, parsing out cmake compiler info
......@@ -80,6 +81,7 @@ function(load_compiler_info infile lang_var outcmvars_var outstr_var)
message("load_compiler_info: ${infile} no LANG info; default to C")
set(lang C)
endif()
set(${lang_var} "${lang}" PARENT_SCOPE)
set(${outcmvars_var} "${outcmvars}" PARENT_SCOPE)
set(${outstr_var} "${outstr}" PARENT_SCOPE)
......@@ -94,6 +96,21 @@ function(unload_compiler_info cmvars)
endforeach()
endfunction()
#
# load_platform_info: establish CMAKE_LIBRARY_ARCHITECTURE_REGEX
# based on the target platform.
#
function(load_platform_info target)
if(target MATCHES "linux-")
set(CMAKE_LIBRARY_ARCHITECTURE_REGEX "[a-z0-9_]+(-[a-z0-9_]+)?-linux-gnu[a-z0-9_]*" PARENT_SCOPE)
set(CMAKE_LIBRARY_ARCHITECTURE_REGEX_VERSIONED "gcc/[a-z0-9_]+(-[a-z0-9_]+)?-linux(-gnu)?/[0-9]+(\\.[0-9]+\\.[0-9]+)*" PARENT_SCOPE)
else()
unset(CMAKE_LIBRARY_ARCHITECTURE_REGEX PARENT_SCOPE)
unset(CMAKE_LIBRARY_ARCHITECTURE_REGEX_VERSIONED PARENT_SCOPE)
endif()
endfunction()
#
# main test loop
#
......@@ -112,10 +129,12 @@ foreach(t ${targets})
endif()
load_compiler_info(${infile} lang cmvars input)
load_platform_info(${t})
# Need to handle files with empty entries for both libs or dirs
set(implicit_lib_output "")
set(idirs_output "")
set(library_arch_output "")
file(STRINGS ${outfile} outputs)
foreach(line IN LISTS outputs)
if(line MATCHES "libs=")
......@@ -124,13 +143,19 @@ foreach(t ${targets})
if(line MATCHES "dirs=")
string(REPLACE "dirs=" "" idirs_output "${line}")
endif()
if(line MATCHES "library_arch=")
string(REPLACE "library_arch=" "" library_arch_output "${line}")
endif()
endforeach()
cmake_parse_implicit_link_info("${input}" implicit_libs idirs implicit_fwks log
"${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}")
set(library_arch)
cmake_parse_library_architecture("${idirs}" library_arch)
# File format
# file(WRITE ${outfile} "libs=${implicit_libs}\ndirs=${idirs}\n")
# file(WRITE ${outfile} "libs=${implicit_libs}\ndirs=${idirs}\nlibrary_arch=${library_arch}")
if(t MATCHES "-empty$") # empty isn't supposed to parse
if("${state}" STREQUAL "done")
......@@ -140,6 +165,8 @@ foreach(t ${targets})
message("${t} parse failed: state=${state}, '${idirs}' does not match '${idirs_output}'")
elseif(NOT "${implicit_libs}" STREQUAL "${implicit_lib_output}")
message("${t} parse failed: state=${state}, '${implicit_libs}' does not match '${implicit_lib_output}'")
elseif(library_arch AND NOT "${library_arch}" STREQUAL "${library_arch_output}")
message("${t} parse failed: state=${state}, '${library_arch}' does not match '${library_arch_output}'")
endif()
unload_compiler_info("${cmvars}")
......
libs=gcc;gcc_s;c;gcc;gcc_s
dirs=/usr/lib/gcc/x86_64-linux-gnu/7;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib
library_arch=x86_64-linux-gnu
libs=imf;svml;irng;m;ipgo;decimal;cilkrts;stdc++;gcc;gcc_s;irc;svml;c;gcc;gcc_s;irc_s;dl;c
dirs=/opt/intel/compilers_and_libraries_2018.0.128/linux/ipp/lib/intel64;/opt/intel/compilers_and_libraries_2018.0.128/linux/compiler/lib/intel64_lin;/opt/intel/compilers_and_libraries_2018.0.128/linux/mkl/lib/intel64_lin;/opt/intel/compilers_and_libraries_2018.0.128/linux/tbb/lib/intel64/gcc4.7;/usr/lib/gcc/x86_64-redhat-linux/4.8.5;/usr/lib64;/lib64;/usr/lib;/lib
library_arch=x86_64-redhat-linux
libs=pgmp;numa;pthread;pgmath;nspgc;pgc;m;gcc;c;gcc;gcc_s
dirs=/mnt/pgi/linux86-64/18.10/lib;/usr/lib64;/usr/lib/gcc/x86_64-linux-gnu/7
library_arch=x86_64-linux-gnu
libs=xlopt;xl;dl;gcc_s;gcc;m;c;gcc_s;gcc
dirs=/soft/compilers/ibmcmp-oct2017/xlsmp/bg/3.1/lib64;/soft/compilers/ibmcmp-oct2017/xlmass/bg/7.3/lib64;/soft/compilers/ibmcmp-oct2017/vac/bg/12.1/lib64;/soft/compilers/ibmcmp-oct2017/vacpp/bg/12.1/lib64;/usr/lib/gcc/ppc64-redhat-linux/4.4.7;/usr/lib64;/lib64;/usr/lib
library_arch=ppc64-redhat-linux
libs=xlopt;xl;dl;gcc_s;pthread;gcc;m;c;gcc_s;gcc
dirs=/opt/ibm/xlsmp/5.1.0/lib;/opt/ibm/xlmass/9.1.0/lib;/opt/ibm/xlC/16.1.0/lib;/usr/lib/gcc/ppc64le-redhat-linux/4.8.5;/usr/lib64;/lib64;/usr/lib
library_arch=ppc64le-redhat-linux
libs=cudadevrt;cudart_static;rt;pthread;dl;stdc++;m;gcc_s;gcc;c;gcc_s;gcc
dirs=/usr/local/cuda/targets/x86_64-linux/lib/stubs;/usr/local/cuda/targets/x86_64-linux/lib;/usr/lib/gcc/x86_64-linux-gnu/8;/usr/lib/x86_64-linux-gnu;/lib/x86_64-linux-gnu;/lib64;/usr/lib;/usr/lib/llvm-8/lib;/lib
library_arch=x86_64-linux-gnu
libs=cudadevrt;cudart_static;rt;pthread;dl;xlopt;xl;ibmc++;stdc++;m;dl;gcc_s;gcc;pthread;m;c;gcc_s;gcc
dirs=/sw/summit/cuda/10.1.168/targets/ppc64le-linux/lib/stubs;/sw/summit/cuda/10.1.168/targets/ppc64le-linux/lib;/autofs/nccs-svm1_sw/summit/.swci/1-compute/opt/spack/20180914/linux-rhel7-ppc64le/xl-16.1.1-3/spectrum-mpi-10.3.0.1-20190611-aqjt3jo53mogrrhcrd2iufr435azcaha/lib;/autofs/nccs-svm1_sw/summit/.swci/1-compute/opt/spack/20180914/linux-rhel7-ppc64le/gcc-4.8.5/darshan-runtime-3.1.7-csygoqyym3m3ysoaperhxlhoiluvpa2u/lib;/autofs/nccs-svm1_sw/summit/xl/16.1.1-3/xlsmp/5.1.1/lib;/autofs/nccs-svm1_sw/summit/xl/16.1.1-3/xlmass/9.1.1/lib;/autofs/nccs-svm1_sw/summit/xl/16.1.1-3/xlC/16.1.1/lib;/usr/lib/gcc/ppc64le-redhat-linux/4.8.5;/usr/lib64;/lib64;/autofs/nccs-svm1_sw/peak/.swci/1-compute/opt/spack/20180914/linux-rhel7-ppc64le/gcc-4.8.5/darshan-runtime-3.1.7-ytwv7xbkub6mqnpvygdthwqa7mhjqbc5/lib;/usr/lib
library_arch=ppc64le-redhat-linux
libs=cudadevrt;cudart_static;rt;pthread;dl;stdc++;m;gcc_s;gcc;c;gcc_s;gcc
dirs=/usr/lib/x86_64-linux-gnu/stubs;/usr/lib/gcc/x86_64-linux-gnu/5;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib
library_arch=x86_64-linux-gnu
libs=stdc++;m;gcc_s;gcc;c;gcc_s;gcc
dirs=/usr/lib/gcc/x86_64-linux-gnu/7;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib
library_arch=x86_64-linux-gnu
libs=imf;svml;irng;stdc++;m;ipgo;decimal;cilkrts;stdc++;gcc;gcc_s;irc;svml;c;gcc;gcc_s;irc_s;dl;c
dirs=/opt/intel/compilers_and_libraries_2018.0.128/linux/ipp/lib/intel64;/opt/intel/compilers_and_libraries_2018.0.128/linux/compiler/lib/intel64_lin;/opt/intel/compilers_and_libraries_2018.0.128/linux/mkl/lib/intel64_lin;/opt/intel/compilers_and_libraries_2018.0.128/linux/tbb/lib/intel64/gcc4.7;/usr/lib/gcc/x86_64-redhat-linux/4.8.5;/usr/lib64;/lib64;/usr/lib;/lib
library_arch=x86_64-redhat-linux
libs=atomic;pgatm;stdc++;pgmp;numa;pthread;pgmath;nspgc;pgc;m;gcc;c;gcc;gcc_s
dirs=/mnt/pgi/linux86-64/18.10/lib;/usr/lib64;/usr/lib/gcc/x86_64-linux-gnu/7
library_arch=x86_64-linux-gnu
libs=xlopt;xl;ibmc++;xlopt;xl;stdc++;m;dl;gcc_s;gcc;m;c;gcc_s;gcc;dl;gcc_s;gcc;m;c;gcc_s;gcc
dirs=/soft/compilers/ibmcmp-oct2017/xlsmp/bg/3.1/lib64;/soft/compilers/ibmcmp-oct2017/xlmass/bg/7.3/lib64;/soft/compilers/ibmcmp-oct2017/vac/bg/12.1/lib64;/soft/compilers/ibmcmp-oct2017/vacpp/bg/12.1/lib64;/usr/lib/gcc/ppc64-redhat-linux/4.4.7;/usr/lib64;/lib64;/usr/lib
library_arch=ppc64-redhat-linux
libs=xlopt;xl;ibmc++;stdc++;m;dl;gcc_s;gcc;pthread;m;c;gcc_s;gcc
dirs=/opt/ibm/xlsmp/5.1.0/lib;/opt/ibm/xlmass/9.1.0/lib;/opt/ibm/xlC/16.1.0/lib;/usr/lib/gcc/ppc64le-redhat-linux/4.8.5;/usr/lib64;/lib64;/usr/lib
library_arch=ppc64le-redhat-linux
libs=gfortran;m;gcc_s;gcc;quadmath;m;gcc_s;gcc;c;gcc_s;gcc
dirs=/usr/lib/gcc/x86_64-linux-gnu/7;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib
library_arch=x86_64-linux-gnu
libs=pgf90rtl;pgf90;pgf90_rpm1;pgf902;pgf90rtl;pgftnrtl;pgmp;numa;pthread;pgmath;nspgc;pgc;rt;pthread;m;gcc;c;gcc;gcc_s
dirs=/mnt/pgi/linux86-64/18.10/lib;/usr/lib64;/usr/lib/gcc/x86_64-linux-gnu/7
library_arch=x86_64-linux-gnu
libs=xlf90;xlopt;xlomp_ser;xl;xlfmath;gcc_s;dl;rt;pthread;gcc;m;c;gcc_s;gcc
dirs=/soft/compilers/ibmcmp-oct2017/xlsmp/bg/3.1/lib64;/soft/compilers/ibmcmp-oct2017/xlmass/bg/7.3/lib64;/soft/compilers/ibmcmp-oct2017/xlf/bg/14.1/lib64;/usr/lib/gcc/ppc64-redhat-linux/4.4.7;/usr/lib64;/lib64;/usr/lib
library_arch=ppc64-redhat-linux
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment