mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 03:45:30 +07:00
add cmake install targets
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
build/*
|
||||
install/*
|
||||
.clangd/*
|
||||
CMakeLists.txt.user
|
||||
|
||||
12
.vscode/settings.json
vendored
12
.vscode/settings.json
vendored
@@ -5,6 +5,18 @@
|
||||
"files.trimFinalNewlines": true,
|
||||
"files.trimTrailingWhitespace": true
|
||||
},
|
||||
"[cmake]": {
|
||||
"files.encoding": "utf8",
|
||||
"files.insertFinalNewline": true,
|
||||
"files.trimFinalNewlines": true,
|
||||
"files.trimTrailingWhitespace": true
|
||||
},
|
||||
"[python]": {
|
||||
"files.encoding": "utf8",
|
||||
"files.insertFinalNewline": true,
|
||||
"files.trimFinalNewlines": true,
|
||||
"files.trimTrailingWhitespace": true
|
||||
},
|
||||
"clangd.arguments": [
|
||||
"--all-scopes-completion",
|
||||
"--background-index",
|
||||
|
||||
@@ -1,48 +1,86 @@
|
||||
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
|
||||
|
||||
#
|
||||
# VERSION
|
||||
#
|
||||
|
||||
file(READ headers/meta.hpp/meta_base/base.hpp META_HPP_BASE_FILE)
|
||||
|
||||
string(REGEX MATCH "#define[ ]+META_HPP_VERSION_MAJOR[ ]+([0-9]+)" _ ${META_HPP_BASE_FILE})
|
||||
set(META_HPP_VERSION_MAJOR "${CMAKE_MATCH_1}")
|
||||
|
||||
string(REGEX MATCH "#define[ ]+META_HPP_VERSION_MINOR[ ]+([0-9]+)" _ ${META_HPP_BASE_FILE})
|
||||
set(META_HPP_VERSION_MINOR "${CMAKE_MATCH_1}")
|
||||
|
||||
string(REGEX MATCH "#define[ ]+META_HPP_VERSION_PATCH[ ]+([0-9]+)" _ ${META_HPP_BASE_FILE})
|
||||
set(META_HPP_VERSION_PATCH "${CMAKE_MATCH_1}")
|
||||
|
||||
set(META_HPP_VERSION ${META_HPP_VERSION_MAJOR}.${META_HPP_VERSION_MINOR}.${META_HPP_VERSION_PATCH})
|
||||
|
||||
#
|
||||
# PROJECT
|
||||
#
|
||||
|
||||
project(meta.hpp
|
||||
VERSION ${META_HPP_VERSION}
|
||||
VERSION "0.0.1"
|
||||
DESCRIPTION "C++20 tiny dynamic reflection library"
|
||||
HOMEPAGE_URL "https://github.com/blackmatov/meta.hpp")
|
||||
|
||||
#
|
||||
# LIBRARY
|
||||
#
|
||||
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
add_library(meta.hpp::meta.hpp ALIAS ${PROJECT_NAME})
|
||||
|
||||
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20)
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE headers)
|
||||
target_compile_features(${PROJECT_NAME} INTERFACE
|
||||
cxx_std_20)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/headers>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(${PROJECT_NAME} INTERFACE Threads::Threads)
|
||||
|
||||
#
|
||||
# INSTALL
|
||||
#
|
||||
|
||||
if(PROJECT_IS_TOP_LEVEL)
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(META_HPP_INSTALL_CONFIG_DIR
|
||||
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
||||
|
||||
set(META_HPP_INSTALL_CONFIG_INPUT
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in")
|
||||
|
||||
set(META_HPP_INSTALL_GENERATED_CONFIG_CMAKE
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}-config.cmake")
|
||||
|
||||
set(META_HPP_INSTALL_GENERATED_CONFIG_VERSION_CMAKE
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}-config-version.cmake")
|
||||
|
||||
configure_package_config_file(
|
||||
"${META_HPP_INSTALL_CONFIG_INPUT}"
|
||||
"${META_HPP_INSTALL_GENERATED_CONFIG_CMAKE}"
|
||||
INSTALL_DESTINATION "${META_HPP_INSTALL_CONFIG_DIR}"
|
||||
NO_SET_AND_CHECK_MACRO
|
||||
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${META_HPP_INSTALL_GENERATED_CONFIG_VERSION_CMAKE}"
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
ARCH_INDEPENDENT)
|
||||
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}-targets
|
||||
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
|
||||
install(
|
||||
DIRECTORY headers/${PROJECT_NAME}
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
|
||||
install(
|
||||
EXPORT ${PROJECT_NAME}-targets
|
||||
FILE ${PROJECT_NAME}-targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION "${META_HPP_INSTALL_CONFIG_DIR}")
|
||||
|
||||
install(
|
||||
FILES "${META_HPP_INSTALL_GENERATED_CONFIG_CMAKE}"
|
||||
"${META_HPP_INSTALL_GENERATED_CONFIG_VERSION_CMAKE}"
|
||||
DESTINATION "${META_HPP_INSTALL_CONFIG_DIR}")
|
||||
endif()
|
||||
|
||||
#
|
||||
# DEVELOPER
|
||||
#
|
||||
|
||||
if(NOT PROJECT_IS_TOP_LEVEL)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(PROJECT_IS_TOP_LEVEL)
|
||||
option(BUILD_WITH_COVERAGE "Build with coverage" OFF)
|
||||
option(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF)
|
||||
|
||||
@@ -59,3 +97,4 @@ add_subdirectory(manuals)
|
||||
add_subdirectory(singles)
|
||||
add_subdirectory(vendors)
|
||||
add_subdirectory(untests)
|
||||
endif()
|
||||
|
||||
6
cmake/Config.cmake.in
Normal file
6
cmake/Config.cmake.in
Normal file
@@ -0,0 +1,6 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
find_dependency(Threads REQUIRED)
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/meta.hpp-targets.cmake")
|
||||
@@ -34,10 +34,6 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#define META_HPP_VERSION_MAJOR 0
|
||||
#define META_HPP_VERSION_MINOR 0
|
||||
#define META_HPP_VERSION_PATCH 1
|
||||
|
||||
#if !defined(__cpp_exceptions)
|
||||
# define META_HPP_NO_EXCEPTIONS
|
||||
#endif
|
||||
|
||||
@@ -29,11 +29,11 @@ setup_defines_for_target(${PROJECT_NAME}.singles)
|
||||
function(setup_libraries_for_target TARGET)
|
||||
target_link_libraries(${TARGET} PRIVATE doctest::doctest_with_main)
|
||||
|
||||
if(${BUILD_WITH_COVERAGE})
|
||||
if(BUILD_WITH_COVERAGE)
|
||||
target_link_libraries(${TARGET} PRIVATE meta.hpp::enable_gcov)
|
||||
endif()
|
||||
|
||||
if(${BUILD_WITH_SANITIZERS})
|
||||
if(BUILD_WITH_SANITIZERS)
|
||||
target_link_libraries(${TARGET} PRIVATE meta.hpp::enable_asan meta.hpp::enable_ubsan)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
@@ -31,10 +31,6 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#define META_HPP_VERSION_MAJOR 0
|
||||
#define META_HPP_VERSION_MINOR 0
|
||||
#define META_HPP_VERSION_PATCH 1
|
||||
|
||||
#if !defined(__cpp_exceptions)
|
||||
# define META_HPP_NO_EXCEPTIONS
|
||||
#endif
|
||||
|
||||
@@ -29,11 +29,11 @@ setup_defines_for_target(${PROJECT_NAME}.singles)
|
||||
function(setup_libraries_for_target TARGET)
|
||||
target_link_libraries(${TARGET} PRIVATE doctest::doctest_with_main)
|
||||
|
||||
if(${BUILD_WITH_COVERAGE})
|
||||
if(BUILD_WITH_COVERAGE)
|
||||
target_link_libraries(${TARGET} PRIVATE meta.hpp::enable_gcov)
|
||||
endif()
|
||||
|
||||
if(${BUILD_WITH_SANITIZERS})
|
||||
if(BUILD_WITH_SANITIZERS)
|
||||
target_link_libraries(${TARGET} PRIVATE meta.hpp::enable_asan meta.hpp::enable_ubsan)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
Reference in New Issue
Block a user