Skip to content
Snippets Groups Projects
Commit ee29a35a authored by Oskar Lappi's avatar Oskar Lappi
Browse files

Better CMake config, "namespaced" package name

parent 009eba1b
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 3.16)
project(bimap CXX)
set(PROJECT_VERSION 0.0.1)
project(ojl_bimap VERSION 0.0.1 LANGUAGES CXX)
#TODO: does this project require C++ 20? Then that should be part of the compile features of the targets
set(CMAKE_CXX_STANDARD 20)
......@@ -9,6 +8,7 @@ include(GNUInstallDirs)
# Define target
add_library(bimap INTERFACE)
add_library(ojl::bimap ALIAS bimap)
target_include_directories(bimap
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
......@@ -19,12 +19,6 @@ target_sources(bimap
BASE_DIRS ${PROJECT_SOURCE_DIR}/include/ojl
FILES ${PROJECT_SOURCE_DIR}/include/ojl/bimap.hpp
)
#target_include_directories(bimap INTERFACE include)
#REMEMBER, usually we would do target_include_directories(bimap PUBLIC $<BUILD_INTERFACE:${bimap_SOURCE_DIR}/include> $<BUILD_INTERFACE:${bimap_BINARY_DIR}/include> $<INSTALL_INTERFACE:include>)
#But we just need the one in this case, since include is in the cmake root dir
add_subdirectory(samples)
option(DOWNLOAD_DEPS "Download unsatisfied dependencies using FetchContent" ON)
......@@ -39,33 +33,5 @@ if (BUILD_TESTS)
add_subdirectory(test)
endif()
# Define export set bimapTargets, install headers (but this doesn't actually install them...)
install(TARGETS bimap
EXPORT bimapTargets
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ojl
)
# Install the headers at the install location
# Export the targets (?) what I don't get is how the bimapTargets.cmake differs from bimapConfig.cmake, why do we need both?
# This still only installs a target named "bimap", not ojl::bimap ??? Even though it says NAMESPACE ojl here
install(EXPORT bimapTargets
FILE bimapTargets.cmake
NAMESPACE ojl::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bimap
)
#TODO: generate a file that checks the version number using CMakePackageConfigHelpers (write_basic_package_version_file)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"bimapConfigVersion.cmake"
VERSION ${bimap_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES "bimapConfig.cmake" "${CMAKE_BINARY_DIR}/bimapConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bimap
)
### SEPARATE FILE TO BE INSTALLED ? ###
# find dependencies if needed
# include("${CMAKE_CURRENT_LIST_DIR}/bimapTargets.cmake}")
# Install
include(cmake/install_bimap.cmake)
#This file could just be generated...
include("${CMAKE_CURRENT_LIST_DIR}/bimapTargets.cmake")
# Install config
# Define export set bimapTargets, install headers
install(TARGETS bimap
EXPORT ojl_bimapExports
FILE_SET HEADERS
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/ojl
)
# Generate the export set file
install(EXPORT ojl_bimapExports
FILE ojl_bimapExports.cmake
NAMESPACE ojl::
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/ojl_bimap-${PROJECT_VERSION}
)
#I'd like for these paths to be cmake/ojl/bimap-version, but CMake won't find that
#Generate the config
include(CMakePackageConfigHelpers)
# Generate the CMake Config file
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/ojl_bimapConfig.cmake.in"
"${PROJECT_BINARY_DIR}/ojl_bimapConfig.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/ojl_bimap-${PROJECT_VERSION}
)
# Generate a file that checks the version
write_basic_package_version_file(
"ojl_bimapConfigVersion.cmake"
VERSION ${bimap_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/ojl_bimapConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/ojl_bimapConfigVersion.cmake"
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/ojl_bimap-${PROJECT_VERSION}
)
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/ojl_bimapExports.cmake")
include(cmake/TestSetup.cmake)
find_catch2_and_define_test_target()
find_catch2_and_define_test_target(bimap)
include(Catch)
include(CTest)
......
#TODO: make this macro take an argument
macro(find_catch2_and_define_test_target)
if (TARGET TestInterface)
set(TestInterface_EXISTS 1)
......@@ -17,10 +18,19 @@ macro(find_catch2_and_define_test_target)
if(NOT TestInterface_EXISTS)
add_library(TestInterface INTERFACE)
target_link_libraries(TestInterface INTERFACE ${PROJECT_NAME} Catch2::Catch2WithMain)
target_link_libraries(TestInterface INTERFACE Catch2::Catch2WithMain)
if(NOT ${Catch2_VERSION} VERSION_GREATER_EQUAL "3")
target_compile_definitions(TestInterface INTERFACE TESTS_CATCH2_USE_OLD_HEADER=1)
endif()
# Link against additional arguments given to the macro
set(test_libraries ${ARGN})
list(LENGTH test_libraries lib_count)
if (${lib_count} GREATER 0)
target_link_libraries(TestInterface INTERFACE ${test_libraries})
endif()
endif()
endmacro()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment