Skip to content

Commit

Permalink
Add CMake install support
Browse files Browse the repository at this point in the history
  • Loading branch information
rigtorp committed Apr 17, 2020
1 parent dcde7ba commit a1527df
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cmake_minimum_required(VERSION 3.6)

project(SPSCQueue LANGUAGES CXX)
project(SPSCQueue VERSION 1.0 LANGUAGES CXX)

add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11)

target_include_directories(SPSCQueue INTERFACE
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

Expand Down Expand Up @@ -42,4 +42,43 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)

enable_testing()
add_test(SPSCQueueTest SPSCQueueTest)
endif()

# Install
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)

export(
TARGETS ${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE "${PROJECT_NAME}Config.cmake"
)

if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
install(
DIRECTORY "include/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(
TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Config"
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(
EXPORT "${PROJECT_NAME}Config"
NAMESPACE ${PROJECT_NAME}::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
endif()

0 comments on commit a1527df

Please sign in to comment.