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

CMake install and find_package working

parent 46e99c69
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)
#TODO: does this project require C++ 20? Then that should be part of the compile features of the targets
set(CMAKE_CXX_STANDARD 20)
include(GNUInstallDirs)
# Define target
add_library(bimap INTERFACE)
target_include_directories(bimap INTERFACE include)
add_library(ojl::bimap ALIAS bimap)
target_include_directories(bimap
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_sources(bimap
INTERFACE FILE_SET HEADERS
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)
......@@ -19,3 +38,34 @@ if (BUILD_TESTS)
enable_testing()
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}")
#This file could just be generated...
include("${CMAKE_CURRENT_LIST_DIR}/bimapTargets.cmake")
......@@ -2,7 +2,7 @@ include(FetchContent)
find_package(Catch2 QUIET)
if (NOT Catch2_FOUND)
message("Could not find Catch2 locally, downloading")
message(STATUS "Could not find Catch2 locally, downloading")
set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
Catch2
......
File moved
File moved
#include <cstdio>
#include <set>
#include <utility>
#include "bimap.hpp"
#include "ojl/bimap.hpp"
int
main(int argc, char* argv[])
......
#include <cstdio>
#include <set>
#include <utility>
#include "bimap.hpp"
#include "ojl/bimap.hpp"
bimap<int, int>
test_bimap1()
......
#include "bimap.hpp"
#include "ojl/bimap.hpp"
#include <string>
#include <cstdint>
#include <vector>
......
......@@ -6,7 +6,7 @@ macro(find_catch2_and_define_test_target)
find_package(Catch2 REQUIRED)
if(Catch2_FOUND)
message(" found Catch2, version: ${Catch2_VERSION}")
message(STATUS "Test setup: found Catch2, version: ${Catch2_VERSION}")
if(NOT TARGET Catch2::Catch2WithMain)
message(SEND_ERROR
"Tests depend on Catch2::Catch2WithMain, but Catch2 was built without "
......
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