From be3e51eadc6f7a42337211e6edb8877f1587f66d Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 4 Oct 2024 19:47:12 -0400 Subject: [PATCH] Use CMAKE_TRY_COMPILE_CONFIGURATION for MSVC --- cmake/modules/FindDEAL_II_MPI.cmake | 66 +++++++++++++++-------------- cmake/setup_compiler_flags.cmake | 1 + cmake/setup_sanity_checks.cmake | 2 + 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/cmake/modules/FindDEAL_II_MPI.cmake b/cmake/modules/FindDEAL_II_MPI.cmake index 01e313f0e1..8ad96111af 100644 --- a/cmake/modules/FindDEAL_II_MPI.cmake +++ b/cmake/modules/FindDEAL_II_MPI.cmake @@ -102,40 +102,42 @@ endif() # lld / ld.gold and missing libopen-pal.so on the link line: # -check_compiler_setup( - "${DEAL_II_CXX_FLAGS_SAVED} ${DEAL_II_CXX_FLAGS}" - "${DEAL_II_LINKER_FLAGS_SAVED} ${DEAL_II_LINKER_FLAGS}" - MPI_UNDERLINKAGE_OK - ${MPI_CXX_LIBRARIES} ${MPI_Fortran_LIBRARIES} ${MPI_C_LIBRARIES} - ) - -if(NOT MPI_UNDERLINKAGE_OK AND NOT "${MPI_CXX_LIBRARIES}" STREQUAL "") - # This check only works if MPI_CXX_LIBRARIES is non-empty, otherwise we will just give up - # and hope for the best... - message(STATUS "Trying to avoid underlinkage by expliclitly adding libopen-pal to link line") - - list(GET MPI_CXX_LIBRARIES 0 _lib) - get_filename_component(_hint ${_lib} DIRECTORY) - deal_ii_find_library(_mpi_libopen_pal_library - NAMES open-pal - HINTS ${_hint} - NO_DEFAULT_PATH - NO_CMAKE_ENVIRONMENT_PATH - NO_CMAKE_PATH - NO_SYSTEM_ENVIRONMENT_PATH - NO_CMAKE_SYSTEM_PATH - NO_CMAKE_FIND_ROOT_PATH +if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + check_compiler_setup( + "${DEAL_II_CXX_FLAGS_SAVED} ${DEAL_II_CXX_FLAGS}" + "${DEAL_II_LINKER_FLAGS_SAVED} ${DEAL_II_LINKER_FLAGS}" + MPI_UNDERLINKAGE_OK + ${MPI_CXX_LIBRARIES} ${MPI_Fortran_LIBRARIES} ${MPI_C_LIBRARIES} ) - # - # Note: We don't need to check whether the find library call is - # successful: If libopen-pal cannot be found then the - # process_feature will drop the library automatically. - # - # In this case the sanity check in cmake/setup_finalize.cmake will fail - # and we start dropping -fuse-ld=lld and -fuse-ld=ld.gold from the - # command line. - # + if(NOT MPI_UNDERLINKAGE_OK AND NOT "${MPI_CXX_LIBRARIES}" STREQUAL "") + # This check only works if MPI_CXX_LIBRARIES is non-empty, otherwise we will just give up + # and hope for the best... + message(STATUS "Trying to avoid underlinkage by expliclitly adding libopen-pal to link line") + + list(GET MPI_CXX_LIBRARIES 0 _lib) + get_filename_component(_hint ${_lib} DIRECTORY) + deal_ii_find_library(_mpi_libopen_pal_library + NAMES open-pal + HINTS ${_hint} + NO_DEFAULT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH + NO_CMAKE_FIND_ROOT_PATH + ) + + # + # Note: We don't need to check whether the find library call is + # successful: If libopen-pal cannot be found then the + # process_feature will drop the library automatically. + # + # In this case the sanity check in cmake/setup_finalize.cmake will fail + # and we start dropping -fuse-ld=lld and -fuse-ld=ld.gold from the + # command line. + # + endif() endif() process_feature(MPI diff --git a/cmake/setup_compiler_flags.cmake b/cmake/setup_compiler_flags.cmake index 9835801de2..d9c438180d 100644 --- a/cmake/setup_compiler_flags.cmake +++ b/cmake/setup_compiler_flags.cmake @@ -68,6 +68,7 @@ # foreach(build ${DEAL_II_BUILD_TYPES}) + set(CMAKE_TRY_COMPILE_CONFIGURATION ${build}) check_compiler_setup( "${DEAL_II_CXX_FLAGS_SAVED} ${DEAL_II_CXX_FLAGS_${build}_SAVED}" "${DEAL_II_LINKER_FLAGS_SAVED} ${DEAL_II_LINKER_FLAGS_${build}_SAVED}" diff --git a/cmake/setup_sanity_checks.cmake b/cmake/setup_sanity_checks.cmake index f52074c309..3f075b0705 100644 --- a/cmake/setup_sanity_checks.cmake +++ b/cmake/setup_sanity_checks.cmake @@ -24,6 +24,8 @@ # foreach(build ${DEAL_II_BUILD_TYPES}) + set(CMAKE_TRY_COMPILE_CONFIGURATION ${build}) + macro(_check_linker_flags) check_compiler_setup( "${DEAL_II_CXX_FLAGS} ${DEAL_II_CXX_FLAGS_${build}}" -- 2.39.5