File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ include(GNUInstallDirs)
4242include (FortranLib )
4343include (AddPatchedSource )
4444
45+ # Use llvm-ar for IntelLLVM Fortran compiler
46+ include (UseLlvmArchive )
47+
4548# Common compiler flags and definitions
4649if (CMAKE_Fortran_COMPILER_ID MATCHES "GNU" )
4750 set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fbacktrace -fconvert=big-endian -ffree-line-length-none -ffixed-line-length-none" )
Original file line number Diff line number Diff line change 1+ # Use llvm-ar with `rcs` so we dont need to setup a separate ranlib.
2+
3+ # Identify compiler is IntelLLVM
4+ # https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
5+ if (NOT (CMAKE_Fortran_COMPILER_ID MATCHES "IntelLLVM" ))
6+ return ()
7+ endif ()
8+
9+ # set a temp variable to hold the Fortran compiler path
10+ set (_TMP_VAR "" )
11+ if (CMAKE_Fortran_COMPILER)
12+ set (_TMP_VAR "${CMAKE_Fortran_COMPILER} " )
13+ endif ()
14+
15+ # try to discover full paths to llvm-ar
16+ # https://cmake.org/cmake/help/latest/command/execute_process.html
17+ if (_TMP_VAR)
18+ execute_process (
19+ COMMAND "${_TMP_VAR} " -print-prog-name=llvm-ar
20+ OUTPUT_VARIABLE LLVM_AR_PATH
21+ OUTPUT_STRIP_TRAILING_WHITESPACE
22+ )
23+ endif ()
24+
25+ # enforce llvm-ar
26+ set (CMAKE_AR "${LLVM_AR_PATH} " CACHE FILEPATH "" FORCE )
27+
28+ # write index table via `s` flag, which disables separate ranlib step.
29+ # https://github.com/Kitware/CMake/blob/1c7fe4dc0b47de90bec6918b33f0aca47d688887/Modules/CMakeCInformation.cmake#L152-L162
30+ # https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_ARCHIVE_FINISH.html
31+ #
32+ set (CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> rcs <TARGET> <OBJECTS>" )
33+ set (CMAKE_Fortran_ARCHIVE_FINISH "" )
34+
35+ unset (_TMP_VAR)
You can’t perform that action at this time.
0 commit comments