mirror of
https://github.com/Kitware/CMake.git
synced 2026-11-06 05:16:58 +00:00
LLVMFlang: Support Flang 18 and 19 on Apple platforms
Flang gained -Xlinker only in LLVM 20, so the Apple linker flags added
by commit 18d65b9d4b (LLVMFlang: Fix Fortran shared library creation on
Apple platforms, 2026-09-23) fail with older Flang. For those versions
the flags now go through -Wl, with the install name joined to its flag.
Flang 20 and later keep the -Xlinker form.
Fixes: #28148
This commit is contained in:
1 parent
c739e7ae98
commit
45208d7353
2 files changed
+20
-4
No files matched your search
@@ -3,7 +3,20 @@
|
||||
|
||||
# LLVM Flang requires Darwin linker flags to be passed through its linker
|
||||
# wrapper rather than directly to the compiler driver.
|
||||
set(CMAKE_Fortran_OSX_COMPATIBILITY_VERSION_FLAG "-Xlinker -compatibility_version -Xlinker ")
|
||||
set(CMAKE_Fortran_OSX_CURRENT_VERSION_FLAG "-Xlinker -current_version -Xlinker ")
|
||||
set(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS "-Xlinker -bundle")
|
||||
set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-Xlinker -install_name -Xlinker ")
|
||||
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 20)
|
||||
# Flang < 20 has no -Xlinker. The -Wl, form needs the install name joined
|
||||
# to its flag, without the space Darwin.cmake leaves after <SONAME_FLAG>.
|
||||
set(CMAKE_Fortran_OSX_COMPATIBILITY_VERSION_FLAG "-Wl,-compatibility_version,")
|
||||
set(CMAKE_Fortran_OSX_CURRENT_VERSION_FLAG "-Wl,-current_version,")
|
||||
set(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS "-Wl,-bundle")
|
||||
set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-Wl,-install_name,")
|
||||
foreach(rule IN ITEMS CREATE_SHARED_LIBRARY CREATE_MACOSX_FRAMEWORK)
|
||||
set(CMAKE_Fortran_${rule}
|
||||
"<CMAKE_Fortran_COMPILER> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> -o <TARGET> <SONAME_FLAG><TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
|
||||
endforeach()
|
||||
else()
|
||||
set(CMAKE_Fortran_OSX_COMPATIBILITY_VERSION_FLAG "-Xlinker -compatibility_version -Xlinker ")
|
||||
set(CMAKE_Fortran_OSX_CURRENT_VERSION_FLAG "-Xlinker -current_version -Xlinker ")
|
||||
set(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS "-Xlinker -bundle")
|
||||
set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-Xlinker -install_name -Xlinker ")
|
||||
endif()
|
||||
@@ -50,6 +50,9 @@ add_library(hello STATIC hello.f)
|
||||
add_library(world ${_SHARED} world.f ${world_def})
|
||||
if(APPLE AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
|
||||
set_target_properties(world PROPERTIES VERSION 1.2.3 SOVERSION 1)
|
||||
add_library(world_module MODULE world.f)
|
||||
add_library(world_framework SHARED world.f)
|
||||
set_target_properties(world_framework PROPERTIES FRAMEWORK TRUE)
|
||||
endif()
|
||||
add_executable(testf testf.f)
|
||||
target_link_libraries(testf hello world)
|
||||
|
||||
Reference in new issue
Block a user