Skip to content

Commit

Permalink
Use clang instead of clang-cl for CMake projects
Browse files Browse the repository at this point in the history
This will be a requirement for upcoming libobjc2 releases. libdispatch must still be built with clang-cl.
  • Loading branch information
triplef committed Feb 16, 2023
1 parent 25c0ff5 commit 6284bed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ where cmake
if %errorlevel% neq 0 call :error_missing_command cmake, "Visual Studio or 'choco install cmake --installargs ADD_CMAKE_TO_PATH=System'"
where ninja
if %errorlevel% neq 0 call :error_missing_command ninja, "'choco install ninja'"
where clang-cl
if %errorlevel% neq 0 call :error_missing_command clang-cl, "Visual Studio or 'choco install llvm'"
where clang
if %errorlevel% neq 0 call :error_missing_command clang, "Visual Studio or 'choco install llvm'"
call %BASH% 'true'
if %errorlevel% neq 0 call :error_missing_command MSYS2, "'choco install msys2'"
call %BASH% 'which make'
Expand Down
2 changes: 0 additions & 2 deletions phases/11-libobjc2.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ cmake .. %CMAKE_OPTIONS% ^

echo.
echo ### Building
set CCC_OVERRIDE_OPTIONS=x-TC x-TP x/TC x/TP
ninja || exit /b 1
set CCC_OVERRIDE_OPTIONS=

echo.
echo ### Installing
Expand Down
3 changes: 3 additions & 0 deletions phases/18-libdispatch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ echo.
echo ### Running cmake
:: CXX and linker flags below are to produce PDBs for release builds.
:: BlocksRuntime parameters provided to use blocks runtime from libobjc2 with libdispatch-own-blocksruntime.patch.
:: libdispatch only supports building with clang-cl frontend.
cmake .. %CMAKE_OPTIONS% ^
-D BUILD_SHARED_LIBS=YES ^
-D INSTALL_PRIVATE_HEADERS=YES ^
-D CMAKE_CXX_FLAGS_RELWITHDEBINFO="/Zi" ^
-D CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO="/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF" ^
-D BlocksRuntime_INCLUDE_DIR=%INSTALL_PREFIX%\include ^
-D BlocksRuntime_LIBRARIES=%INSTALL_PREFIX%\lib\objc.lib ^
-D CMAKE_C_COMPILER=clang-cl ^
-D CMAKE_CXX_COMPILER=clang-cl ^
|| exit /b 1

echo.
Expand Down
28 changes: 14 additions & 14 deletions scripts/sdkenv.bat
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ if "%ARCH%" == "x86" (
exit /b 1
)

:: compiler/linker flags
:: - -m32/64 flags are required to ensure the right architecture is built and linked,
:: and setting these via CFLAGS doesn't work because GNUstep Make ignores those,
:: so we set them as part of the compiler instead
:: - LLD linker is required for linking Objective C
if not defined CC set CC=clang %MFLAG%
if not defined CXX set CXX=clang++ %MFLAG%
if not defined OBJCC set OBJCC=clang %MFLAG%
if not defined OBJCXX set OBJCXX=clang++ %MFLAG%
:: compiler flags: -m32/64 is required to ensure the right architecture is
:: built and linked. Unfortunately GNUstep Make ignores those, so we also set
:: them as part of the compiler.
if not defined CFLAGS set CFLAGS=%MFLAG%
if not defined CXXFLAGS set CXXFLAGS=%MFLAG%
if not defined OBJCFLAGS set OBJCFLAGS=%MFLAG%
if not defined OBJCXXFLAGS set OBJCXXFLAGS=%MFLAG%
if not defined ASMFLAGS set ASMFLAGS=%MFLAG%
if not defined CC set "CC=clang %MFLAG%"
if not defined CXX set "CXX=clang++ %MFLAG%"
if not defined OBJCC set "OBJCC=clang %MFLAG%"
if not defined OBJCXX set "OBJCXX=clang++ %MFLAG%"

:: LLD linker is required for linking Objective C
set LDFLAGS=-fuse-ld=lld

:: common CMake options
:: - CMAKE_C(XX)_COMPILER_TARGET are required to ensure the right architecture is built and linked
set CMAKE_BUILD_TYPE=%BUILD_TYPE%
if "%BUILD_TYPE%" == "Release" set CMAKE_BUILD_TYPE=RelWithDebInfo
set CMAKE_OPTIONS=^
-G Ninja ^
-D CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% ^
-D CMAKE_INSTALL_PREFIX="%INSTALL_PREFIX%" ^
-D CMAKE_C_COMPILER=clang-cl ^
-D CMAKE_CXX_COMPILER=clang-cl ^
-D CMAKE_C_COMPILER_TARGET=%TARGET% ^
-D CMAKE_CXX_COMPILER_TARGET=%TARGET% ^

0 comments on commit 6284bed

Please sign in to comment.