Skip to content

Commit 0c55b44

Browse files
committed
cmake: extend DaemonPlatform/System to detect host system and target system
1 parent 1d6b6b4 commit 0c55b44

File tree

9 files changed

+236
-67
lines changed

9 files changed

+236
-67
lines changed

CMakeLists.txt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ if(NOT DAEMON_EXTERNAL_APP)
9090

9191
set(NACL_RUNTIME_PATH "" CACHE STRING "Directory containing the NaCl binaries")
9292

93-
if (WIN32)
93+
if (DAEMON_TARGET_SYSTEM_Windows)
9494
# The alternative code is based on non-curses unix terminal functions.
9595
set(USE_CURSES ON)
9696
else()
97-
if (NOT APPLE)
97+
if (NOT DAEMON_TARGET_SYSTEM_macOS)
9898
# Not supported on macOS because the included version is too old.
9999
option(USE_CURSES_NCURSES "Use ncurses instead of PDCursesMod" ON)
100100
endif()
@@ -199,7 +199,7 @@ endmacro()
199199

200200
set(DEFAULT_USE_EXTERNAL_DEPS_LIBS ON)
201201

202-
if (USE_EXTERNAL_DEPS AND NOT NACL)
202+
if (USE_EXTERNAL_DEPS AND NOT DAEMON_TARGET_SYSTEM_NaCl)
203203
set(EXTERNAL_DEPS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external_deps" CACHE STRING "Directory in which to store the downloaded dependencies.")
204204

205205
set(DEPS_EXT ".tar.xz")
@@ -214,10 +214,10 @@ if (USE_EXTERNAL_DEPS AND NOT NACL)
214214
set(DEPS_COMPILER default)
215215
endif()
216216

217-
if (WIN32)
217+
if (DAEMON_TARGET_SYSTEM_Windows)
218218
set(DEPS_SYSTEM windows)
219219
set(SUPPORTED_${DEPS_SYSTEM}_ARCH amd64 i686)
220-
elseif (APPLE)
220+
elseif (DAEMON_TARGET_SYSTEM_macOS)
221221
set(DEPS_SYSTEM macos)
222222
set(SUPPORTED_${DEPS_SYSTEM}_ARCH amd64)
223223

@@ -230,10 +230,10 @@ if (USE_EXTERNAL_DEPS AND NOT NACL)
230230
set(DEFAULT_USE_EXTERNAL_DEPS_LIBS OFF)
231231
endif()
232232
endif()
233-
elseif (LINUX)
233+
elseif (DAEMON_TARGET_SYSTEM_Linux)
234234
set(DEPS_SYSTEM linux)
235235
set(SUPPORTED_${DEPS_SYSTEM}_ARCH amd64 i686 arm64 armhf)
236-
elseif (FREEBSD)
236+
elseif (DAEMON_TARGET_SYSTEM_FreeBSD)
237237
set(DEPS_SYSTEM freebsd)
238238
set(SUPPORTED_${DEPS_SYSTEM}_ARCH amd64 i686)
239239

@@ -264,7 +264,7 @@ endif()
264264

265265
option(USE_EXTERNAL_DEPS_LIBS "Build and link against libraries from the EXTERNAL_DEPS_DIR" ${DEFAULT_USE_EXTERNAL_DEPS_LIBS})
266266

267-
if (USE_EXTERNAL_DEPS AND NOT NACL)
267+
if (USE_EXTERNAL_DEPS AND NOT DAEMON_TARGET_SYSTEM_NaCl)
268268
if (DEPS_DIR)
269269
message(STATUS "Using external deps dir: ${DEPS_DIR}")
270270

@@ -462,23 +462,23 @@ endif()
462462

463463
# Native client
464464
include(DaemonNacl)
465-
if (NACL)
465+
if (DAEMON_TARGET_SYSTEM_NaCl)
466466
add_library(srclibs-nacl-module EXCLUDE_FROM_ALL ${NACLLIST_MODULE})
467467
set(LIBS_BASE ${LIBS_BASE} srclibs-nacl-module)
468468
else()
469469
add_library(srclibs-nacl-native EXCLUDE_FROM_ALL ${NACLLIST_NATIVE})
470470
set_target_properties(srclibs-nacl-native PROPERTIES POSITION_INDEPENDENT_CODE 1 FOLDER "libs")
471-
if (APPLE)
471+
if (DAEMON_TARGET_SYSTEM_macOS)
472472
# Do not error for OSAtomic* deprecation notices
473473
target_compile_options(srclibs-nacl-native PRIVATE "-Wno-error=deprecated-declarations")
474474
endif()
475475
set(LIBS_BASE ${LIBS_BASE} srclibs-nacl-native)
476476
endif()
477477

478478
# Base OS libs
479-
if (WIN32)
479+
if (DAEMON_TARGET_SYSTEM_Windows)
480480
set(LIBS_BASE ${LIBS_BASE} winmm ws2_32)
481-
elseif (NACL)
481+
elseif (DAEMON_TARGET_SYSTEM_NaCl)
482482
find_library(NACL_EXCEPTION nacl_exception)
483483
find_library(NACL_MINIDUMP minidump_generator)
484484

@@ -510,7 +510,7 @@ else()
510510
set(LIBS_BASE ${LIBS_BASE} ${CMAKE_DL_LIBS})
511511
find_package(Threads REQUIRED)
512512
set(LIBS_BASE ${LIBS_BASE} ${CMAKE_THREAD_LIBS_INIT})
513-
if (APPLE)
513+
if (DAEMON_TARGET_SYSTEM_macOS)
514514
set(LIBS_CLIENT ${LIBS_CLIENT} "-framework Carbon" "-framework IOKit" "-framework Cocoa")
515515
endif()
516516
endif()
@@ -533,7 +533,7 @@ else()
533533

534534
# Look for OpenGL here before we potentially switch to looking for static libs.
535535
if (BUILD_CLIENT)
536-
if (LINUX OR FREEBSD)
536+
if (DAEMON_TARGET_SYSTEM_Linux OR DAEMON_TARGET_SYSTEM_FreeBSD)
537537
# Set LEGACY OpenGL ABI if the variable is not explictly set.
538538
# The backward-incompatible GLVND OpenGL ABI should only be used
539539
# by developers who have a good reason to require it.
@@ -549,7 +549,7 @@ else()
549549
# This code is unreachable since it already errored out at find_package time.
550550
# This code only executes if OpenGL is supported, either because the GLVND ABI
551551
# is available, either because the LEGACY ABI is available.
552-
if (LINUX OR FREEBSD)
552+
if (DAEMON_TARGET_SYSTEM_Linux OR DAEMON_TARGET_SYSTEM_FreeBSD)
553553
if (NOT OPENGL_gl_LIBRARY)
554554
# When OpenGL_GL_PREFERENCE is supported and GLVND is available
555555
# OPENGL_gl_LIBRARY is expected to be empty. So we can use the
@@ -596,7 +596,7 @@ endif()
596596

597597
# Prefer static libs
598598
if ( USE_STATIC_LIBS )
599-
if (LINUX OR FREEBSD)
599+
if (DAEMON_TARGET_SYSTEM_Linux OR DAEMON_TARGET_SYSTEM_FreeBSD)
600600
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
601601
endif()
602602
endif()
@@ -624,7 +624,7 @@ if (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER OR BUILD_DUMMY_APP)
624624
set(LIBS_ENGINE_BASE ${LIBS_ENGINE_BASE} ${CURSESW_LIBRARIES})
625625
include_directories(${CURSESW_INCLUDE_DIR})
626626
else ()
627-
if (WIN32)
627+
if (DAEMON_TARGET_SYSTEM_Windows)
628628
set(LIBS_ENGINE_BASE ${LIBS_ENGINE_BASE} gdi32 comdlg32)
629629
endif()
630630

@@ -674,7 +674,7 @@ if (BUILD_CLIENT OR BUILD_TTY_CLIENT)
674674
endif()
675675

676676
# SDL, required for all targets on win32 because of iconv and SDL_SetHint(SDL_TIMER_RESOLUTION, 0)
677-
if (BUILD_CLIENT OR WIN32)
677+
if (BUILD_CLIENT OR DAEMON_TARGET_SYSTEM_Windows)
678678
# Use our detected architecture instead of letting SDL do it again
679679
# Note that sdlcpu.cmake is only included on a random subset of platforms
680680
set(sdlvar_i686 SDL_CPU_X86)
@@ -689,7 +689,7 @@ if (BUILD_CLIENT OR WIN32)
689689

690690
find_package(SDL3 REQUIRED CONFIG)
691691

692-
if (WIN32)
692+
if (DAEMON_TARGET_SYSTEM_Windows)
693693
set(LIBS_ENGINE_BASE ${LIBS_ENGINE_BASE} SDL3::SDL3)
694694
else()
695695
set(LIBS_CLIENT ${LIBS_CLIENT} SDL3::SDL3)
@@ -701,7 +701,7 @@ if (USE_BREAKPAD)
701701
add_definitions(-DUSE_BREAKPAD)
702702
include_directories(${LIB_DIR}/breakpad/src)
703703

704-
if (WIN32)
704+
if (DAEMON_TARGET_SYSTEM_Windows)
705705
add_library(srclibs-breakpad-common EXCLUDE_FROM_ALL ${BREAKPAD_COMMON_LIST})
706706
add_library(srclibs-breakpad-crash_generation_server EXCLUDE_FROM_ALL ${BREAKPAD_CRASHGENERATIONSERVER_LIST})
707707
add_library(srclibs-breakpad-exception_handler EXCLUDE_FROM_ALL ${BREAKPAD_EXCEPTIONHANDLER_LIST})
@@ -731,7 +731,7 @@ if (USE_BREAKPAD)
731731
set(LIBS_ENGINE_BASE ${LIBS_ENGINE_BASE} srclibs-breakpad-exception_handler
732732
srclibs-breakpad-crash_generation_client srclibs-breakpad-common)
733733

734-
elseif (LINUX)
734+
elseif (DAEMON_TARGET_SYSTEM_Linux)
735735
add_library(srclibs-breakpad EXCLUDE_FROM_ALL ${BREAKPAD_LIST})
736736
set_target_properties(srclibs-breakpad PROPERTIES POSITION_INDEPENDENT_CODE 1 FOLDER "libs")
737737
target_compile_definitions(srclibs-breakpad PUBLIC HAVE_GETCONTEXT=1)
@@ -746,7 +746,7 @@ option(PREFER_EXTERNAL_LIBS "Tries to use system libs where possible." ON)
746746

747747
macro(prefer_package LIB_NAME LIB_CMAKE)
748748
if (NOT ${LIB_NAME}_FOUND)
749-
if (PREFER_EXTERNAL_LIBS AND NOT NACL)
749+
if (PREFER_EXTERNAL_LIBS AND NOT DAEMON_TARGET_SYSTEM_NaCl)
750750
find_package(${LIB_NAME})
751751

752752
if (NOT ${LIB_NAME}_FOUND)
@@ -876,7 +876,7 @@ endfunction()
876876

877877
daemon_write_buildinfo("Engine")
878878

879-
if (NOT NACL)
879+
if (NOT DAEMON_TARGET_SYSTEM_NaCl)
880880
add_library(engine-lib EXCLUDE_FROM_ALL ${PCH_FILE} ${BUILDINFOLIST} ${COMMONLIST} ${ENGINELIST})
881881
target_link_libraries(engine-lib ${LIBS_BASE} ${LIBS_ENGINE_BASE} ${CPP23SupportLibrary})
882882
set_property(TARGET engine-lib APPEND PROPERTY COMPILE_DEFINITIONS BUILD_ENGINE)
@@ -979,7 +979,7 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER
979979
)
980980

981981
# Linux uses a bootstrap program to reserve address space
982-
if (LINUX OR FREEBSD)
982+
if (DAEMON_TARGET_SYSTEM_Linux OR DAEMON_TARGET_SYSTEM_FreeBSD)
983983
if (DAEMON_ARCH_arm64)
984984
add_executable(nacl_helper_bootstrap-armhf tools/nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp)
985985
add_dependencies(runtime_deps nacl_helper_bootstrap-armhf)
@@ -1004,7 +1004,7 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER
10041004
endif()
10051005

10061006
# Win32 requires nacl_loader_amd64.exe in order to run on Win64
1007-
if (WIN32 AND DAEMON_ARCH_i686)
1007+
if (DAEMON_TARGET_SYSTEM_Windows AND DAEMON_ARCH_i686)
10081008
add_custom_command(TARGET runtime_deps PRE_BUILD
10091009
COMMAND ${CMAKE_COMMAND} -E copy_if_different
10101010
${DEPS_DIR}/nacl_loader-amd64${CMAKE_EXECUTABLE_SUFFIX}
@@ -1018,7 +1018,7 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER
10181018
endif()
10191019

10201020
# Mac requires some libraries from external_deps
1021-
if (APPLE)
1021+
if (DAEMON_TARGET_SYSTEM_macOS)
10221022
file(GLOB RUNTIME_FRAMEWORKS ${DEPS_DIR}/lib/*.framework)
10231023
foreach(RUNTIME_FRAMEWORK ${RUNTIME_FRAMEWORKS})
10241024
get_filename_component(RUNTIME_FRAMEWORK_NAME ${RUNTIME_FRAMEWORK} NAME)
@@ -1040,7 +1040,7 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER
10401040
endif()
10411041

10421042
# Windows requires some libraries from external_deps
1043-
if (WIN32)
1043+
if (DAEMON_TARGET_SYSTEM_Windows)
10441044
file(GLOB RUNTIME_LIBS ${DEPS_DIR}/bin/*.dll ${DEPS_DIR}/SDL3/lib/*/SDL3.dll)
10451045
foreach(RUNTIME_LIB ${RUNTIME_LIBS})
10461046
add_custom_command(TARGET runtime_deps PRE_BUILD

cmake/DaemonFlags.cmake

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ else()
362362
endif()
363363
endif()
364364

365-
if (NACL AND USE_NACL_SAIGO AND SAIGO_DAEMON_ARCH_arm)
365+
if (DAEMON_TARGET_SYSTEM_NaCl AND USE_NACL_SAIGO AND SAIGO_DAEMON_ARCH_arm)
366366
# This should be set for every build type because build type flags
367367
# are set after the other custom flags and then have the last word.
368368
# DEBUG should already use -O0 anyway.
@@ -413,7 +413,7 @@ else()
413413
try_flag(WARNINGS "-Werror")
414414
endif()
415415

416-
if (NACL AND NOT USE_NACL_SAIGO)
416+
if (DAEMON_TARGET_SYSTEM_NaCl AND NOT USE_NACL_SAIGO)
417417
# PNaCl only supports libc++ as standard library.
418418
set_c_cxx_flag("-stdlib=libc++")
419419
set_c_cxx_flag("--pnacl-allow-exceptions")
@@ -425,12 +425,12 @@ else()
425425
try_cxx_flag(FNO_GNU_UNIQUE "-fno-gnu-unique")
426426

427427
# Use MSVC-compatible bitfield layout
428-
if (WIN32)
428+
if (DAEMON_TARGET_SYSTEM_Windows)
429429
set_c_cxx_flag("-mms-bitfields")
430430
endif()
431431

432432
# Linker flags
433-
if (NOT APPLE)
433+
if (NOT DAEMON_TARGET_SYSTEM_macOS)
434434
try_linker_flag(LINKER_O1 "-Wl,-O1")
435435
try_linker_flag(LINKER_SORT_COMMON "-Wl,--sort-common")
436436
try_linker_flag(LINKER_AS_NEEDED "-Wl,--as-needed")
@@ -443,7 +443,7 @@ else()
443443
try_linker_flag(LINKER_Z_NOW "-Wl,-z,now")
444444
endif()
445445

446-
if (WIN32)
446+
if (DAEMON_TARGET_SYSTEM_Windows)
447447
try_linker_flag(LINKER_DYNAMICBASE "-Wl,--dynamicbase")
448448
try_linker_flag(LINKER_NXCOMPAT "-Wl,--nxcompat")
449449
try_linker_flag(LINKER_LARGE_ADDRESS_AWARE "-Wl,--large-address-aware")
@@ -456,7 +456,7 @@ else()
456456

457457
# The -pthread flag sets some preprocessor defines,
458458
# it is also used to link with libpthread on Linux.
459-
if (NOT APPLE)
459+
if (NOT DAEMON_TARGET_SYSTEM_macOS)
460460
try_c_cxx_flag(PTHREAD "-pthread")
461461
endif()
462462

@@ -480,7 +480,7 @@ else()
480480

481481
if (USE_HARDENING)
482482
# PNaCl accepts the flags but does not define __stack_chk_guard and __stack_chk_fail.
483-
if (NOT NACL)
483+
if (NOT DAEMON_TARGET_SYSTEM_NaCl)
484484
try_c_cxx_flag(FSTACK_PROTECTOR_STRONG "-fstack-protector-strong")
485485

486486
if (NOT FLAG_FSTACK_PROTECTOR_STRONG)
@@ -491,12 +491,12 @@ else()
491491
try_c_cxx_flag(FNO_STRICT_OVERFLOW "-fno-strict-overflow")
492492
try_c_cxx_flag(WSTACK_PROTECTOR "-Wstack-protector")
493493

494-
if (NOT NACL)
494+
if (NOT DAEMON_TARGET_SYSTEM_NaCl)
495495
# The -pie flag requires -fPIC:
496496
# > ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC
497497
# This flag isn't used on macOS:
498498
# > clang: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
499-
if (FLAG_FPIC AND NOT APPLE)
499+
if (FLAG_FPIC AND NOT DAEMON_TARGET_SYSTEM_macOS)
500500
try_exe_linker_flag(LINKER_PIE "-pie")
501501
endif()
502502
endif()
@@ -519,7 +519,7 @@ else()
519519
# PNaCl accepts the flag but does nothing with it, underlying clang doesn't support it.
520520
# Saigo NaCl compiler doesn't support LTO, the flag is accepted but linking fails
521521
# with “unable to pass LLVM bit-code files to linker” error.
522-
if (USE_LTO AND NOT NACL)
522+
if (USE_LTO AND NOT DAEMON_TARGET_SYSTEM_NaCl)
523523
try_c_cxx_flag(LTO_AUTO "-flto=auto")
524524

525525
if (NOT FLAG_LTO_AUTO)
@@ -585,7 +585,7 @@ if (MSVC)
585585
set_c_cxx_flag("/arch:IA32") # minimum
586586
endif()
587587
endif()
588-
elseif (NOT NACL)
588+
elseif (NOT DAEMON_TARGET_SYSTEM_NaCl)
589589
# Among the required hardware features, the NX bit (No eXecute bit)
590590
# feature may be required for NativeClient to work. Some early
591591
# Intel EM64T processors are known to not implement the NX bit.
@@ -672,7 +672,7 @@ elseif (NOT NACL)
672672
endif()
673673

674674
# Windows-specific definitions
675-
if (WIN32)
675+
if (DAEMON_TARGET_SYSTEM_Windows)
676676
add_definitions(
677677
-DWINVER=0x501 # Minimum Windows version: XP
678678
-DWIN32 # Define WIN32 for compatibility (compiler defines _WIN32)
@@ -687,7 +687,7 @@ if (MSVC)
687687
endif()
688688

689689
# Mac-specific definitions
690-
if (APPLE)
690+
if (DAEMON_TARGET_SYSTEM_macOS)
691691
add_definitions(-DMACOS_X)
692692
set(CMAKE_INSTALL_RPATH "@executable_path")
693693
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)

cmake/DaemonNacl.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
option(USE_NACL_SAIGO "Use Saigo toolchain to build NaCl executables" OFF)
3030

31-
if( NACL )
31+
if (DAEMON_TARGET_SYSTEM_NaCl)
3232
# Build nexe binary.
3333
if(USE_NACL_SAIGO)
3434
# DAEMON_NACL_ARCH is "pnacl" here, NACL_TARGET carries the architecture.
@@ -53,13 +53,13 @@ if( NACL )
5353
endif()
5454
else()
5555
# Build native dll or native exe.
56-
if( APPLE )
56+
if (DAEMON_TARGET_SYSTEM_macOS)
5757
add_definitions( -DNACL_WINDOWS=0 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=1 )
58-
elseif( LINUX )
58+
elseif (DAEMON_TARGET_SYSTEM_Linux)
5959
add_definitions( -DNACL_WINDOWS=0 -DNACL_LINUX=1 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=0 )
60-
elseif( FREEBSD )
60+
elseif (DAEMON_TARGET_SYSTEM_FreeBSD)
6161
add_definitions( -DNACL_WINDOWS=0 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=1 -DNACL_OSX=0 )
62-
elseif( WIN32 )
62+
elseif (DAEMON_TARGET_SYSTEM_Windows)
6363
add_definitions( -DNACL_WINDOWS=1 -DNACL_LINUX=0 -DNACL_ANDROID=0 -DNACL_FREEBSD=0 -DNACL_OSX=0 )
6464
endif()
6565

cmake/DaemonPlatform/Architecture.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ daemon_add_buildinfo("char*" "DAEMON_ARCH_STRING" "\"${DAEMON_ARCH}\"")
7474
# Modifying NACL_ARCH breaks engine compatibility with nexe game binaries
7575
# since NACL_ARCH contributes to the nexe file name.
7676
set(DAEMON_NACL_ARCH "${DAEMON_ARCH}")
77-
if (LINUX OR FREEBSD)
77+
if (DAEMON_TARGET_SYSTEM_Linux OR DAEMON_TARGET_SYSTEM_FreeBSD)
7878
set(ARMHF_USAGE arm64 armel)
7979
if (DAEMON_ARCH IN_LIST ARMHF_USAGE)
8080
# Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch.
8181
# The nexe is system agnostic so there should be no difference with armel.
8282
set(DAEMON_NACL_ARCH "armhf")
8383
endif()
84-
elseif(APPLE)
84+
elseif(DAEMON_TARGET_SYSTEM_macOS)
8585
if ("${DAEMON_ARCH}" STREQUAL arm64)
8686
# You can get emulated NaCl going like this:
8787
# cp external_deps/macos-amd64-default_10/{nacl_loader,irt_core-amd64.nexe} build/

0 commit comments

Comments
 (0)