2020-09-25 11:05:15 +00:00
|
|
|
cmake_minimum_required(VERSION 3.16)
|
2020-12-31 12:52:11 +00:00
|
|
|
include(CheckIPOSupported)
|
2022-02-05 12:59:15 +00:00
|
|
|
include(CPM.cmake)
|
2020-12-31 12:52:11 +00:00
|
|
|
|
2019-10-06 11:50:52 +00:00
|
|
|
project(CreatureLib)
|
|
|
|
|
2020-07-17 11:12:21 +00:00
|
|
|
# Enable all warnings, and make them error when occurring.
|
|
|
|
add_compile_options(-Wall -Wextra -Werror)
|
|
|
|
# We like new stuff, so set the c++ standard to c++20.
|
2020-06-26 15:08:23 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
2019-10-06 11:50:52 +00:00
|
|
|
|
2020-07-17 11:12:21 +00:00
|
|
|
option(WINDOWS "Whether the build target is Windows or not." OFF)
|
|
|
|
option(SHARED "Whether we should build a shared library, instead of a static one." OFF)
|
2022-02-05 14:52:03 +00:00
|
|
|
option(CREATURELIB_TESTS "Whether the test executable should be build as well." OFF)
|
2022-03-22 17:16:00 +00:00
|
|
|
option(SANITIZER_TESTS "Whether the test executable should be built using address sanitizer." ON)
|
2020-07-17 11:12:21 +00:00
|
|
|
option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF)
|
2020-09-19 10:03:41 +00:00
|
|
|
set(LEVEL_SIZE "8" CACHE STRING "Number of bits to store the level as. Currently reserved, and can only be 8")
|
2020-05-03 10:45:12 +00:00
|
|
|
|
2022-02-05 13:45:10 +00:00
|
|
|
execute_process(COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include)
|
2022-02-05 12:59:15 +00:00
|
|
|
CPMAddPackage(
|
|
|
|
NAME Arbutils
|
|
|
|
GIT_REPOSITORY https://git.p-epsilon.com/Deukhoofd/Arbutils.git
|
|
|
|
GIT_TAG master
|
|
|
|
OPTIONS
|
|
|
|
"SHARED=${SHARED}"
|
|
|
|
"WINDOWS=${WINDOWS}"
|
|
|
|
"STATICC=${STATICC}"
|
|
|
|
)
|
2022-02-05 13:45:10 +00:00
|
|
|
execute_process(COMMAND ln -sf ${Arbutils_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/include/Arbutils)
|
2022-02-05 12:59:15 +00:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
|
2021-04-12 17:05:30 +00:00
|
|
|
|
2020-08-14 12:26:40 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
add_compile_options(-fconcepts)
|
|
|
|
endif ()
|
|
|
|
|
2022-03-12 09:33:16 +00:00
|
|
|
if (CMAKE_BUILD_TYPE MATCHES Release)
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
# Include debug symbols in all linux builds
|
|
|
|
message("Including debug symbols")
|
|
|
|
add_compile_options(-g -gline-tables-only)
|
|
|
|
endif ()
|
|
|
|
# FIXME: Add debug symbols for GCC
|
2020-08-16 15:41:56 +00:00
|
|
|
endif ()
|
|
|
|
|
2020-08-07 10:20:59 +00:00
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
2020-07-17 11:12:21 +00:00
|
|
|
# Set whether we want a static or shared library.
|
|
|
|
set(LIBTYPE STATIC)
|
|
|
|
if (SHARED)
|
|
|
|
set(LIBTYPE SHARED)
|
|
|
|
endif (SHARED)
|
2019-10-06 11:50:52 +00:00
|
|
|
|
2020-09-21 10:51:45 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
add_link_options(-fuse-ld=lld)
|
2022-03-23 13:19:07 +00:00
|
|
|
# Only warn for unknown sanitizers. This error is not major enough to error on.
|
|
|
|
add_compile_options(-Wno-error=unknown-sanitizers)
|
2020-09-21 10:51:45 +00:00
|
|
|
endif ()
|
|
|
|
|
2020-08-19 18:11:00 +00:00
|
|
|
if (LEVEL_SIZE STREQUAL "8")
|
|
|
|
add_definitions(-DLEVEL_U8)
|
2020-08-22 08:21:39 +00:00
|
|
|
message(STATUS "Using level size of 8")
|
2020-09-27 09:25:32 +00:00
|
|
|
elseif (LEVEL_SIZE STREQUAL "16")
|
|
|
|
add_definitions(-DLEVEL_U16)
|
|
|
|
message(STATUS "Using level size of 16")
|
|
|
|
elseif (LEVEL_SIZE STREQUAL "32")
|
|
|
|
add_definitions(-DLEVEL_U32)
|
|
|
|
message(STATUS "Using level size of 32")
|
|
|
|
elseif (LEVEL_SIZE STREQUAL "64")
|
|
|
|
add_definitions(-DLEVEL_U64)
|
|
|
|
message(STATUS "Using level size of 64")
|
2020-08-19 18:11:00 +00:00
|
|
|
else ()
|
|
|
|
message(FATAL_ERROR, "Invalid level size was given.")
|
|
|
|
endif ()
|
|
|
|
|
2020-07-31 08:51:03 +00:00
|
|
|
file(GLOB_RECURSE LIBRARY_SRC_FILES
|
|
|
|
"src/*.cpp" "src/*.hpp" "CInterface/*.cpp" "CInterface/*.hpp")
|
2021-08-29 14:03:19 +00:00
|
|
|
add_library(CreatureLib ${LIBTYPE} ${LIBRARY_SRC_FILES})
|
2019-10-17 12:33:25 +00:00
|
|
|
|
2020-12-31 12:52:11 +00:00
|
|
|
# If interprocedural optimization is available, apply it
|
|
|
|
check_ipo_supported(RESULT IPO_SUPPORTED)
|
|
|
|
if (IPO_SUPPORTED)
|
|
|
|
message(STATUS "IPO / LTO enabled")
|
|
|
|
set_property(TARGET CreatureLib PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
endif ()
|
|
|
|
|
2019-10-06 11:50:52 +00:00
|
|
|
if (WINDOWS)
|
2020-07-17 11:12:21 +00:00
|
|
|
MESSAGE(WARNING, "Using Windows Build.")
|
|
|
|
# Add a definition for the compiler, so we can use it in C++ as well.
|
|
|
|
ADD_DEFINITIONS(-D WINDOWS=1)
|
|
|
|
# -m64: Build a 64 bit library
|
|
|
|
add_compile_options(-m64)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-allow-multiple-definition")
|
2021-03-07 08:43:10 +00:00
|
|
|
if (SHARED)
|
|
|
|
set_target_properties(CreatureLib PROPERTIES SUFFIX ".dll")
|
|
|
|
endif (SHARED)
|
2020-05-02 13:55:31 +00:00
|
|
|
endif (WINDOWS)
|
|
|
|
|
2021-03-07 08:43:10 +00:00
|
|
|
|
2020-07-17 11:12:21 +00:00
|
|
|
# Set up links to all relevant libraries.
|
|
|
|
SET(_LIBRARYLINKS Arbutils)
|
2020-08-15 15:47:01 +00:00
|
|
|
if (NOT WINDOWS)
|
2022-02-26 14:22:11 +00:00
|
|
|
set(_LIBRARYLINKS ${_LIBRARYLINKS} -ldw)
|
2020-08-15 15:47:01 +00:00
|
|
|
endif ()
|
2020-07-17 11:12:21 +00:00
|
|
|
|
|
|
|
# If we need to link the C libraries statically, do so.
|
2020-05-02 13:55:31 +00:00
|
|
|
if (STATICC)
|
2020-05-03 10:45:12 +00:00
|
|
|
message(STATUS "Linking C statically.")
|
2021-03-26 13:09:22 +00:00
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
|
2022-02-12 13:00:50 +00:00
|
|
|
SET(_LIBRARYLINKS ${_LIBRARYLINKS} -static-libgcc -static-libstdc++)
|
2020-05-02 13:55:31 +00:00
|
|
|
endif ()
|
|
|
|
|
2020-07-17 11:12:21 +00:00
|
|
|
# And link the libraries together
|
2022-02-12 13:00:50 +00:00
|
|
|
target_link_libraries(CreatureLib PUBLIC ${_LIBRARYLINKS})
|
2019-10-06 11:50:52 +00:00
|
|
|
|
2022-02-05 14:52:03 +00:00
|
|
|
if (CREATURELIB_TESTS)
|
2022-02-05 12:59:15 +00:00
|
|
|
CPMAddPackage(
|
|
|
|
NAME doctest
|
|
|
|
GITHUB_REPOSITORY doctest/doctest
|
2022-03-11 10:07:25 +00:00
|
|
|
GIT_TAG v2.4.8
|
2022-02-05 12:59:15 +00:00
|
|
|
DOWNLOAD_ONLY YES
|
|
|
|
)
|
2020-05-02 13:55:31 +00:00
|
|
|
# Create Test executable
|
|
|
|
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
|
2022-02-05 12:59:15 +00:00
|
|
|
add_executable(CreatureLibTests ${TEST_FILES})
|
2020-07-31 08:51:03 +00:00
|
|
|
target_link_libraries(CreatureLibTests PUBLIC CreatureLib Arbutils)
|
2022-02-05 12:59:15 +00:00
|
|
|
target_include_directories(CreatureLibTests PUBLIC ${doctest_SOURCE_DIR}/doctest)
|
2020-05-02 13:55:31 +00:00
|
|
|
|
2019-12-27 12:50:12 +00:00
|
|
|
# Add a definition for the test library
|
|
|
|
target_compile_definitions(CreatureLibTests PRIVATE TESTS_BUILD)
|
2022-03-22 17:16:00 +00:00
|
|
|
if (SANITIZER_TESTS AND NOT WINDOWS)
|
2022-03-25 18:21:02 +00:00
|
|
|
target_compile_options(CreatureLib PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all)
|
2022-03-23 12:56:45 +00:00
|
|
|
target_compile_options(CreatureLibTests PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all)
|
|
|
|
target_link_options(CreatureLibTests PRIVATE -fsanitize=address,undefined,leak,integer,nullability -fno-sanitize-recover=all)
|
2022-03-22 17:16:00 +00:00
|
|
|
endif ()
|
2020-05-02 13:55:31 +00:00
|
|
|
endif ()
|