Simplify CMake config by making a reusable library.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
eda8bcf69c
commit
16821fd90c
|
@ -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}")
|
||||
|
|
|
@ -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
|
||||
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
|
||||
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>")
|
||||
|
||||
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()
|
||||
|
|
Reference in New Issue
Block a user