129 lines
3.9 KiB
CMake
129 lines
3.9 KiB
CMake
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
|
|
project(BillySheet LANGUAGES CXX)
|
|
|
|
include(GNUInstallDirs)
|
|
include(CMakePackageConfigHelpers)
|
|
include(FetchContent)
|
|
|
|
file(GLOB_RECURSE SOURCE_HEADERS include/*.h include/*.hpp)
|
|
|
|
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
|
|
|
|
set(SOURCES
|
|
${SOURCE_HEADERS}
|
|
${SOURCE_FILES}
|
|
)
|
|
|
|
find_package(PkgConfig REQUIRED)
|
|
pkg_check_modules(Jemalloc REQUIRED IMPORTED_TARGET jemalloc)
|
|
|
|
find_program(CCACHE_FOUND ccache)
|
|
if (CCACHE_FOUND)
|
|
message(STATUS "ccache found !")
|
|
set_property(GLOBAL PROPERTY C_COMPILER_LAUNCHER ccache)
|
|
set_property(GLOBAL PROPERTY C_LINKER_LAUNCHER ccache)
|
|
set_property(GLOBAL PROPERTY CXX_COMPILER_LAUNCHER ccache)
|
|
set_property(GLOBAL PROPERTY CXX_LINKER_LAUNCHER ccache)
|
|
else ()
|
|
message(STATUS "ccache not found")
|
|
endif ()
|
|
|
|
fetchcontent_declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
|
|
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
|
option(JSON_ImplicitConversions "Enable implicit conversions." OFF)
|
|
option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." ON)
|
|
fetchcontent_makeavailable(json)
|
|
|
|
option(CATCH_INSTALL_DOCS "Install documentation alongside library" OFF)
|
|
option(CATCH_INSTALL_EXTRAS "Install extras alongside library" OFF)
|
|
add_subdirectory(external/catch2)
|
|
|
|
|
|
set(COMPILE_FLAGS
|
|
-pipe
|
|
-march=znver3 # change to native or your architecture.
|
|
-mtune=znver3 # same as above
|
|
-mrdseed # be careful about this, this is linked to the x86 architecture.
|
|
-mrdrnd # same as above
|
|
-Wall
|
|
-Wextra
|
|
-Wpedantic
|
|
# -Wpadded
|
|
-pedantic
|
|
$<$<CONFIG:Release>:-ffunction-sections -fdata-sections>
|
|
-fuse-ld=gold
|
|
-funroll-loops
|
|
-fdevirtualize-at-ltrans
|
|
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
|
|
)
|
|
set(LINKER_OPTIONS
|
|
-Wl,--sort-common,--as-needed$<$<CONFIG:Release>:,--gc-sections,--strip-all>
|
|
-fuse-ld=gold
|
|
-fdevirtualize-at-ltrans
|
|
)
|
|
|
|
option(ENABLE_COVERAGE "Enabling coverage" OFF)
|
|
|
|
if (${ENABLE_COVERAGE})
|
|
message(STATUS "Coverage enabled")
|
|
list(APPEND COMPILE_FLAGS --coverage)
|
|
list(APPEND LINKER_OPTIONS --coverage)
|
|
list(APPEND LINKER_FLAGS gcov)
|
|
endif ()
|
|
|
|
add_library(BillySheet SHARED ${SOURCES})
|
|
|
|
target_include_directories(BillySheet
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INDLUDEDIR}/billySheet>
|
|
)
|
|
|
|
set_target_properties(BillySheet PROPERTIES
|
|
CXX_STANDARD 17
|
|
CXX_STANDARD_REQUIRED ON
|
|
CXX_EXTENSIONS OFF
|
|
INTERPROCEDURAL_OPTIMIZATION ON
|
|
UNITY_BUILD ON
|
|
PUBLIC_HEADER "include/billy_objects.hpp;include/character_sheet.hpp;include/generic_object.hpp;include/characteristic.hpp"
|
|
)
|
|
|
|
target_compile_definitions(BillySheet PRIVATE
|
|
$<$<CONFIG:Debug>:_GLIBCXX_DEBUG>
|
|
)
|
|
|
|
target_compile_options(BillySheet PRIVATE ${COMPILE_FLAGS})
|
|
|
|
target_link_options(BillySheet PRIVATE ${LINKER_OPTIONS})
|
|
|
|
target_link_libraries(BillySheet PUBLIC
|
|
nlohmann_json::nlohmann_json
|
|
PkgConfig::Jemalloc
|
|
)
|
|
|
|
install(TARGETS BillySheet nlohmann_json
|
|
EXPORT billySheetTargets
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/billySheet"
|
|
)
|
|
|
|
install(EXPORT billySheetTargets
|
|
FILE billySheetTargets.cmake
|
|
NAMESPACE billySheet::
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/billySheet
|
|
)
|
|
|
|
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
|
|
"${CMAKE_CURRENT_BINARY_DIR}/billySheetConfig.cmake"
|
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/billySheet
|
|
)
|
|
|
|
install(FILES
|
|
"${CMAKE_CURRENT_BINARY_DIR}/billySheetConfig.cmake"
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/billySheet
|
|
)
|
|
|
|
add_subdirectory("Unit testing")
|