add cmake install targets

This commit is contained in:
BlackMATov
2023-01-05 09:45:47 +07:00
parent d75fe30108
commit 3a628a5f80
20 changed files with 160 additions and 52 deletions

View File

@@ -10,6 +10,7 @@ Checks: '-*,
-cppcoreguidelines-pro-bounds-constant-array-index,
modernize-*,
-modernize-macro-to-enum,
-modernize-use-trailing-return-type,
performance-*,
@@ -17,5 +18,6 @@ Checks: '-*,
portability-*,
readability-*,
-readability-identifier-length,
'
...

2
.gitignore vendored
View File

@@ -1,4 +1,4 @@
build/*
install/*
.clangd/*
.vscode/*
CMakeLists.txt.user

11
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [{
"name": "LLDB Debug",
"type": "lldb",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"cwd": "${workspaceFolder}"
}]
}

29
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,29 @@
{
"[cpp]": {
"files.encoding": "utf8",
"files.insertFinalNewline": true,
"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",
"--clang-tidy",
"--compile-commands-dir=${workspaceFolder}/.clangd",
"--completion-style=detailed",
"--header-insertion=never"
],
"cmake.copyCompileCommands": "${workspaceFolder}/.clangd/compile_commands.json"
}

View File

@@ -1,25 +1,83 @@
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
if(NOT DEFINED PROJECT_NAME)
set(BUILD_AS_STANDALONE ON)
else()
set(BUILD_AS_STANDALONE OFF)
endif()
project(enum.hpp
VERSION "0.0.1"
DESCRIPTION "C++17 compile-time enum reflection library"
HOMEPAGE_URL "https://github.com/blackmatov/enum.hpp")
project(enum.hpp)
#
# LIBRARY
#
add_library(${PROJECT_NAME} INTERFACE)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
target_include_directories(${PROJECT_NAME} INTERFACE headers)
add_library(enum.hpp::enum.hpp ALIAS ${PROJECT_NAME})
target_compile_features(${PROJECT_NAME} INTERFACE
cxx_std_17)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/headers>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
#
# BUILD_AS_STANDALONE
# INSTALL
#
if(NOT ${BUILD_AS_STANDALONE})
return()
if(PROJECT_IS_TOP_LEVEL)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
set(ENUM_HPP_INSTALL_CONFIG_DIR
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(ENUM_HPP_INSTALL_CONFIG_INPUT
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in")
set(ENUM_HPP_INSTALL_GENERATED_CONFIG_CMAKE
"${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}-config.cmake")
set(ENUM_HPP_INSTALL_GENERATED_CONFIG_VERSION_CMAKE
"${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}-config-version.cmake")
configure_package_config_file(
"${ENUM_HPP_INSTALL_CONFIG_INPUT}"
"${ENUM_HPP_INSTALL_GENERATED_CONFIG_CMAKE}"
INSTALL_DESTINATION "${ENUM_HPP_INSTALL_CONFIG_DIR}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
"${ENUM_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 "${ENUM_HPP_INSTALL_CONFIG_DIR}")
install(
FILES "${ENUM_HPP_INSTALL_GENERATED_CONFIG_CMAKE}"
"${ENUM_HPP_INSTALL_GENERATED_CONFIG_VERSION_CMAKE}"
DESTINATION "${ENUM_HPP_INSTALL_CONFIG_DIR}")
endif()
#
# DEVELOPER
#
if(PROJECT_IS_TOP_LEVEL)
option(BUILD_WITH_COVERAGE "Build with coverage" OFF)
option(BUILD_WITH_SANITIZERS "Build with sanitizers" OFF)
@@ -34,3 +92,4 @@ include(EnableUBSan)
add_subdirectory(vendors)
add_subdirectory(untests)
endif()

View File

@@ -3,7 +3,7 @@
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"minor": 21,
"patch": 0
},

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com)
Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

3
cmake/Config.cmake.in Normal file
View File

@@ -0,0 +1,3 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/enum.hpp-targets.cmake")

View File

@@ -1,14 +1,15 @@
# https://clang.llvm.org/docs/AddressSanitizer.html
add_library(enable_asan INTERFACE)
add_library(${PROJECT_NAME}.enable_asan INTERFACE)
add_library(${PROJECT_NAME}::enable_asan ALIAS ${PROJECT_NAME}.enable_asan)
target_compile_options(enable_asan INTERFACE
target_compile_options(${PROJECT_NAME}.enable_asan INTERFACE
-fsanitize=address
-fno-omit-frame-pointer
-fsanitize-address-use-after-scope
-fsanitize-address-use-after-return=always)
target_link_options(enable_asan INTERFACE
target_link_options(${PROJECT_NAME}.enable_asan INTERFACE
-fsanitize=address
-fno-omit-frame-pointer
-fsanitize-address-use-after-scope

View File

@@ -1,9 +1,10 @@
# https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
add_library(enable_gcov INTERFACE)
add_library(${PROJECT_NAME}.enable_gcov INTERFACE)
add_library(${PROJECT_NAME}::enable_gcov ALIAS ${PROJECT_NAME}.enable_gcov)
target_compile_options(enable_gcov INTERFACE
target_compile_options(${PROJECT_NAME}.enable_gcov INTERFACE
--coverage)
target_link_options(enable_gcov INTERFACE
target_link_options(${PROJECT_NAME}.enable_gcov INTERFACE
--coverage)

View File

@@ -1,11 +1,12 @@
# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
add_library(enable_ubsan INTERFACE)
add_library(${PROJECT_NAME}.enable_ubsan INTERFACE)
add_library(${PROJECT_NAME}::enable_ubsan ALIAS ${PROJECT_NAME}.enable_ubsan)
target_compile_options(enable_ubsan INTERFACE
target_compile_options(${PROJECT_NAME}.enable_ubsan INTERFACE
-fsanitize=undefined
-fno-omit-frame-pointer)
target_link_options(enable_ubsan INTERFACE
target_link_options(${PROJECT_NAME}.enable_ubsan INTERFACE
-fsanitize=undefined
-fno-omit-frame-pointer)

View File

@@ -1,7 +1,7 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/enum.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once

View File

@@ -1,7 +1,7 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/enum.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once

View File

@@ -1,16 +1,17 @@
---
Checks: '-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
clang-analyzer-*,
concurrency-*,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-bounds-constant-array-index,
modernize-*,
-modernize-avoid-c-arrays,
-modernize-use-auto,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
portability-*,

View File

@@ -4,7 +4,7 @@ file(GLOB_RECURSE UNTESTS_SOURCES "*.cpp" "*.hpp")
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${UNTESTS_SOURCES})
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE enum.hpp)
target_link_libraries(${PROJECT_NAME} PRIVATE enum.hpp::enum.hpp)
#
# setup defines
@@ -23,14 +23,14 @@ setup_defines_for_target(${PROJECT_NAME})
#
function(setup_libraries_for_target TARGET)
target_link_libraries(${TARGET} PRIVATE doctest_with_main)
target_link_libraries(${TARGET} PRIVATE doctest::doctest_with_main)
if(${BUILD_WITH_COVERAGE})
target_link_libraries(${TARGET} PRIVATE enable_gcov)
target_link_libraries(${TARGET} PRIVATE enum.hpp::enable_gcov)
endif()
if(${BUILD_WITH_SANITIZERS})
target_link_libraries(${TARGET} PRIVATE enable_asan enable_ubsan)
target_link_libraries(${TARGET} PRIVATE enum.hpp::enable_asan enum.hpp::enable_ubsan)
endif()
endfunction()

View File

@@ -1,7 +1,7 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/enum.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include <enum.hpp/enum_bitflags.hpp>

View File

@@ -1,7 +1,7 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/enum.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include <enum.hpp/enum_bitflags.hpp>

View File

@@ -1,7 +1,7 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/enum.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include <enum.hpp/enum.hpp>

View File

@@ -1,7 +1,7 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/enum.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019-2022, by Matvey Cherevko (blackmatov@gmail.com)
* Copyright (C) 2019-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include <enum.hpp/enum.hpp>

View File

@@ -1,5 +1,5 @@
project(vmath.hpp.vendors)
project(enum.hpp.vendors)
set(DOCTEST_NO_INSTALL ON CACHE INTERNAL "")
add_subdirectory(doctest)
set_target_properties(doctest_with_main PROPERTIES FOLDER vmath.hpp.vendors)
set_target_properties(doctest_with_main PROPERTIES FOLDER enum.hpp.vendors)