Skip to content

Commit 8a3be75

Browse files
JohanMabilleTessil
authored andcommitted
Add installation rules in the CMake of the project (#22)
1 parent 789292a commit 8a3be75

3 files changed

Lines changed: 78 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,79 @@
11
cmake_minimum_required(VERSION 3.1)
22

3-
project(tsl_ordered_map)
3+
project(tsl_ordered_map VERSION 0.7.0)
44

5-
add_library(tsl_ordered_map INTERFACE)
5+
add_library(ordered_map INTERFACE)
66
# Use tsl::ordered_map as target, more consistent with other libraries conventions (Boost, Qt, ...)
7-
add_library(tsl::ordered_map ALIAS tsl_ordered_map)
7+
add_library(tsl::ordered_map ALIAS ordered_map)
88

9-
target_include_directories(tsl_ordered_map INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
10-
target_sources(tsl_ordered_map INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_hash.h"
11-
"${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_map.h"
12-
"${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_set.h")
9+
target_include_directories(ordered_map INTERFACE
10+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
11+
$<INSTALL_INTERFACE:include>)
12+
13+
target_sources(ordered_map INTERFACE
14+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_hash.h
15+
${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_map.h
16+
${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_set.h>)
1317

1418
if(MSVC)
15-
target_sources(tsl_ordered_map INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/tsl_ordered_map.natvis")
19+
target_sources(ordered_map INTERFACE
20+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tsl_ordered_map.natvis>
21+
$<INSTALL_INTERFACE:tsl_ordered_map.natvis>)
1622
endif()
1723

1824
if(${CMAKE_VERSION} VERSION_GREATER "3.7")
1925
# Only available since version 3.8
20-
target_compile_features(tsl_ordered_map INTERFACE cxx_std_11)
26+
target_compile_features(ordered_map INTERFACE cxx_std_11)
2127
endif()
28+
29+
30+
31+
32+
# Installation
33+
include(CMakePackageConfigHelpers)
34+
include(GNUInstallDirs)
35+
36+
## Install include directory and potential natvis file
37+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/tsl
38+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
39+
40+
if(MSVC)
41+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tsl_ordered_map.natvis
42+
DESTINATION ".")
43+
endif()
44+
45+
46+
47+
## Create and install tsl_ordered_mapConfig.cmake
48+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
49+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
50+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
51+
52+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
53+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
54+
55+
56+
57+
## Create and install tsl_ordered_mapTargets.cmake
58+
install(TARGETS ordered_map
59+
EXPORT ${PROJECT_NAME}Targets)
60+
61+
install(EXPORT ${PROJECT_NAME}Targets
62+
NAMESPACE tsl::
63+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
64+
65+
66+
67+
## Create and install tsl_ordered_mapConfigVersion.cmake
68+
# ordered_map is header-only and does not depend on the architecture.
69+
# Remove CMAKE_SIZEOF_VOID_P from tsl_ordered_mapConfigVersion.cmake so that an
70+
# tsl_ordered_mapConfig.cmake generated for a 64 bit target can be used for 32 bit
71+
# targets and vice versa.
72+
set(TSL_ORDERED_MAP_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
73+
unset(CMAKE_SIZEOF_VOID_P)
74+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
75+
COMPATIBILITY SameMajorVersion)
76+
set(CMAKE_SIZEOF_VOID_P ${TSL_ORDERED_MAP_CMAKE_SIZEOF_VOID_P})
77+
78+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
79+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ add_subdirectory(third-party/ordered-map)
6161
target_link_libraries(your_target PRIVATE tsl::ordered_map)
6262
```
6363

64+
If the project has been installed through `make install`, you can also use `find_package(tsl_ordered_map REQUIRED)` instead of `add_subdirectory`.
65+
6466
The code should work with any C++11 standard-compliant compiler and has been tested with GCC 4.8.4, Clang 3.5.0 and Visual Studio 2015.
6567

6668
To run the tests you will need the Boost Test library and CMake.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This module sets the following variables:
2+
# * tsl_ordered_map_FOUND - true if tsl_ordered_map found on the system
3+
# * tsl_ordered_map_INCLUDE_DIRS - the directory containing tsl_ordered_map headers
4+
@PACKAGE_INIT@
5+
6+
if(NOT TARGET tsl::ordered_map)
7+
include("${CMAKE_CURRENT_LIST_DIR}/tsl_ordered_mapTargets.cmake")
8+
get_target_property(tsl_ordered_map_INCLUDE_DIRS tsl::ordered_map INTERFACE_INCLUDE_DIRECTORIES)
9+
endif()

0 commit comments

Comments
 (0)