Skip to content

Introduce TSL_SPARSE_MAP_ENABLE_INSTALL #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 42 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ cmake_minimum_required(VERSION 3.5)
project(tsl-sparse-map VERSION 0.6.2 LANGUAGES CXX)
include(GNUInstallDirs)

set(IS_MAIN_PROJECT FALSE)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(IS_MAIN_PROJECT TRUE)
endif()

option(TSL_SPARSE_MAP_ENABLE_INSTALL "Enable install target" ${IS_MAIN_PROJECT}) # PROJECT_IS_TOP_LEVEL)

add_library(sparse_map INTERFACE)
# Use tsl::sparse_map as target, more consistent with other libraries conventions (Boost, Qt, ...)
add_library(tsl::sparse_map ALIAS sparse_map)
Expand All @@ -23,52 +30,53 @@ if(MSVC)
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_DATAROOTDIR}/tsl-sparse-map.natvis>")
endif()

# Installation
if(TSL_SPARSE_MAP_ENABLE_INSTALL)
include(CMakePackageConfigHelpers)

## 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-sparse-map.natvis"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}")
endif()

include(CMakePackageConfigHelpers)

## 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-sparse-map.natvis"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}")
endif()

## Create and install tsl-sparse-mapConfig.cmake
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/tsl-sparse-mapConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/tsl-sparse-mapConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/tsl-sparse-map")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tsl-sparse-mapConfig.cmake"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/tsl-sparse-map")

## Create and install tsl-sparse-mapConfig.cmake
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/tsl-sparse-mapConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/tsl-sparse-mapConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/tsl-sparse-map")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tsl-sparse-mapConfig.cmake"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/tsl-sparse-map")

## Create and install tsl-sparse-mapTargets.cmake
install(TARGETS sparse_map
EXPORT tsl-sparse-mapTargets)

install(EXPORT tsl-sparse-mapTargets
NAMESPACE tsl::
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/tsl-sparse-map")

## Create and install tsl-sparse-mapTargets.cmake
install(TARGETS sparse_map
EXPORT tsl-sparse-mapTargets)

install(EXPORT tsl-sparse-mapTargets
NAMESPACE tsl::
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/tsl-sparse-map")

## Create and install tsl-sparse-mapConfigVersion.cmake
# tsl-sparse-map is header-only and does not depend on the architecture.
# Remove CMAKE_SIZEOF_VOID_P from tsl-sparse-mapConfigVersion.cmake so that a
# tsl-sparse-mapConfig.cmake generated for a 64 bit target can be used for 32 bit
# targets and vice versa.
set(CMAKE_SIZEOF_VOID_P_BACKUP ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/tsl-sparse-mapConfigVersion.cmake"
COMPATIBILITY SameMajorVersion)
set(CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P_BACKUP})

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tsl-sparse-mapConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/tsl-sparse-map")

## Create and install tsl-sparse-mapConfigVersion.cmake
# tsl-sparse-map is header-only and does not depend on the architecture.
# Remove CMAKE_SIZEOF_VOID_P from tsl-sparse-mapConfigVersion.cmake so that a
# tsl-sparse-mapConfig.cmake generated for a 64 bit target can be used for 32 bit
# targets and vice versa.
set(CMAKE_SIZEOF_VOID_P_BACKUP ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/tsl-sparse-mapConfigVersion.cmake"
COMPATIBILITY SameMajorVersion)
set(CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P_BACKUP})

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tsl-sparse-mapConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/tsl-sparse-map")
endif()