Skip to content

Commit da85ede

Browse files
authored
macOS: Fix #3901 - CMake quirks on macOS wrt. CMAKE_C[XX]_COMPILER (#4926)
See https://cmake.org/cmake/help/latest/policy/CMP0132.html.
1 parent ef844b7 commit da85ede

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

.github/actions/helper-build-ldc/action.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ runs:
3636
-DLLVM_ROOT_DIR="$PWD/../${{ inputs.llvm_dir }}" \
3737
-DD_COMPILER='${{ inputs.host_dc }}' \
3838
-DLDC_LINK_MANUALLY=OFF \
39-
${{ runner.os == 'macOS' && '-DCMAKE_C_COMPILER=/usr/bin/cc' || '' }} \
40-
${{ runner.os == 'macOS' && '-DCMAKE_CXX_COMPILER=/usr/bin/c++' || '' }} \
4139
${{ inputs.specify_install_dir == 'true' && '-DCMAKE_INSTALL_PREFIX="$installDir"' || '' }} \
4240
${{ inputs.specify_install_dir == 'true' && '-DINCLUDE_INSTALL_DIR="$installDir/import"' || '' }} \
4341
${{ inputs.cmake_flags }}

.github/workflows/supported_llvm_versions.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ jobs:
2828
os: macos-14
2929
host_dc: ldc-beta
3030
llvm_version: 17.0.5
31-
cmake_flags: -DBUILD_SHARED_LIBS=ON -DRT_SUPPORT_SANITIZERS=ON -DCMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/opt/zstd/lib -DCMAKE_C_COMPILER=/usr/bin/cc -DCMAKE_CXX_COMPILER=/usr/bin/c++
31+
cmake_flags: -DBUILD_SHARED_LIBS=ON -DRT_SUPPORT_SANITIZERS=ON -DCMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/opt/zstd/lib
3232
- job_name: macOS 14, LLVM 16, latest LDC beta
3333
os: macos-14
3434
host_dc: ldc-beta
3535
llvm_version: 16.0.5
36-
cmake_flags: -DBUILD_SHARED_LIBS=OFF -DCMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/opt/zstd/lib -DCMAKE_C_COMPILER=/usr/bin/cc -DCMAKE_CXX_COMPILER=/usr/bin/c++
36+
cmake_flags: -DBUILD_SHARED_LIBS=OFF -DCMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/opt/zstd/lib
3737
- job_name: Ubuntu 24.04, LLVM 15, latest DMD beta
3838
os: ubuntu-24.04
3939
host_dc: dmd-beta
4040
llvm_version: 15
41-
cmake_flags: -DBUILD_SHARED_LIBS=ON -DRT_SUPPORT_SANITIZERS=ON -DLIB_SUFFIX=64 -DLDC_LINK_MANUALLY=ON
41+
cmake_flags: -DBUILD_SHARED_LIBS=ON -DRT_SUPPORT_SANITIZERS=ON -DLIB_SUFFIX=64
4242
name: ${{ matrix.job_name }}
4343
runs-on: ${{ matrix.os }}
4444
env:
@@ -124,7 +124,6 @@ jobs:
124124
cmake -G Ninja . \
125125
-DCMAKE_BUILD_TYPE=Release \
126126
-DLLVM_ROOT_DIR=${{ runner.os == 'Linux' && format('/usr/lib/llvm-{0}', matrix.llvm_version) || '"$PWD/llvm"' }} \
127-
-DLDC_LINK_MANUALLY=OFF \
128127
${{ matrix.cmake_flags }}
129128
ninja obj/ldc2.o all ldc2-unittest all-test-runners
130129
bin/ldc2 --version

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.16.0)
22
if(POLICY CMP0025)
33
cmake_policy(SET CMP0025 NEW)
44
endif()
5+
if(POLICY CMP0132)
6+
# see https://github.com/ldc-developers/ldc/issues/3901
7+
cmake_policy(SET CMP0132 NEW)
8+
endif()
59
if(${CMAKE_VERSION} VERSION_GREATER "3.26.9")
610
# Prevent implicit dependencies for custom commands, e.g.,
711
# `obj/ldc2.o` depending on `lib/libldc.a` with LDC_LINK_MANUALLY=ON.

cmake/Modules/BuildDExecutable.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ function(build_d_executable target_name output_exe d_src_files compiler_args lin
100100

101101
# We need to link against the C++ runtime library.
102102
if(NOT MSVC AND "${D_COMPILER_ID}" STREQUAL "LDMD" AND NOT "${dflags}" MATCHES "(^|;)-gcc=")
103-
set(translated_linker_args "-gcc=${CMAKE_CXX_COMPILER}" ${translated_linker_args})
103+
if(CMAKE_VERSION VERSION_LESS "4.0.0" AND APPLE AND "${CMAKE_CXX_COMPILER}" MATCHES "/Developer/.+/usr/bin/c\\+\\+$")
104+
# see https://github.com/ldc-developers/ldc/issues/3901
105+
set(translated_linker_args "-gcc=/usr/bin/c++" ${translated_linker_args})
106+
else()
107+
set(translated_linker_args "-gcc=${CMAKE_CXX_COMPILER}" ${translated_linker_args})
108+
endif()
104109
endif()
105110

106111
# Use an extra custom target as dependency for the executable in

runtime/DRuntimeIntegrationTests.cmake

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,19 @@ else()
5757
list(REMOVE_ITEM testnames uuid)
5858
endif()
5959

60+
set(musl "")
6061
if(TARGET_SYSTEM MATCHES "musl")
6162
set(musl "IS_MUSL=1")
6263
endif()
6364

65+
set(cc "CC=${CMAKE_C_COMPILER}")
66+
set(cxx "CXX=${CMAKE_CXX_COMPILER}")
67+
if(CMAKE_VERSION VERSION_LESS "4.0.0" AND CMAKE_HOST_APPLE AND "${TARGET_SYSTEM}" MATCHES "APPLE")
68+
# see https://github.com/ldc-developers/ldc/issues/3901
69+
set(cc "")
70+
set(cxx "")
71+
endif()
72+
6473
foreach(name ${testnames})
6574
foreach(build debug release)
6675
set(druntime_path_build ${druntime_path})
@@ -78,10 +87,9 @@ foreach(name ${testnames})
7887
add_test(NAME ${fullname}
7988
COMMAND ${GNU_MAKE_BIN} -C ${PROJECT_SOURCE_DIR}/druntime/test/${name}
8089
ROOT=${outdir} DMD=${LDMD_EXE_FULL} BUILD=${build} SHARED=1
81-
CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER}
8290
DRUNTIME=${druntime_path_build} DRUNTIMESO=${shared_druntime_path_build}
83-
CFLAGS_BASE=${cflags_base} DFLAGS_BASE=${dflags_base} ${linkdl}
84-
IN_LDC=1 ${musl}
91+
${cc} ${cxx} CFLAGS_BASE=${cflags_base} DFLAGS_BASE=${dflags_base} ${linkdl}
92+
IN_LDC=1 ${musl}
8593
)
8694
set_tests_properties(${fullname} PROPERTIES DEPENDS clean-${fullname})
8795
endforeach()

0 commit comments

Comments
 (0)