Skip to content

Commit ab04522

Browse files
committed
Make cmake build work on MacOS
1 parent c5bc332 commit ab04522

15 files changed

Lines changed: 321 additions & 136 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ wiShaderdump.h
216216

217217
# vscode
218218
.vscode/settings.json
219+
/.vscode/
219220

220221
# PlayStation
221222
*.tlog

CMakeLists.txt

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,25 @@ option(USE_LIBCXX "Link WickedEngine to llvm libc++ library - only available wit
2727
option(WICKED_EDITOR "Build WickedEngine editor" ON)
2828
option(WICKED_TESTS "Build WickedEngine tests" ON)
2929
option(WICKED_IMGUI_EXAMPLE "Build WickedEngine imgui example" ON)
30-
option(WICKED_ENABLE_IPO "Enable IPO/LTO in non-debug builds" NO)
31-
option(WICKED_EMBED_SHADERS "Embed shaders into the library" NO)
30+
option(WICKED_ENABLE_IPO "Enable IPO/LTO in non-debug builds" OFF)
31+
option(WICKED_EMBED_SHADERS "Embed shaders into the library" OFF)
3232
option(WICKED_ENABLE_RTTI "Enable RTTI" NO)
33-
if(UNIX)
33+
if (APPLE)
34+
set(WICKED_TESTS OFF) # no main for macos
35+
set(WICKED_IMGUI_EXAMPLE OFF) # no main for macos
36+
set(WICKED_ENABLE_IPO OFF)
37+
endif()
38+
39+
if(UNIX AND NOT APPLE)
3440
option(WICKED_ENABLE_ASAN "Enable AddressSanitizer in debug builds" OFF)
3541
option(WICKED_ENABLE_UBSAN "Enable UndefinedBehaviourSanitizer in debug builds" OFF)
3642
option(WICKED_ENABLE_TSAN "Enable ThreadSanitizer in debug builds" OFF)
3743
option(WICKED_ENABLE_SAN_ALWAYS "Enable the selected sanitizers in all builds, not just debug" OFF)
3844
endif()
39-
if(UNIX)
45+
46+
if(APPLE)
47+
option(WICKED_MACOS_TEMPLATE "Build WickedEngine MacOS template" ON)
48+
elseif(UNIX)
4049
option(WICKED_LINUX_TEMPLATE "Build WickedEngine Linux template" ON)
4150
elseif(WIN32)
4251
option(WICKED_WINDOWS_TEMPLATE "Build WickedEngine Windows template" ON)
@@ -113,6 +122,15 @@ if (WIN32)
113122
set(PLATFORM "Windows")
114123
add_compile_definitions(WIN32=1)
115124
add_compile_definitions(_HAS_EXCEPTIONS=0)
125+
elseif (APPLE)
126+
# set(CMAKE_C_COMPILER /opt/homebrew/opt/llvm/bin/clang)
127+
# set(CMAKE_CXX_COMPILER /opt/homebrew/opt/llvm/bin/clang++)
128+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
129+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
130+
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
131+
set(CMAKE_LINKER ld64.lld)
132+
set(PLATFORM "MacOS")
133+
add_compile_definitions(MACOS=1)
116134
elseif (UNIX)
117135
set(PLATFORM "SDL2")
118136
add_compile_definitions(SDL2=1)
@@ -147,7 +165,7 @@ else()
147165
# security checks disabled in Release:
148166
$<$<CONFIG:Release>:-fno-stack-protector>
149167
$<$<CONFIG:Release>:-fcf-protection=none>
150-
$<$<AND:$<CONFIG:Release>,$<NOT:$<PLATFORM_ID:Windows>>>:-fno-stack-clash-protection> # not supported on Windows
168+
$<$<AND:$<CONFIG:Release>,$<NOT:$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Darwin>>>>:-fno-stack-clash-protection> # not supported on Windows or macOS
151169
$<$<CONFIG:Release>:-fno-stack-check>
152170
$<$<AND:$<CONFIG:Release>,$<NOT:$<PLATFORM_ID:Windows>>>:-fno-asynchronous-unwind-tables> # seems to crash LUA evaluation on Windows
153171
)
@@ -206,6 +224,10 @@ if (WICKED_LINUX_TEMPLATE)
206224
add_subdirectory(Samples/Template_Linux)
207225
endif()
208226

227+
if (WICKED_MACOS_TEMPLATE)
228+
add_subdirectory(Samples/Template_MacOS)
229+
endif()
230+
209231
if (WICKED_WINDOWS_TEMPLATE)
210232
add_subdirectory(Samples/Template_Windows)
211233
endif()

Editor/CMakeLists.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ string(REGEX REPLACE "([.+?*])" "\\\\\\1" SDIR "${CMAKE_CURRENT_SOURCE_DIR}")
66
file(GLOB SOURCE_FILES CONFIGURE_DEPENDS *.cpp)
77
list(FILTER SOURCE_FILES EXCLUDE REGEX ${SDIR}/main_.*)
88
list(FILTER SOURCE_FILES EXCLUDE REGEX ${SDIR}/stdafx.*)
9-
list(APPEND SOURCE_FILES main_${PLATFORM}.cpp)
109

10+
if (APPLE)
11+
list(APPEND SOURCE_FILES main_MacOS.mm)
12+
# PCH has disabled objective C, so don't use PCH
13+
set_source_files_properties(main_MacOS.mm PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
14+
else()
15+
list(APPEND SOURCE_FILES main_${PLATFORM}.cpp)
16+
endif()
1117

1218
if (WIN32)
1319
list (APPEND SOURCE_FILES
@@ -30,6 +36,22 @@ if (WIN32)
3036

3137
set_property(TARGET Editor PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
3238
set(LIB_DXCOMPILER "dxcompiler.dll")
39+
elseif (APPLE)
40+
add_executable(Editor ${SOURCE_FILES})
41+
42+
find_library(APPKIT_FRAMEWORK AppKit REQUIRED)
43+
44+
target_link_libraries(Editor PUBLIC
45+
WickedEngine
46+
${APPKIT_FRAMEWORK}
47+
)
48+
set(LIB_DXCOMPILER "libdxcompiler.dylib")
49+
50+
# needed for proper names in crash stacktrace
51+
set_target_properties(Editor
52+
PROPERTIES
53+
ENABLE_EXPORTS ON
54+
)
3355
else ()
3456
add_executable(Editor ${SOURCE_FILES})
3557

Samples/Example_ImGui/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ if (WIN32)
4343
Example_ImGui_Lib
4444
)
4545
set(LIB_DXCOMPILER "dxcompiler.dll")
46+
elseif(APPLE)
47+
# TODO
48+
set(LIB_DXCOMPILER "dxcompiler.dylib")
4649
else()
4750
list(APPEND SOURCE_FILES
4851
main_SDL2.cpp
@@ -76,10 +79,10 @@ else()
7679
endif ()
7780

7881
if(WICKED_ENABLE_IPO)
79-
set_target_properties(Example_ImGui PROPERTIES
80-
INTERPROCEDURAL_OPTIMIZATION ON
81-
INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF
82-
)
82+
set_target_properties(Example_ImGui PROPERTIES
83+
INTERPROCEDURAL_OPTIMIZATION ON
84+
INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF
85+
)
8386
endif()
8487

8588
if (MSVC)

Samples/Example_ImGui_Docking/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ if (WIN32)
4747
Example_ImGui_Docking_Lib
4848
)
4949
set(LIB_DXCOMPILER "dxcompiler.dll")
50+
elseif(APPLE)
51+
set(LIB_DXCOMPILER "dxcompiler.dylib")
5052
else()
5153
list(APPEND SOURCE_FILES
5254
main_SDL2.cpp
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 3.19)
2+
project(Template_MacOS)
3+
4+
# if the engine is installed system-wise,
5+
# you can set INSTALLED_ENGINE to ON
6+
# moving your project folder wherever you want
7+
set(INSTALLED_ENGINE OFF)
8+
# you may also want to remove the copy mechanism of the startup.lua file
9+
10+
if (${INSTALLED_ENGINE})
11+
find_package(WickedEngine REQUIRED)
12+
endif()
13+
14+
set(SOURCE_FILES
15+
main.mm
16+
)
17+
18+
set(LIB_DXCOMPILER "libdxcompiler.dylib")
19+
20+
add_executable(Template_MacOS ${SOURCE_FILES})
21+
22+
target_link_libraries(Template_MacOS PUBLIC
23+
$<IF:$<BOOL:${INSTALLED_ENGINE}>,WickedEngine::WickedEngine,WickedEngine>
24+
)
25+
26+
if(WICKED_ENABLE_IPO)
27+
set_target_properties(Template_MacOS PROPERTIES
28+
INTERPROCEDURAL_OPTIMIZATION ON
29+
INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF
30+
)
31+
endif()
32+
33+
if (${INSTALLED_ENGINE})
34+
get_property(LIBDXCOMPILER_PATH
35+
TARGET WickedEngine::dxcompiler
36+
PROPERTY IMPORTED_LOCATION)
37+
get_filename_component(WICKED_LIBFOLDER ${LIBDXCOMPILER_PATH} DIRECTORY)
38+
else()
39+
set(LIBDXCOMPILER_PATH "${WICKED_ROOT_DIR}/WickedEngine/${LIB_DXCOMPILER}")
40+
endif()
41+
message("libdxcompiler found at ${LIBDXCOMPILER_PATH}")
42+
43+
add_custom_command(
44+
TARGET Template_MacOS POST_BUILD
45+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBDXCOMPILER_PATH} ${CMAKE_CURRENT_BINARY_DIR}
46+
)

Samples/Tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ if (WIN32)
1818
)
1919

2020
set(LIB_DXCOMPILER "dxcompiler.dll")
21+
elseif(APPLE)
22+
23+
set(LIB_DXCOMPILER "dxcompiler.dylib")
2124
else()
2225
list (APPEND SOURCE_FILES
2326
main_SDL2.cpp

0 commit comments

Comments
 (0)