diff --git a/doc/compiling/README.md b/doc/compiling/README.md index 3652c2d74..a1ab1ebbd 100644 --- a/doc/compiling/README.md +++ b/doc/compiling/README.md @@ -20,6 +20,8 @@ General options and their default values: SemiDebug - Partially optimized debug build RelWithDebInfo - Release build with debug information MinSizeRel - Release build with -Os passed to compiler to make executable as small as possible + PRECOMPILE_HEADERS=FALSE - Precompile some headers (experimental; requires CMake 3.16 or later) + PRECOMPILED_HEADERS_PATH= - Path to a file listing all headers to precompile (default points to src/precompiled_headers.txt) ENABLE_CURL=ON - Build with cURL; Enables use of online mod repo, public serverlist and remote media fetching via http ENABLE_CURSES=ON - Build with (n)curses; Enables a server side terminal (command line option: --terminal) ENABLE_GETTEXT=ON - Build with Gettext; Allows using translations diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a37b02f87..bcbe6d7f5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,6 +48,25 @@ if(NOT (BUILD_CLIENT OR BUILD_SERVER)) endif() +option(PRECOMPILE_HEADERS "Precompile some headers (experimental; requires CMake 3.16 or later)" FALSE) +set(PRECOMPILED_HEADERS_PATH "" CACHE FILEPATH "Path to a file listing all headers to precompile") + +if(PRECOMPILE_HEADERS) + if(${CMAKE_VERSION} VERSION_LESS 3.16) + message(FATAL_ERROR "PRECOMPILE_HEADERS is on, but precompiled headers require at least CMake 3.16.") + endif() + if(PRECOMPILED_HEADERS_PATH) + set(PRECOMPILED_HEADERS ${PRECOMPILED_HEADERS_PATH}) + else() + set(PRECOMPILED_HEADERS "${CMAKE_SOURCE_DIR}/src/precompiled_headers.txt") + endif() + message(STATUS "Reading headers to precompile from: ${PRECOMPILED_HEADERS}") + # ignore lines that begin with # and empty lines + file(STRINGS ${PRECOMPILED_HEADERS} PRECOMPILED_HEADERS_LIST REGEX "^[^#].*$") + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${PRECOMPILED_HEADERS}) +endif() + + option(ENABLE_CURL "Enable cURL support for fetching media" TRUE) set(USE_CURL FALSE) @@ -619,6 +638,10 @@ if(BUILD_CLIENT) if(BUILD_UNITTESTS OR BUILD_BENCHMARKS) target_link_libraries(${PROJECT_NAME} Catch2::Catch2) endif() + + if(PRECOMPILE_HEADERS) + target_precompile_headers(${PROJECT_NAME} PRIVATE ${PRECOMPILED_HEADERS_LIST}) + endif() endif(BUILD_CLIENT) @@ -682,6 +705,10 @@ if(BUILD_SERVER) if(BUILD_UNITTESTS OR BUILD_BENCHMARKS) target_link_libraries(${PROJECT_NAME}server Catch2::Catch2) endif() + + if(PRECOMPILE_HEADERS) + target_precompile_headers(${PROJECT_NAME}server PRIVATE ${PRECOMPILED_HEADERS_LIST}) + endif() endif(BUILD_SERVER) # See issue #4638 diff --git a/src/precompiled_headers.txt b/src/precompiled_headers.txt new file mode 100644 index 000000000..24c92b783 --- /dev/null +++ b/src/precompiled_headers.txt @@ -0,0 +1,103 @@ + +# stdlib +# ------ + +# C stuff: + + + + + + + + + + + + + + + + + + + + + + + + + +# Containers: + + + + + + + + + + + + +# Input/Output: + + + + + + + + + + +# Multi-threading: + + + + + + + +# Other: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# libs +# ---- + +# jsoncpp +