Skip to content

Commit

Permalink
Add installation rules in the CMake of the project (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille authored and Tessil committed Oct 10, 2018
1 parent 789292a commit 8a3be75
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 9 deletions.
76 changes: 67 additions & 9 deletions CMakeLists.txt
@@ -1,21 +1,79 @@
cmake_minimum_required(VERSION 3.1)

project(tsl_ordered_map)
project(tsl_ordered_map VERSION 0.7.0)

add_library(tsl_ordered_map INTERFACE)
add_library(ordered_map INTERFACE)
# Use tsl::ordered_map as target, more consistent with other libraries conventions (Boost, Qt, ...)
add_library(tsl::ordered_map ALIAS tsl_ordered_map)
add_library(tsl::ordered_map ALIAS ordered_map)

target_include_directories(tsl_ordered_map INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_sources(tsl_ordered_map INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_hash.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_map.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_set.h")
target_include_directories(ordered_map INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

target_sources(ordered_map INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_hash.h
${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_map.h
${CMAKE_CURRENT_SOURCE_DIR}/include/tsl/ordered_set.h>)

if(MSVC)
target_sources(tsl_ordered_map INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/tsl_ordered_map.natvis")
target_sources(ordered_map INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tsl_ordered_map.natvis>
$<INSTALL_INTERFACE:tsl_ordered_map.natvis>)
endif()

if(${CMAKE_VERSION} VERSION_GREATER "3.7")
# Only available since version 3.8
target_compile_features(tsl_ordered_map INTERFACE cxx_std_11)
target_compile_features(ordered_map INTERFACE cxx_std_11)
endif()




# Installation
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

## Install include directory and potential natvis file
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/tsl
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

if(MSVC)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tsl_ordered_map.natvis
DESTINATION ".")
endif()



## Create and install tsl_ordered_mapConfig.cmake
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})



## Create and install tsl_ordered_mapTargets.cmake
install(TARGETS ordered_map
EXPORT ${PROJECT_NAME}Targets)

install(EXPORT ${PROJECT_NAME}Targets
NAMESPACE tsl::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})



## Create and install tsl_ordered_mapConfigVersion.cmake
# ordered_map is header-only and does not depend on the architecture.
# Remove CMAKE_SIZEOF_VOID_P from tsl_ordered_mapConfigVersion.cmake so that an
# tsl_ordered_mapConfig.cmake generated for a 64 bit target can be used for 32 bit
# targets and vice versa.
set(TSL_ORDERED_MAP_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
set(CMAKE_SIZEOF_VOID_P ${TSL_ORDERED_MAP_CMAKE_SIZEOF_VOID_P})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -61,6 +61,8 @@ add_subdirectory(third-party/ordered-map)
target_link_libraries(your_target PRIVATE tsl::ordered_map)
```

If the project has been installed through `make install`, you can also use `find_package(tsl_ordered_map REQUIRED)` instead of `add_subdirectory`.

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.

To run the tests you will need the Boost Test library and CMake.
Expand Down
9 changes: 9 additions & 0 deletions cmake/tsl_ordered_mapConfig.cmake.in
@@ -0,0 +1,9 @@
# This module sets the following variables:
# * tsl_ordered_map_FOUND - true if tsl_ordered_map found on the system
# * tsl_ordered_map_INCLUDE_DIRS - the directory containing tsl_ordered_map headers
@PACKAGE_INIT@

if(NOT TARGET tsl::ordered_map)
include("${CMAKE_CURRENT_LIST_DIR}/tsl_ordered_mapTargets.cmake")
get_target_property(tsl_ordered_map_INCLUDE_DIRS tsl::ordered_map INTERFACE_INCLUDE_DIRECTORIES)
endif()

0 comments on commit 8a3be75

Please sign in to comment.