From 5e49ed5f9aaeccbac9c70dbbbd2b5852da328a1b Mon Sep 17 00:00:00 2001 From: rexy712 Date: Mon, 23 May 2022 18:25:44 -0700 Subject: [PATCH] Enable header only build --- CMakeLists.txt | 57 +++++++++++++++++++++++------------- include/rexy/filerd.hpp | 12 ++++++++ include/rexy/rexy.hpp.in | 16 ++++++++-- include/rexy/string.hpp | 10 ++----- include/rexy/string_base.hpp | 7 ----- include/rexy/string_view.hpp | 17 +++++++++-- src/ensure.cpp | 9 ++++-- 7 files changed, 86 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5491d15..b8ed301 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ project(librexy) cmake_minimum_required(VERSION 3.0.2) include(GNUInstallDirs) +include(CMakeDependentOption) set(librexy_VERSION_STRING "000020000L") set(librexy_VERSION_MAJOR 0) @@ -10,37 +11,52 @@ set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include) include_directories(BEFORE SYSTEM "${INCLUDE_PATH}") -option(ENABLE_SHARED "Build shared library" ON) +cmake_dependent_option(ENABLE_SHARED "Build shared library" ON "NOT BUILD_HEADER_ONLY" OFF) option(ENABLE_PROFILING "Enable asan" OFF) option(BUILD_TESTS "Enable testing" OFF) +option(BUILD_HEADER_ONLY "Enable header only build" OFF) mark_as_advanced(ENABLE_PROFILING) -set(SOURCE_LIST "src/filerd.cpp" "src/string.cpp" "src/string_view.cpp" "src/threadpool.cpp" "src/demangle.cpp") -add_library(ensure OBJECT "src/ensure.cpp") -target_compile_options(ensure PRIVATE -Wall -Wextra -pedantic -std=c++20) -if(ENABLE_SHARED) - add_library(rexy SHARED ${SOURCE_LIST}) - set_target_properties(rexy PROPERTIES SOVERSION "${librexy_VERSION_MAJOR}.${librexy_VERSION_MINOR}") - set(LIBREXY_LIBFLAGS "-lrexy") - target_link_libraries(rexy "-lpthread") -else() - add_library(rexy STATIC ${SOURCE_LIST}) - set(LIBREXY_LIBFLAGS "-lrexy -lpthread") - target_link_libraries(rexy "-lpthread") -endif() -set_target_properties(rexy PROPERTIES VERSION "${librexy_VERSION_MAJOR}.${librexy_VERSION_MINOR}.${librexy_VERSION_REVISION}") +set(LIBREXY_PUBLIC_HEADERS "include/rexy/rexy.hpp" "include/rexy/algorithm.hpp" "include/rexy/utility.hpp" "include/rexy/basic_string_hash.hpp" "include/rexy/hash.hpp" "include/rexy/string_view_hash.hpp" "include/rexy/string_hash.hpp" "include/rexy/mpmc_queue.hpp" "include/rexy/mpmc_queue.tpp" "include/rexy/traits.hpp" "include/rexy/steal.hpp" "include/rexy/expression.hpp" "include/rexy/string_base.hpp" "include/rexy/string.hpp" "include/rexy/string_base.tpp" "include/rexy/allocator.hpp" "include/rexy/meta.hpp" "include/rexy/buffer.hpp" "include/rexy/buffer.tpp" "include/rexy/debug_print.hpp" "include/rexy/deferred.hpp" "include/rexy/enum_traits.hpp" "include/rexy/storage_for.hpp" "include/rexy/storage_for.tpp" "include/rexy/visitor.hpp" "include/rexy/string_view.hpp" "include/rexy/string_view.tpp") -if(ENABLE_PROFILING) - target_compile_options(rexy PRIVATE -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls) - target_link_options(rexy PRIVATE -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls) +if(BUILD_HEADER_ONLY) + set(LIBREXY_BUILT_LIBRARY_HEADERS "") + set(librexy_HEADER_ONLY_BUILD 1) + + add_library(rexy INTERFACE) + set(LIBREXY_LIBFLAGS "") +else() + set(LIBREXY_BUILT_LIBRARY_HEADERS "include/rexy/filerd.hpp" "include/rexy/threadpool.hpp" "include/rexy/demangle.hpp") + set(librexy_HEADER_ONLY_BUILD 0) + set(SOURCE_LIST "src/filerd.cpp" "src/string.cpp" "src/string_view.cpp" "src/threadpool.cpp" "src/demangle.cpp") + + if(ENABLE_SHARED) + add_library(rexy SHARED ${SOURCE_LIST}) + set_target_properties(rexy PROPERTIES SOVERSION "${librexy_VERSION_MAJOR}.${librexy_VERSION_MINOR}") + set(LIBREXY_LIBFLAGS "-lrexy") + target_link_libraries(rexy "-lpthread") + else() + add_library(rexy STATIC ${SOURCE_LIST}) + set(LIBREXY_LIBFLAGS "-lrexy -lpthread") + target_link_libraries(rexy "-lpthread") + endif() + set_target_properties(rexy PROPERTIES VERSION "${librexy_VERSION_MAJOR}.${librexy_VERSION_MINOR}.${librexy_VERSION_REVISION}") + + if(ENABLE_PROFILING) + target_compile_options(rexy PRIVATE -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls) + target_link_options(rexy PRIVATE -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls) + endif() + + target_compile_options(rexy PRIVATE -Wall -Wextra -pedantic -std=c++20) endif() + if(BUILD_TESTS) + add_library(ensure OBJECT "src/ensure.cpp") + target_compile_options(ensure PRIVATE -Wall -Wextra -pedantic -std=c++20) enable_testing() add_subdirectory(tests) endif() -set(LIBREXY_PUBLIC_HEADERS "include/rexy/rexy.hpp" "include/rexy/algorithm.hpp" "include/rexy/utility.hpp" "include/rexy/basic_string_hash.hpp" "include/rexy/hash.hpp" "include/rexy/string_view_hash.hpp" "include/rexy/string_hash.hpp" "include/rexy/mpmc_queue.hpp" "include/rexy/mpmc_queue.tpp" "include/rexy/traits.hpp" "include/rexy/steal.hpp" "include/rexy/expression.hpp" "include/rexy/string_base.hpp" "include/rexy/string.hpp" "include/rexy/filerd.hpp" "include/rexy/string_base.tpp" "include/rexy/allocator.hpp" "include/rexy/meta.hpp" "include/rexy/buffer.hpp" "include/rexy/buffer.tpp" "include/rexy/debug_print.hpp" "include/rexy/deferred.hpp" "include/rexy/demangle.hpp" "include/rexy/enum_traits.hpp" "include/rexy/storage_for.hpp" "include/rexy/storage_for.tpp" "include/rexy/visitor.hpp" "include/rexy/string_view.hpp" "include/rexy/string_view.tpp") -target_compile_options(rexy PRIVATE -Wall -Wextra -pedantic -std=c++20) install(TARGETS rexy ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -50,6 +66,7 @@ install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pc/librexy.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) install(FILES ${LIBREXY_PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/rexy/") +install(FILES ${LIBREXY_BUILT_LIBRARY_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/rexy/") install(DIRECTORY "include/rexy/detail" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/rexy" FILES_MATCHING PATTERN "*.hpp" PATTERN "*.tpp") install(DIRECTORY "include/rexy/cx" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/rexy" FILES_MATCHING PATTERN "*.hpp" PATTERN "*.tpp") install(DIRECTORY "include/rexy/compat" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/rexy" FILES_MATCHING PATTERN "*.hpp" PATTERN "*.tpp") diff --git a/include/rexy/filerd.hpp b/include/rexy/filerd.hpp index e196da1..162bbea 100644 --- a/include/rexy/filerd.hpp +++ b/include/rexy/filerd.hpp @@ -29,6 +29,8 @@ #include "rexy.hpp" #include "buffer.hpp" +#ifndef LIBREXY_HEADER_ONLY + namespace rexy{ //RAII wrapper for FILE* @@ -73,4 +75,14 @@ namespace rexy{ } +#else //LIBREXY_HEADER_ONLY + +namespace rexy{ + + static_assert(false, "rexy::filerd is not available when built with header only support"); + +} + +#endif //LIBREXY_HEADER_ONLY + #endif diff --git a/include/rexy/rexy.hpp.in b/include/rexy/rexy.hpp.in index 10a26c1..4ee2b85 100644 --- a/include/rexy/rexy.hpp.in +++ b/include/rexy/rexy.hpp.in @@ -1,6 +1,6 @@ /** This file is a part of rexy's general purpose library - Copyright (C) 2021 rexy712 + Copyright (C) 2021-2022 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,9 +16,19 @@ along with this program. If not, see . */ -#ifndef REXY_REXY_HPP -#define REXY_REXY_HPP +#ifndef REXY_CONFIG_REXY_HPP +#define REXY_CONFIG_REXY_HPP + +#define LIBREXY_BUILD_HEADER_ONLY @librexy_HEADER_ONLY_BUILD@ + +#if LIBREXY_BUILD_HEADER_ONLY + #define LIBREXY_HEADER_ONLY 1 +#endif #define LIBREXY_VERSION @librexy_VERSION_STRING@ +#define LIBREXY_VERSION_MAJOR @librexy_VERSION_MAJOR@ +#define LIBREXY_VERSION_MINOR @librexy_VERSION_MINOR@ +#define LIBREXY_VERSION_REVISION @librexy_VERSION_REVISION@ + #endif diff --git a/include/rexy/string.hpp b/include/rexy/string.hpp index 2bf3a10..b5f4398 100644 --- a/include/rexy/string.hpp +++ b/include/rexy/string.hpp @@ -28,18 +28,12 @@ namespace rexy{ //new allocated string using string = basic_string>; +#ifndef LIBREXY_HEADER_ONLY extern template class basic_string>; extern template class basic_string>; extern template class basic_string>; extern template class basic_string>; - - - using string_view = basic_string_view; - - extern template class basic_string_view; - extern template class basic_string_view; - extern template class basic_string_view; - extern template class basic_string_view; +#endif } diff --git a/include/rexy/string_base.hpp b/include/rexy/string_base.hpp index 1478321..7c50f5f 100644 --- a/include/rexy/string_base.hpp +++ b/include/rexy/string_base.hpp @@ -706,11 +706,4 @@ namespace{ } -#ifdef REXY_BINARY_BASE_HPP -#include "detail/binary_string_conv.hpp" -#endif -#ifdef REXY_HASH_HPP -#include "static_string_hash.hpp" -#endif - #endif diff --git a/include/rexy/string_view.hpp b/include/rexy/string_view.hpp index b4cddc9..a09622f 100644 --- a/include/rexy/string_view.hpp +++ b/include/rexy/string_view.hpp @@ -23,6 +23,7 @@ #include //reverse_iterator #include "compat/constexpr.hpp" +#include "rexy.hpp" namespace rexy{ @@ -101,8 +102,14 @@ namespace rexy{ template basic_string_view(const T*, size_t) -> basic_string_view; - template - using static_string [[deprecated]] = basic_string_view; + using string_view = basic_string_view; + +#ifndef LIBREXY_HEADER_ONLY + extern template class basic_string_view; + extern template class basic_string_view; + extern template class basic_string_view; + extern template class basic_string_view; +#endif } @@ -124,8 +131,14 @@ namespace{ std::ostream& operator<<(std::ostream& os, const rexy::basic_string_view& str){ return os << str.c_str(); } + } #include "string_view.tpp" + +#ifdef REXY_HASH_HPP + #include "string_view_hash.hpp" +#endif + #endif diff --git a/src/ensure.cpp b/src/ensure.cpp index c59fc53..86e0dcd 100644 --- a/src/ensure.cpp +++ b/src/ensure.cpp @@ -1,11 +1,11 @@ //Never actually used in the project. This just ensures that all syntax is correct during builds. +#include "rexy/rexy.hpp" #include "rexy/algorithm.hpp" #include "rexy/allocator.hpp" #include "rexy/buffer.hpp" #include "rexy/buffer.tpp" #include "rexy/expression.hpp" -#include "rexy/filerd.hpp" #include "rexy/hash.hpp" #include "rexy/mpmc_queue.hpp" #include "rexy/steal.hpp" @@ -18,13 +18,18 @@ #include "rexy/meta.hpp" #include "rexy/enum_traits.hpp" #include "rexy/deferred.hpp" -#include "rexy/demangle.hpp" #include "rexy/debug_print.hpp" #include "rexy/storage_for.hpp" #include "rexy/visitor.hpp" #include "rexy/string_view.hpp" #include "rexy/string_view.tpp" +#ifndef LIBREXY_HEADER_ONLY + #include "rexy/filerd.hpp" + #include "rexy/threadpool.hpp" + #include "rexy/demangle.hpp" +#endif + #include "rexy/detail/string_appender.hpp" #include "rexy/cx/array.hpp"