Add indicatorsConfigVersion cmake support + create source packages

This commit is contained in:
Anonymous Maarten
2020-02-20 21:12:19 +01:00
parent 3c969556c3
commit 7c762ed146
3 changed files with 75 additions and 31 deletions

View File

@@ -1,8 +1,16 @@
cmake_minimum_required(VERSION 3.8)
project(indicators VERSION 1.7.0 LANGUAGES CXX DESCRIPTION "Activity Indicators for Modern C++")
option(INDICATORS_BUILD_TESTS OFF)
option(SAMPLES "Build Samples" OFF)
option(DEMO "Build Demo" OFF)
if(DEFINED PROJECT_NAME)
set(INDICATORS_SUBPROJECT ON)
endif()
project(indicators VERSION 1.7.0 LANGUAGES CXX
HOMEPAGE_URL "https://github.com/p-ranav/indicators"
DESCRIPTION "Activity Indicators for Modern C++")
option(INDICATORS_BUILD_TESTS "Build indicators tests + enable CTest")
option(INDICATORS_SAMPLES "Build indicators samples")
option(INDICATORS_DEMO "Build indicators demo" OFF)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
@@ -18,33 +26,68 @@ target_include_directories(indicators INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)
target_link_libraries(indicators INTERFACE Threads::Threads)
if( DEMO )
if(INDICATORS_DEMO)
add_subdirectory(demo)
endif()
if( SAMPLES )
if(INDICATORS_SAMPLES)
add_subdirectory(samples)
endif()
configure_package_config_file(indicatorsConfig.cmake.in
if(NOT INDICATORS_SUBPROJECT)
configure_package_config_file(indicatorsConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators)
write_basic_package_version_file(indicatorsConfigVersion.cmake
COMPATIBILITY AnyNewerVersion)
configure_file(indicators.pc.in
"${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/indicators.pc"
@ONLY)
configure_file(indicators.pc.in indicators.pc @ONLY)
install(TARGETS indicators EXPORT indicatorsTargets)
install(EXPORT indicatorsTargets
install(TARGETS indicators EXPORT indicatorsTargets)
install(EXPORT indicatorsTargets
FILE indicatorsTargets.cmake
NAMESPACE indicators::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfig.cmake
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/indicatorsConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/indicators)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/indicators.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/indicators
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/indicators.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/indicators
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
USE_SOURCE_PERMISSIONS
PATTERN "*.hpp")
install(FILES LICENSE LICENSE.termcolor
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/licenses/indicators)
if(EXISTS "${PROJECT_SOURCE_DIR}/.gitignore")
# Simple glob to regex conversion (.gitignore => CPACK_SOURCE_IGNORE_FILES)
file(READ ".gitignore" DOT_GITIGNORE)
string(REPLACE ";" "RANDOMSEQUENCE" DOT_GITIGNORE "${DOT_GITIGNORE}")
string(REPLACE "\n" ";" DOT_GITIGNORE "${DOT_GITIGNORE}")
string(REPLACE "RANDOMSEQUENCE" "\\;" DOT_GITIGNORE "${DOT_GITIGNORE}")
foreach(IGNORE_LINE ${DOT_GITIGNORE})
if(NOT IGNORE_LINE OR IGNORE_LINE MATCHES "^#")
continue()
endif()
string(REPLACE "\\" "\\\\" IGNORE_LINE "${IGNORE_LINE}")
string(REPLACE "." "\\\\." IGNORE_LINE "${IGNORE_LINE}")
string(REPLACE "*" ".*" IGNORE_LINE "${IGNORE_LINE}")
string(REPLACE "+" "\\\\+" IGNORE_LINE "${IGNORE_LINE}")
list(APPEND CPACK_SOURCE_IGNORE_FILES "${IGNORE_LINE}")
endforeach()
endif()
# extra ignored files
list(APPEND CPACK_SOURCE_IGNORE_FILES
.editorconfig
.git
.gitignore
.travis.yml
.appveyor.yml
)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
set(CPACK_GENERATOR "TGZ;TXZ")
set(CPACK_SOURCE_GENERATOR "TGZ;TXZ")
include(CPack)
endif()

View File

@@ -1,6 +1,7 @@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: indicators
Description: Activity Indicators for Modern C++
Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Cflags: -I${includedir}

View File

@@ -2,7 +2,7 @@
include(CMakeFindDependencyMacro)
find_dependency(Threads)
find_dependency(Threads REQUIRED)
if (NOT TARGET indicators::indicators)
include(${CMAKE_CURRENT_LIST_DIR}/indicatorsTargets.cmake)