Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize and clean up CMakeLists.txt for streets_service_base #237

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 14 additions & 82 deletions streets_utils/streets_service_base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,89 +1,21 @@
cmake_minimum_required(VERSION 3.10.2)
project(streets_service_base)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
enable_testing()

find_package(Boost COMPONENTS system filesystem thread REQUIRED)
find_package(spdlog REQUIRED)
add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE)
# In CMake 3.21, PROJECT_IS_TOP_LEVEL is provided, so if block can be removed when the
# project upgrades to that CMake version
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(PROJECT_IS_TOP_LEVEL TRUE CACHE INTERNAL "")
else()
set(PROJECT_IS_TOP_LEVEL FALSE CACHE INTERNAL "")
endif()

option(STREETSSERVICEBASE_ENABLE_TESTING "Enable unit tests for streets_service_base" ${PROJECT_IS_TOP_LEVEL})

include(dependencies.cmake)

add_library(${PROJECT_NAME}_lib
src/streets_configuration_exception.cpp
src/configuration.cpp
src/streets_configuration.cpp
)
add_subdirectory(src)


target_include_directories(${PROJECT_NAME}_lib PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries( ${PROJECT_NAME}_lib PUBLIC
Boost::system
Boost::thread
Boost::filesystem
spdlog::spdlog
)



########################################################
# Install streets_service_base_lib package.
########################################################
file(GLOB files ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
file(GLOB templates ${CMAKE_CURRENT_SOURCE_DIR}/include/internal/*.tpp)

install(
TARGETS ${PROJECT_NAME}_lib
EXPORT ${PROJECT_NAME}_libTargets
LIBRARY DESTINATION lib
INCLUDES DESTINATION include
ARCHIVE DESTINATION lib
)
install(
EXPORT ${PROJECT_NAME}_libTargets
FILE ${PROJECT_NAME}_libTargets.cmake
DESTINATION lib/cmake/${PROJECT_NAME}_lib/
NAMESPACE ${PROJECT_NAME}_lib::
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/${PROJECT_NAME}_libConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_libConfig.cmake
INSTALL_DESTINATION lib/${PROJECT_NAME}_lib/${PROJECT_NAME}_lib/ )
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_libConfig.cmake
DESTINATION lib/cmake/${PROJECT_NAME}_lib/
)
install(FILES ${files} DESTINATION include)
install(FILES ${templates} DESTINATION include/internal)


########################
# googletest for unit testing
########################
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(BINARY ${PROJECT_NAME}_test)
file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false test/*.h test/*.cpp)
set(SOURCES ${TEST_SOURCES} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test)


add_executable(${BINARY} ${TEST_SOURCES}
src/streets_configuration_exception.cpp
src/configuration.cpp
src/streets_configuration.cpp
)

add_test(NAME ${BINARY} COMMAND ${BINARY})
target_include_directories(${BINARY} PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(${BINARY} PUBLIC
Boost::system
Boost::thread
Boost::filesystem
spdlog::spdlog
gtest
${PROJECT_NAME}_lib
)
if(STREETSSERVICEBASE_ENABLE_TESTING OR PROJECT_IS_TOP_LEVEL)
add_subdirectory(test)
endif()
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

find_dependency(Boost 1.65.1 COMPONENTS system filesystem thread REQUIRED)
find_dependency(RapidJSON REQUIRED)
find_dependency(spdlog REQUIRED)
find_dependency(GTest)

include("${CMAKE_CURRENT_LIST_DIR}/streets_service_base_libTargets.cmake")
include(${CMAKE_CURRENT_LIST_DIR}/streets_service_base_libTargets.cmake)
7 changes: 7 additions & 0 deletions streets_utils/streets_service_base/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
find_package(RapidJSON REQUIRED)
find_package(Boost COMPONENTS system filesystem thread REQUIRED)
find_package(spdlog 1.10.0 EXACT REQUIRED)

if(STREETSSERVICEBASE_ENABLE_TESTING OR PROJECT_IS_TOP_LEVEL)
find_package(GTest REQUIRED)
endif()
70 changes: 70 additions & 0 deletions streets_utils/streets_service_base/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
include(GNUInstallDirs)

set(STREETSSERVICEBASE_SPDLOG_LEVEL SPDLOG_LEVEL_WARN CACHE STRING "Logging level for spdlog")
set_property(CACHE STREETSSERVICEBASE_SPDLOG_LEVEL PROPERTY STRINGS
SPDLOG_LEVEL_TRACE
SPDLOG_LEVEL_DEBUG
SPDLOG_LEVEL_INFO
SPDLOG_LEVEL_WARN
SPDLOG_LEVEL_ERROR
SPDLOG_LEVEL_CRITICAL
SPDLOG_LEVEL_OFF
)

add_library(streets_service_base_lib
streets_configuration_exception.cpp
configuration.cpp
streets_configuration.cpp
)

add_library(streets_service_base_lib::streets_service_base_lib ALIAS streets_service_base_lib)

target_compile_definitions(streets_service_base_lib
PRIVATE
SPDLOG_ACTIVE_LEVEL=${STREETSSERVICEBASE_SPDLOG_LEVEL}
)

target_compile_options(streets_service_base_lib
PRIVATE
-fPIC
)

target_include_directories(streets_service_base_lib
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)

target_link_libraries(streets_service_base_lib
PUBLIC
Boost::system
Boost::thread
Boost::filesystem
spdlog::spdlog
)

install(TARGETS streets_service_base_lib
EXPORT streets_service_base_libTargets
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(EXPORT streets_service_base_libTargets
FILE streets_service_base_libTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/streets_service_base_lib
NAMESPACE streets_service_base_lib::
)

install(FILES ${PROJECT_SOURCE_DIR}/cmake/streets_service_base_libConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/streets_service_base_lib/
)

install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN *.h
PATTERN *.tpp
)
23 changes: 23 additions & 0 deletions streets_utils/streets_service_base/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
add_executable(streets_service_base_test
test_main.cpp
test_streets_configuration.cpp
test_streets_singleton.cpp
)

target_link_libraries(streets_service_base_test
PRIVATE
Boost::system
Boost::thread
Boost::filesystem
spdlog::spdlog
GTest::GTest
streets_service_base_lib::streets_service_base_lib
)

# The CI system expects the test binary to be in the project's binary root directory
set_target_properties(streets_service_base_test
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
)

gtest_discover_tests(streets_service_base_test)