95 lines
3.1 KiB
CMake
95 lines
3.1 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
project(CreatureLib)
|
|
|
|
# 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.
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
|
|
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)
|
|
option(TESTS "Whether the test executable should be build as well." OFF)
|
|
option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF)
|
|
set(LEVEL_SIZE "8" CACHE STRING "Number of bits to store the level as. Currently reserved, and can only be 8")
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
add_compile_options(-fconcepts)
|
|
endif ()
|
|
|
|
if (NOT WINDOWS)
|
|
# Include debug symbols in all linux builds
|
|
add_compile_options(-g -gfull -g3)
|
|
endif ()
|
|
|
|
include(CmakeConanSetup.cmake)
|
|
SetupConan()
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
find_package(Threads REQUIRED)
|
|
|
|
# Set whether we want a static or shared library.
|
|
set(LIBTYPE STATIC)
|
|
if (SHARED)
|
|
set(LIBTYPE SHARED)
|
|
endif (SHARED)
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
add_link_options(-fuse-ld=lld)
|
|
endif ()
|
|
|
|
if (LEVEL_SIZE STREQUAL "8")
|
|
add_definitions(-DLEVEL_U8)
|
|
message(STATUS "Using level size of 8")
|
|
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")
|
|
else ()
|
|
message(FATAL_ERROR, "Invalid level size was given.")
|
|
endif ()
|
|
|
|
file(GLOB_RECURSE LIBRARY_SRC_FILES
|
|
"src/*.cpp" "src/*.hpp" "CInterface/*.cpp" "CInterface/*.hpp")
|
|
add_library(CreatureLib SHARED ${LIBRARY_SRC_FILES})
|
|
target_precompile_headers(CreatureLib PUBLIC src/Precompiled.hxx)
|
|
|
|
# If we are building for Windows we need to set some specific variables.
|
|
if (WINDOWS)
|
|
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")
|
|
endif (WINDOWS)
|
|
|
|
# Set up links to all relevant libraries.
|
|
SET(_LIBRARYLINKS Arbutils)
|
|
if (NOT WINDOWS)
|
|
set(_LIBRARYLINKS ${_LIBRARYLINKS} -ldw)
|
|
endif ()
|
|
|
|
# If we need to link the C libraries statically, do so.
|
|
if (STATICC)
|
|
message(STATUS "Linking C statically.")
|
|
SET(_LIBRARYLINKS ${_LIBRARYLINKS} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread)
|
|
endif ()
|
|
|
|
# And link the libraries together
|
|
target_link_libraries(CreatureLib PUBLIC ${_LIBRARYLINKS} Threads::Threads)
|
|
|
|
if (TESTS)
|
|
# Create Test executable
|
|
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
|
|
add_executable(CreatureLibTests ${TEST_FILES} extern/doctest.hpp)
|
|
target_link_libraries(CreatureLibTests PUBLIC CreatureLib Arbutils)
|
|
|
|
# Add a definition for the test library
|
|
target_compile_definitions(CreatureLibTests PRIVATE TESTS_BUILD)
|
|
endif ()
|