Skip to content

Commit 4787949

Browse files
committed
Added CMake config file and complete export target
1 parent aef5636 commit 4787949

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

CMakeLists.txt

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
cmake_minimum_required(VERSION 3.8)
22

3+
# Setup main project
34
project(oup LANGUAGES CXX VERSION 1.0)
45

6+
# Create library (header-only)
57
add_library(oup INTERFACE)
68
add_library(oup::oup ALIAS oup)
79
set_target_properties(oup PROPERTIES EXPORT_NAME oup::oup)
810

9-
target_sources(oup INTERFACE ${PROJECT_SOURCE_DIR}/include/oup/observable_unique_ptr.hpp)
10-
target_include_directories(oup INTERFACE ${PROJECT_SOURCE_DIR}/include)
11+
target_sources(oup INTERFACE
12+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/oup/observable_unique_ptr.hpp>
13+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/oup/observable_unique_ptr.hpp>)
14+
target_include_directories(oup INTERFACE
15+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
16+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
1117
target_compile_features(oup INTERFACE cxx_std_17)
1218

13-
install(FILES ${PROJECT_SOURCE_DIR}/include/oup/observable_unique_ptr.hpp DESTINATION include/oup)
14-
install(TARGETS oup EXPORT oup)
19+
# Setup install target and exports
20+
install(FILES ${PROJECT_SOURCE_DIR}/include/oup/observable_unique_ptr.hpp
21+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/oup)
22+
install(TARGETS oup EXPORT oup-targets)
1523

24+
install(EXPORT oup-targets
25+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/oup COMPONENT Development)
26+
27+
export(EXPORT oup-targets)
28+
29+
# Setup CMake config file
30+
include(CMakePackageConfigHelpers)
31+
configure_package_config_file(
32+
"${PROJECT_SOURCE_DIR}/cmake/oup-config.cmake.in"
33+
"${PROJECT_BINARY_DIR}/oup-config.cmake"
34+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}
35+
NO_CHECK_REQUIRED_COMPONENTS_MACRO
36+
NO_SET_AND_CHECK_MACRO)
37+
38+
install(FILES
39+
"${PROJECT_BINARY_DIR}/oup-config.cmake"
40+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/oup COMPONENT Development)
41+
42+
# Setup tests
1643
if (OUP_DO_TEST)
1744
enable_testing()
1845
add_subdirectory(tests)

cmake/oup-config.cmake.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/oup-targets.cmake")
4+
5+
if (NOT TARGET oup)
6+
add_library(oup INTERFACE IMPORTED)
7+
# Equivalent to target_link_libraries INTERFACE, but compatible with CMake 3.10
8+
set_target_properties(oup PROPERTIES INTERFACE_LINK_LIBRARIES oup::oup)
9+
endif ()

0 commit comments

Comments
 (0)