basedOpinionated utility library |
git clone git://git.dimitrijedobrota.com/based.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
commit | c521dbe99b9c3fe2f43691c3d2fac4ea01d3883a |
parent | 5c23715f617524c3b0e7c9273fde573ebfc7582e |
author | Dimitrije Dobrota < mail@dimitrijedobrota.com > |
date | Mon, 5 May 2025 11:49:29 +0200 |
Proper header-only config
M | CMakeLists.txt | | | +++++ ------------------------------- |
M | cmake/install-rules.cmake | | | +++++++ ------------- |
M | cmake/variables.cmake | | | ------------- |
D | source/empty.cpp | | | |
M | test/CMakeLists.txt | | | +++++ |
5 files changed, 17 insertions(+), 57 deletions(-)
diff --git a/ CMakeLists.txt b/ CMakeLists.txt
@@ -15,47 +15,21 @@
include(cmake/variables.cmake)
# ---- Declare library ----
add_library(
based_based
source/empty.cpp
)
add_library(based_based INTERFACE)
add_library(based::based ALIAS based_based)
include(GenerateExportHeader)
generate_export_header(
based_based
BASE_NAME based
EXPORT_FILE_NAME export/based/based_export.hpp
CUSTOM_CONTENT_FROM_VARIABLE pragma_suppress_c4251
)
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(based_based PUBLIC BASED_STATIC_DEFINE)
endif()
set_target_properties(
based_based PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN YES
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}"
set_property(
TARGET based_based PROPERTY
EXPORT_NAME based
OUTPUT_NAME based
)
target_include_directories(
based_based ${warning_guard}
PUBLIC
INTERFACE
"\$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
)
target_include_directories(
based_based SYSTEM
PUBLIC
"\$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/export>"
)
target_compile_features(based_based PUBLIC cxx_std_20)
target_compile_features(based_based INTERFACE cxx_std_20)
# ---- Install rules ----
diff --git a/ cmake/install-rules.cmake b/ cmake/install-rules.cmake
@@ -6,6 +6,9 @@
if(PROJECT_IS_TOP_LEVEL)
set_property(CACHE CMAKE_INSTALL_INCLUDEDIR PROPERTY TYPE PATH)
endif()
# Project is configured with no languages, so tell GNUInstallDirs the lib dir
set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "")
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
@@ -13,9 +16,7 @@
include(GNUInstallDirs)
set(package based)
install(
DIRECTORY
include/
"${PROJECT_BINARY_DIR}/export/"
DIRECTORY include/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT based_Development
)
@@ -23,25 +24,18 @@
install(
install(
TARGETS based_based
EXPORT basedTargets
RUNTIME #
COMPONENT based_Runtime
LIBRARY #
COMPONENT based_Runtime
NAMELINK_COMPONENT based_Development
ARCHIVE #
COMPONENT based_Development
INCLUDES #
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
write_basic_package_version_file(
"${package}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
# Allow package maintainers to freely override the path for the configs
set(
based_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${package}"
based_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/${package}"
CACHE STRING "CMake package config location relative to the install prefix"
)
set_property(CACHE based_INSTALL_CMAKEDIR PROPERTY TYPE PATH)
diff --git a/ cmake/variables.cmake b/ cmake/variables.cmake
@@ -6,21 +6,8 @@
# consumers can trivially build and package the project
if(PROJECT_IS_TOP_LEVEL)
option(based_DEVELOPER_MODE "Enable developer mode" OFF)
option(BUILD_SHARED_LIBS "Build shared libs." OFF)
endif()
# ---- Suppress C4251 on Windows ----
# Please see include/based/based.hpp for more details
set(pragma_suppress_c4251 "
/* This needs to suppress only for MSVC */
#if defined(_MSC_VER) && !defined(__ICL)
# define BASED_SUPPRESS_C4251 _Pragma(\"warning(suppress:4251)\")
#else
# define BASED_SUPPRESS_C4251
#endif
")
# ---- Warning guard ----
# target_include_directories with the SYSTEM modifier will request the compiler
diff --git a/ source/empty.cpp b/ source/empty.cpp
diff --git a/ test/CMakeLists.txt b/ test/CMakeLists.txt
@@ -7,6 +7,11 @@
include(../cmake/folders.cmake)
# ---- Dependencies ----
if(PROJECT_IS_TOP_LEVEL)
find_package(based REQUIRED)
enable_testing()
endif()
find_package(Catch2 REQUIRED)
include(Catch)