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

Fixes when including with CMake add_subdirectory() #15

Merged
merged 3 commits into from
Aug 19, 2024
Merged
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
53 changes: 33 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
cmake_minimum_required(VERSION 3.11)
ahogen marked this conversation as resolved.
Show resolved Hide resolved
cmake_policy(SET CMP0077 NEW)

project(cerberus-cpp LANGUAGES CXX)

cmake_minimum_required(VERSION 3.11)
set(CERBERUS_CPP_MAIN_PROJECT OFF)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(CERBERUS_CPP_MAIN_PROJECT ON)
endif()

option(CERBERUS_CPP_FIND_YAML_CPP "Enable find_package(yaml-cpp)." ON)
option(CERBERUS_CPP_INSTALL "Enable generation of cerberus-cpp install targets" ${CERBERUS_CPP_MAIN_PROJECT})

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -13,14 +22,16 @@ if(DOCS_ONLY)
set(REQUIRED_STRING "")
endif()

find_package(yaml-cpp 0.6 ${REQUIRED_STRING})
if(${CERBERUS_CPP_FIND_YAML_CPP})
find_package(yaml-cpp 0.6 ${REQUIRED_STRING})
endif()

# Add library target that can be linked against
add_library(cerberus-cpp INTERFACE)
target_include_directories(
cerberus-cpp
INTERFACE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(cerberus-cpp INTERFACE yaml-cpp)
Expand All @@ -32,7 +43,7 @@ add_library(cerberus-cpp::cerberus-cpp ALIAS cerberus-cpp)
add_subdirectory(doc)

# Add the testing subdirectories
if(EXISTS ${CMAKE_SOURCE_DIR}/ext/Catch2/CMakeLists.txt)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/ext/Catch2/CMakeLists.txt)
include(CTest)
add_subdirectory(ext/Catch2)
add_subdirectory(test)
Expand All @@ -41,24 +52,26 @@ endif()
# Installation rules
include(GNUInstallDirs)

install(
TARGETS cerberus-cpp
EXPORT cerberus-cpp-config
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
if (CERBERUS_CPP_INSTALL)
install(
TARGETS cerberus-cpp
EXPORT cerberus-cpp-config
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(
EXPORT cerberus-cpp-config
NAMESPACE cerberus-cpp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cerberus-cpp
)
install(
EXPORT cerberus-cpp-config
NAMESPACE cerberus-cpp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cerberus-cpp
)

install(
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()

include(FeatureSummary)
feature_summary(WHAT ALL)