From 2b59a832a458f9a5cb14073b67533d8f9f33abb0 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Wed, 30 Oct 2024 20:35:38 +0100 Subject: [PATCH] Removing useless submodules and exporting targets --- .gitmodules | 9 ------ CMakeLists.txt | 79 +++++++++++++++++++++++++++--------------------- Config.cmake.in | 7 +++++ external/json | 1 - external/spdlog | 1 - external/svector | 1 - 6 files changed, 51 insertions(+), 47 deletions(-) create mode 100644 Config.cmake.in delete mode 160000 external/json delete mode 160000 external/spdlog delete mode 160000 external/svector diff --git a/.gitmodules b/.gitmodules index 10ec53e..e540fcd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,3 @@ -[submodule "external/spdlog"] - path = external/spdlog - url = https://github.com/gabime/spdlog.git -[submodule "external/json"] - path = external/json - url = https://github.com/nlohmann/json.git [submodule "external/catch2"] path = external/catch2 url = https://github.com/catchorg/Catch2.git -[submodule "external/svector"] - path = external/svector - url = https://github.com/martinus/svector.git diff --git a/CMakeLists.txt b/CMakeLists.txt index a6e059b..1258457 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,10 @@ 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) @@ -10,6 +14,9 @@ set(SOURCES ${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 !") @@ -21,20 +28,11 @@ else () message(STATUS "ccache not found") endif () -add_subdirectory(external/svector) - -option(SPDLOG_ENABLE_PCH "Build static or shared library using precompiled header to speed up compilation time" ON) -option(SPDLOG_BUILD_WARNINGS "Enable compiler warnings" ON) -option(SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" ON) -option(SPDLOG_NO_THREAD_ID "prevent spdlog from querying the thread id on each log call if thread id is not needed" ON) -option(SPDLOG_NO_TLS "prevent spdlog from using thread local storage" ON) -option(SPDLOG_NO_ATOMIC_LEVELS "prevent spdlog from using of std::atomic log levels (use only if your code never modifies log levels concurrently" ON) -add_subdirectory(external/spdlog) - +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) -add_subdirectory(external/json) +fetchcontent_makeavailable(json) option(CATCH_INSTALL_DOCS "Install documentation alongside library" OFF) option(CATCH_INSTALL_EXTRAS "Install extras alongside library" OFF) @@ -64,10 +62,6 @@ set(LINKER_OPTIONS -fdevirtualize-at-ltrans ) -set(LINKER_FLAGS - jemalloc -) - option(ENABLE_COVERAGE "Enabling coverage" OFF) if (${ENABLE_COVERAGE}) @@ -79,41 +73,56 @@ endif () add_library(BillySheet SHARED ${SOURCES}) -target_include_directories(BillySheet PRIVATE include include/imgui external/ImFileDialog) +target_include_directories(BillySheet + PUBLIC + $ + $ +) -set_target_properties(BillySheet spdlog svector PROPERTIES +set_target_properties(BillySheet PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF INTERPROCEDURAL_OPTIMIZATION ON - # UNITY_BUILD ON + UNITY_BUILD ON + PUBLIC_HEADER "include/billy_objects.hpp;include/character_sheet.hpp;include/generic_object.hpp;include/characteristic.hpp" ) -set_target_properties(spdlog svector PROPERTIES UNITY_BUILD ON) - target_compile_definitions(BillySheet PRIVATE $<$:_GLIBCXX_DEBUG> - $<$:SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG> - $<$:SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_ERROR>) +) -target_compile_definitions(spdlog PRIVATE $<$:_GLIBCXX_DEBUG>) -target_compile_definitions(svector INTERFACE $<$:_GLIBCXX_DEBUG>) - -target_compile_options(spdlog PRIVATE ${COMPILE_FLAGS}) -target_compile_options(svector INTERFACE ${COMPILE_FLAGS}) target_compile_options(BillySheet PRIVATE ${COMPILE_FLAGS}) -target_link_options(spdlog PRIVATE ${LINKER_OPTIONS}) -target_link_options(svector INTERFACE ${LINKER_OPTIONS}) target_link_options(BillySheet PRIVATE ${LINKER_OPTIONS}) -target_link_libraries(spdlog PRIVATE ${LINKER_FLAGS}) -target_link_libraries(svector INTERFACE ${LINKER_FLAGS}) -target_link_libraries(BillySheet glfw - spdlog::spdlog_header_only - svector::svector +target_link_libraries(BillySheet PUBLIC nlohmann_json::nlohmann_json - ${LINKER_FLAGS} + 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") diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 0000000..849e51d --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1,7 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/billySheetTargets.cmake") +include(CMakeFindDependencyMacro) +find_dependency(PkgConfig REQUIRED) + +check_required_components(billySheet) \ No newline at end of file diff --git a/external/json b/external/json deleted file mode 160000 index 9cca280..0000000 --- a/external/json +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03 diff --git a/external/spdlog b/external/spdlog deleted file mode 160000 index 27cb4c7..0000000 --- a/external/spdlog +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 27cb4c76708608465c413f6d0e6b8d99a4d84302 diff --git a/external/svector b/external/svector deleted file mode 160000 index cbeced4..0000000 --- a/external/svector +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cbeced42e061da03b881ba1d09621d4604de030a