Skip to content

Commit

Permalink
All around cleanup, major CMake rework and install commands
Browse files Browse the repository at this point in the history
  • Loading branch information
deqyra committed Jul 7, 2024
1 parent 455a311 commit f6a4951
Show file tree
Hide file tree
Showing 53 changed files with 496 additions and 582 deletions.
30 changes: 11 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# #
################################################################################

cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.24)



################################################################################
# #
Expand All @@ -14,10 +16,6 @@ cmake_minimum_required(VERSION 3.11)

option( CPPTOOLS_SKIP_TESTS "Whether or not to skip tests" OFF )

if( WIN32 AND BUILD_SHARED_LIBS )
set( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
endif( )

set( CMAKE_EXPORT_COMPILE_COMMANDS ON )


Expand All @@ -31,8 +29,13 @@ set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
project( cpptools
DESCRIPTION "C++ tools developed for use in other projects"
LANGUAGES CXX
VERSION 1.0
)

message( VERBOSE " cpptools v${CMAKE_PROJECT_VERSION}" )
message( VERBOSE "----------------------------------" )
message( VERBOSE "https://github.com/deqyra/CppTools" )

set( CMAKE_CXX_STANDARD 23 )


Expand All @@ -48,6 +51,8 @@ cpptools_configure_debug_macros( CPPTOOLS ${CMAKE_CURRENT_SOURCE_DIR}/cpptools/_

add_subdirectory( cpptools )



################################################################################
# #
# Unit tests #
Expand All @@ -59,24 +64,11 @@ if( NOT CPPTOOLS_SKIP_TESTS )
add_subdirectory( tests )
endif( )

# Install targets
install(
TARGETS cpptools
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
)

install(
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tools"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN "*.hxx"
)

################################################################################
# #
# Unit tests #
# Clang format #
# #
################################################################################

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ Non-exhaustive summary of the cool stuff in there:
See [**`list.todo`**][todo] for a quick overview of what is likely to be worked
on at present.

[tree]: https://github.com/deqyra/CppTools/blob/master/cpptools/container
[ex]: https://github.com/deqyra/CppTools/blob/master/cpptools/exception/exception.hpp
[cli]: https://github.com/deqyra/CppTools/tree/master/cpptools/cli
[picross_cli]: https://github.com/deqyra/PicrossEngine/blob/master/main.cpp#L48
[shell]: https://github.com/deqyra/CppTools/tree/master/cpptools/cli/shell.hpp
[picross_shell]: https://github.com/deqyra/PicrossEngine/blob/master/picross_cli/cli_modify_grid_command.cpp#L41
[tree]: https://github.com/deqyra/CppTools/blob/master/cpptools/container
[ex]: https://github.com/deqyra/CppTools/blob/master/cpptools/exception/exception.hpp
[sine]: https://github.com/deqyra/CppTools/blob/master/cpptools/math/sine_generator.hpp
[interruptible]: https://github.com/deqyra/CppTools/blob/master/cpptools/thread/interfaces/interruptible.hpp
[worker]: https://github.com/deqyra/CppTools/blob/master/cpptools/thread/worker.hpp
[bitwise_enum_ops]: https://github.com/deqyra/CppTools/blob/master/cpptools/utility/bitwise_enum_ops.hpp
Expand Down
9 changes: 9 additions & 0 deletions cmake/cpptools-config.config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@PACKAGE_INIT@

include( "${CMAKE_CURRENT_LIST_DIR}/cpptools-targets.cmake" )

check_required_components( cpptools )

if( NOT TARGET cpptools::cpptools )
add_library( cpptools::cpptools ALIAS cpptools::cpptools_@CPPTOOLS_STATIC_OR_SHARED@ )
endif()
126 changes: 112 additions & 14 deletions cpptools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Build target
add_library( cpptools
include( GNUInstallDirs )
include( CMakePackageConfigHelpers )
set( INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cpptools/cmake" ) # this supports side-by-side multilib (x86 vs x64) setups for free so why not
set( CPPTOOLS_TEMPLATE_CONFIG_FILE "${CMAKE_CURRENT_LIST_DIR}/../cmake/cpptools-config.config.cmake" )
set( CPPTOOLS_OUTPUT_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/cpptools-config.cmake" )
set( CPPTOOLS_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/cpptools-config-version.cmake" )

# Compile library
add_library( cpptools_objects OBJECT
_internal/assume.hpp
_internal/debug_log.cpp
_internal/debug_log.hpp
_internal/debug_macros.hpp
_internal/undef_debug_macros.hpp
Expand Down Expand Up @@ -32,9 +38,6 @@ add_library( cpptools
exception/range_exception.hpp
exception/range_exception.hpp
math/sine_generator.hpp
oo/notifier.hpp
oo/interfaces/action_event_receiver.hpp
oo/interfaces/event_receiver.hpp
thread/worker.cpp
thread/worker.hpp
thread/interfaces/interruptible.hpp
Expand All @@ -50,15 +53,110 @@ add_library( cpptools
utility/to_string.hpp
)

if( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
target_compile_definitions( cpptools PUBLIC
CPPTOOLS_ENABLE_DEBUG_MASTER_SWITCH=1
)
set( CPPTOOLS_ENABLE_DEBUG $<CONFIG:Debug,RelWithDebInfo> )

target_include_directories( cpptools_objects
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..> # usage from source tree
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> # usage from install site
)

target_compile_definitions( cpptools_objects
PUBLIC CPPTOOLS_ENABLE_DEBUG_MASTER_SWITCH=${CPPTOOLS_ENABLE_DEBUG}
PRIVATE CPPTOOLS_DLL_EXPORT=1
)

target_compile_options( cpptools_objects
INTERFACE $<$<CXX_COMPILER_ID:MSVC>:"/wd4068;">
)

# Usage interface
add_library( cpptools_interface INTERFACE )

target_include_directories( cpptools_interface
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..> # usage from source tree
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> # usage from install site
)

target_compile_definitions( cpptools_interface
INTERFACE CPPTOOLS_ENABLE_DEBUG_MASTER_SWITCH=${CPPTOOLS_ENABLE_DEBUG}
)

target_compile_options( cpptools_interface
INTERFACE $<$<CXX_COMPILER_ID:MSVC>:"/wd4068;">
)

# Static library
add_library( cpptools_static STATIC
$<TARGET_OBJECTS:cpptools_objects>
)
target_link_libraries( cpptools_static
PUBLIC cpptools_interface
)

# Shared library
add_library( cpptools_shared SHARED
$<TARGET_OBJECTS:cpptools_objects>
)
target_link_libraries( cpptools_shared
PUBLIC cpptools_interface
)
target_compile_definitions( cpptools_shared
INTERFACE CPPTOOLS_DLL_IMPORT=1
)

# Install library
install(
TARGETS
cpptools_static
cpptools_shared
cpptools_interface
EXPORT cpptools-targets
LIBRARY DESTINATION "${CMAKE_INSTALL_BINDIR}/$<CONFIG>"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/$<CONFIG>"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/$<CONFIG>"
)

# Install headers
install(
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.config.hpp" EXCLUDE
PATTERN "_internal/config/" EXCLUDE
)

# Export targets
install( EXPORT cpptools-targets
NAMESPACE cpptools::
DESTINATION ${INSTALL_CMAKE_DIR}
)

# Package config
set( CPPTOOLS_STATIC_OR_SHARED static )
if ( ${BUILD_SHARED_LIBS} )
set( CPPTOOLS_STATIC_OR_SHARED shared )
endif( )

target_include_directories(
cpptools PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/..
# Configure config script
configure_package_config_file(
${CPPTOOLS_TEMPLATE_CONFIG_FILE} ${CPPTOOLS_OUTPUT_CONFIG_FILE}
INSTALL_DESTINATION ${INSTALL_CMAKE_DIR}
)

export( TARGETS cpptools )
# Versioning support
write_basic_package_version_file(
${CPPTOOLS_VERSION_FILE}
COMPATIBILITY ExactVersion
)

# Install package config
install(
FILES
${CPPTOOLS_VERSION_FILE}
${CPPTOOLS_OUTPUT_CONFIG_FILE}
DESTINATION
${INSTALL_CMAKE_DIR}
)
8 changes: 4 additions & 4 deletions cpptools/_internal/config/debug_macros.config.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <stdexcept>
#include <cstring>

#include <cpptools/exception/exception.hpp>

#include <cpptools/_internal/assume.hpp>
Expand Down Expand Up @@ -134,10 +131,13 @@
# define @CONFIGURE_DEBUG_PROJECT_MACRO@_NOEXCEPT_RELEASE noexcept(@CONFIGURE_DEBUG_PROJECT_MACRO@_LOCAL_DEBUG_MACRO == 0)
# define @CONFIGURE_DEBUG_PROJECT_MACRO@_NOEXCEPT_RELEASE_AND(cond) noexcept(@CONFIGURE_DEBUG_PROJECT_MACRO@_LOCAL_DEBUG_MACRO == 0 && (cond))
# endif
#else
# define @CONFIGURE_DEBUG_PROJECT_MACRO@_NOEXCEPT_RELEASE noexcept
# define @CONFIGURE_DEBUG_PROJECT_MACRO@_NOEXCEPT_RELEASE_AND(cond) noexcept(cond)
#endif

#if @CONFIGURE_DEBUG_PROJECT_MACRO@_LOCAL_DEBUG_MACRO != 0
# if @CONFIGURE_DEBUG_PROJECT_MACRO@_DEBUG_ENABLED == 0
# warning @CONFIGURE_DEBUG_PROJECT_MACRO@_LOCAL_DEBUG_MACRO is defined and non-zero but @CONFIGURE_DEBUG_PROJECT_MACRO@_DEBUG_ENABLED is not, debug assertions will NOT run
# endif
# endif
#endif
28 changes: 0 additions & 28 deletions cpptools/_internal/debug_log.cpp

This file was deleted.

16 changes: 13 additions & 3 deletions cpptools/_internal/debug_log.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#ifndef CPPTOOLS_INTERNAL_DEBUG_LOG_HPP
#define CPPTOOLS_INTERNAL_DEBUG_LOG_HPP

#include <map>
#include <array>
#include <iostream>
#include <string_view>

#include <cpptools/api.hpp>

namespace tools::internal::debug_log {

enum level : unsigned char {
Expand All @@ -13,9 +16,16 @@ enum level : unsigned char {
extra = 3
};

extern std::map<std::string_view, level> channel_levels;
inline constexpr std::array<std::string_view, 4> _level_names = {
"none",
"critical",
"pedantic",
"extra"
};

void log(level lv, std::string_view channel, std::string_view message);
inline void log(level lv, std::string_view channel, std::string_view message) {
std::cerr << '[' << _level_names[lv] << "][" << channel << "] " << message << std::endl;
}

} // namespace tools::internal::debug_log

Expand Down
5 changes: 5 additions & 0 deletions cpptools/_internal/force_enable_debug.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifdef CPPTOOLS_ENABLE_DEBUG_MASTER_SWITCH
# undef CPPTOOLS_ENABLE_DEBUG_MASTER_SWITCH
#endif

#define CPPTOOLS_ENABLE_DEBUG_MASTER_SWITCH 1
12 changes: 12 additions & 0 deletions cpptools/api.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef CPPTOOLS_API_HPP
#define CPPTOOLS_API_HPP

#if defined CPPTOOLS_DLL_IMPORT && defined(_WIN32)
# define CPPTOOLS_API __declspec(dllimport)
#elif defined CPPTOOLS_DLL_EXPORT && defined(_WIN32)
# define CPPTOOLS_API __declspec(dllexport)
#else
# define CPPTOOLS_API
#endif

#endif//CPPTOOLS_API_HPP
9 changes: 3 additions & 6 deletions cpptools/cli/command.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#include "command.hpp"

namespace tools::cli
{
namespace tools::cli {

std::string to_string(command_code c)
{
switch (c)
{
std::string to_string(command_code c) {
switch (c) {
case command_code::success:
return "success";
case command_code::failure:
Expand Down
4 changes: 3 additions & 1 deletion cpptools/cli/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <string>
#include <string_view>

#include <cpptools/api.hpp>

#include "streams.hpp"
#include "input.hpp"

Expand All @@ -14,7 +16,7 @@ enum class command_code {
failure = -1
};

std::string to_string(command_code c);
CPPTOOLS_API std::string to_string(command_code c);

template<typename Context>
class command {
Expand Down
Loading

0 comments on commit f6a4951

Please sign in to comment.