darlingserver/CMakeLists.txt
Zhaofeng Li 21e3c36904 Allow overriding xdg-user-dir executable
This makes it easier to set the path as xdg-user-dir may
not be in PATH.
2023-04-26 16:07:37 -06:00

175 lines
4.2 KiB
CMake

project(darlingserver)
cmake_minimum_required(VERSION 3.13)
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" ON)
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\")")
set(DARLINGSERVER_XDG_USER_DIR_CMD "xdg-user-dir" CACHE STRING "The xdg-user-dir binary darlingserver should execute (default is \"xdg-user-dir\")")
include_directories(
include
internal-include
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/internal-include
${CMAKE_BINARY_DIR}/src/startup # for `rtsig.h`
)
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
src/stack-pool.cpp
)
add_dependencies(darlingserver
generate_dserver_rpc_wrappers
rtsig_h
)
target_link_libraries(darlingserver PRIVATE
darlingserver_duct_tape
)
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"
#)
if (NOT "${DARLINGSERVER_INIT_PROCESS}" STREQUAL "")
target_compile_definitions(darlingserver PRIVATE
DARLINGSERVER_INIT_PROCESS="${DARLINGSERVER_INIT_PROCESS}"
)
endif()
if (NOT "${DARLINGSERVER_XDG_USER_DIR_CMD}" STREQUAL "")
target_compile_definitions(darlingserver PRIVATE
DARLINGSERVER_XDG_USER_DIR_CMD="${DARLINGSERVER_XDG_USER_DIR_CMD}"
)
endif()