Skip to content

Commit

Permalink
Merge pull request #15 from ahogen/main
Browse files Browse the repository at this point in the history
Fixes when including with CMake add_subdirectory()
  • Loading branch information
dokempf authored Aug 19, 2024
2 parents f1ddc98 + d116c63 commit 50cd91e
Showing 1 changed file with 33 additions and 20 deletions.
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)
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)

0 comments on commit 50cd91e

Please sign in to comment.