darlingserver/CMakeLists.txt
2022-03-09 17:44:54 -05:00

171 lines
4.0 KiB
CMake

project(darlingserver)
cmake_minimum_required(VERSION 3.10)
option(DSERVER_ASAN "Build darlingserver with ASAN" OFF)
option(DSERVER_UBSAN "Build darlingserver with UBSAN" OFF)
if (DSERVER_ASAN)
add_compile_definitions(
DSERVER_ASAN=1
)
else()
add_compile_definitions(
DSERVER_ASAN=0
)
endif()
if (DSERVER_UBSAN)
add_compile_definitions(
DSERVER_UBSAN=1
)
else()
add_compile_definitions(
DSERVER_UBSAN=0
)
endif()
set(dserver_sanitizers "")
if (DSERVER_ASAN)
if (NOT (dserver_sanitizers STREQUAL ""))
set(dserver_sanitizers "${dserver_sanitizers},")
endif()
set(dserver_sanitizers "${dserver_sanitizers}address")
endif()
if (DSERVER_UBSAN)
if (NOT (dserver_sanitizers STREQUAL ""))
set(dserver_sanitizers "${dserver_sanitizers},")
endif()
set(dserver_sanitizers "${dserver_sanitizers}undefined")
endif()
option(DSERVER_EXTENDED_DEBUG "Build darlingserver with extended debugging support" OFF)
if (DSERVER_EXTENDED_DEBUG)
add_compile_definitions(
DSERVER_EXTENDED_DEBUG=1
)
else()
add_compile_definitions(
DSERVER_EXTENDED_DEBUG=0
)
endif()
option(DSERVER_SINGLE_THREADED "Only use a single thread per workqueue in darlingserver" OFF)
if (DSERVER_SINGLE_THREADED)
add_compile_definitions(
DSERVER_SINGLE_THREADED=1
)
else()
add_compile_definitions(
DSERVER_SINGLE_THREADED=0
)
endif()
add_subdirectory(duct-tape)
set(DARLINGSERVER_INIT_PROCESS "/sbin/launchd" CACHE STRING "The init process darlingserver should execute (default is \"/sbin/launchd\")")
include_directories(
include
internal-include
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/internal-include
)
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/include/darlingserver/rpc.h
${CMAKE_CURRENT_BINARY_DIR}/internal-include/darlingserver/rpc.internal.h
${CMAKE_CURRENT_BINARY_DIR}/src/rpc.c
COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate-rpc-wrappers.py
${CMAKE_CURRENT_BINARY_DIR}/include/darlingserver/rpc.h
${CMAKE_CURRENT_BINARY_DIR}/internal-include/darlingserver/rpc.internal.h
${CMAKE_CURRENT_BINARY_DIR}/src/rpc.c
\"../include/darlingserver/rpc.h\"
VERBATIM
MAIN_DEPENDENCY
${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate-rpc-wrappers.py
)
add_custom_target(generate_dserver_rpc_wrappers
ALL
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/include/darlingserver/rpc.h
${CMAKE_CURRENT_BINARY_DIR}/internal-include/darlingserver/rpc.internal.h
${CMAKE_CURRENT_BINARY_DIR}/src/rpc.c
)
add_executable(darlingserver
src/darlingserver.cpp
src/server.cpp
src/message.cpp
src/call.cpp
src/registry.cpp
src/logging.cpp
src/process.cpp
src/thread.cpp
src/utility.cpp
src/kqchan.cpp
src/async-writer.cpp
)
add_dependencies(darlingserver
generate_dserver_rpc_wrappers
)
target_link_libraries(darlingserver PRIVATE
darlingserver_duct_tape
cap
)
target_compile_options(darlingserver PRIVATE
-pthread
-std=c++17
)
target_link_options(darlingserver PRIVATE
-pthread
-Wl,--gc-sections
)
if (DSERVER_ASAN OR DSERVER_UBSAN)
target_compile_options(darlingserver PRIVATE
-fsanitize=${dserver_sanitizers}
-fsanitize-recover=all
-fno-omit-frame-pointer
-g
-Og
)
target_link_options(darlingserver PRIVATE
-fsanitize=${dserver_sanitizers}
-fsanitize-recover=all
)
endif()
if (DSERVER_EXTENDED_DEBUG)
target_compile_options(darlingserver PRIVATE
-fno-omit-frame-pointer
)
endif()
install(TARGETS darlingserver DESTINATION bin)
#file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${DARLING_SDK_RELATIVE_PATH}/usr/include/darlingserver")
#create_symlink(
# "${DARLING_ROOT_RELATIVE_TO_SDK}/../../../src/darlingserver/include/darlingserver/rpc.h"
# "${CMAKE_BINARY_DIR}/${DARLING_SDK_RELATIVE_PATH}/usr/include/darlingserver/rpc.h"
#)
include(setcap)
# necessary because mldr has these capabilities, so in order to access it for ptracing, we need the same set or a superset
setcap(bin/darlingserver cap_sys_rawio,cap_sys_resource+ep)
if (NOT "${DARLINGSERVER_INIT_PROCESS}" STREQUAL "")
target_compile_definitions(darlingserver PRIVATE
DARLINGSERVER_INIT_PROCESS="${DARLINGSERVER_INIT_PROCESS}"
)
endif()