From 16821fd90c6cfcb33c56de0783a4015391a70bcc Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 2 Jul 2020 06:54:54 +0200 Subject: [PATCH] Simplify CMake config by making a reusable library. --- src/CMakeLists.txt | 20 ++++++++++++-------- tests/CMakeLists.txt | 20 ++------------------ 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cac3fa4..7802477 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,25 +2,29 @@ include(GNUInstallDirs) configure_file(fs-compat.hpp.in fs-compat.hpp @ONLY) -add_executable(${PROJECT_NAME} main.cpp) - file(GLOB_RECURSE sources_src *.cpp) file(GLOB_RECURSE headers_src *.hpp) -target_sources(${PROJECT_NAME} - PRIVATE "${sources_src}" "${headers_src}") +# Library for the main executable, the generators and the test. +add_library(fediblock STATIC + "${sources_src}" "${headers_src}") unset(sources_src) unset(headers_src) -target_include_directories(${PROJECT_NAME} - PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(fediblock + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -target_link_libraries(${PROJECT_NAME} - PRIVATE +target_link_libraries(fediblock + PUBLIC PkgConfig::cgicc nlohmann_json std::filesystem PkgConfig::libgit2 CURL::libcurl) +add_executable(${PROJECT_NAME} main.cpp) + +target_link_libraries(${PROJECT_NAME} + PRIVATE fediblock) + install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 204320f..1f01370 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,21 +1,5 @@ include(CTest) -file(GLOB sources_testlib ../src/*.cpp) -add_library(${PROJECT_NAME}_testlib SHARED ${sources_testlib}) - -target_include_directories(${PROJECT_NAME}_testlib - PUBLIC - "$" - "$") - -target_link_libraries(${PROJECT_NAME}_testlib - PUBLIC - PkgConfig::cgicc - nlohmann_json - std::filesystem - PkgConfig::libgit2 - CURL::libcurl) - file(GLOB sources_tests test_*.cpp) find_package(Catch2 CONFIG) @@ -24,7 +8,7 @@ if(Catch2_FOUND) # Catch 2.x include(Catch) add_executable(all_tests main.cpp ${sources_tests}) target_link_libraries(all_tests - PRIVATE Catch2::Catch2 ${PROJECT_NAME}_testlib) + PRIVATE Catch2::Catch2 fediblock) target_include_directories(all_tests PRIVATE "/usr/include/catch2") catch_discover_tests(all_tests EXTRA_ARGS "${EXTRA_TEST_ARGS}") else() # Catch 1.x @@ -33,7 +17,7 @@ else() # Catch 1.x foreach(src ${sources_tests}) get_filename_component(bin ${src} NAME_WE) add_executable(${bin} main.cpp ${src}) - target_link_libraries(${bin} PRIVATE ${PROJECT_NAME}_testlib) + target_link_libraries(${bin} PRIVATE fediblock) add_test(${bin} ${bin} "${EXTRA_TEST_ARGS}") endforeach() else()