Skip to content

Commit 656f4a4

Browse files
committed
Some cmake fixes
- third_party back to previous version - updated readme and added components info
1 parent ddd7ae0 commit 656f4a4

6 files changed

Lines changed: 86 additions & 38 deletions

File tree

README.md

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
## About
44

5-
**mstd** (Maipa's Standard Library) is an extension of the C++ standard library, providing additional utility functions, new data types, and helpful templates for type comparisons. It aims to enhance the standard functionality with useful features while maintaining compatibility with modern C++. [DOCS](https://maipa01.github.io/mstd/html "Documentation")
5+
**mstd** (Maipa's Standard Library) is an extension of the C++ standard library, providing additional utility functions,
6+
new data types, and helpful templates for type comparisons. It aims to enhance the standard functionality with useful
7+
features while maintaining compatibility with modern C++. [DOCS](https://maipa01.github.io/mstd/html "Documentation")
68

79
## Requirements
810

9-
- **C++ Standard**: The library is designed for **C++20** and later.
11+
- **C++ Standard**: The library is designed for **C++17** and later.
1012
- **Supported Platforms**: The library is intended to work on **Windows, macOS, and Linux**.
1113

12-
1314
## Options
15+
1416
### Compilation defines options
17+
1518
You can enable option using `#define option_name` or use cmake `set(option_name ON CACHE BOOL)`
1619

1720
| Cmake option/C++ define Name | Description | Default |
@@ -24,13 +27,15 @@ You can enable option using `#define option_name` or use cmake `set(option_name
2427
| `MSTD_ENABLE_EXTRA_MACROS` | enables external macros | OFF |
2528

2629
### External libraries options
30+
2731
If you want to use external libraries not installed by project using CPM
2832

2933
| Cmake option Name | Description | Default |
3034
|:--------------------|:--------------------------------------------------------------------------------------|:-------:|
3135
| `MSTD_FMT_EXTERNAL` | Enable if you want to use own fmt library (tested and compatible fmt version: 12.1.0) | OFF |
3236

3337
### Project developing options
38+
3439
These options are used while testing or changing code in project
3540

3641
| Cmake option Name | Description | Default |
@@ -47,45 +52,67 @@ These options are used while testing or changing code in project
4752
- **Extended String Manipulation**: Additional functions for modifying and handling strings.
4853
- **Terminal Utilities**: Functions for clearing the terminal and retrieving its dimensions.
4954
- **New Data Structures**:
50-
- `ordered_map`: A map that preserves the insertion order, similar to `vector`.
51-
- `ordered_set`: A set that maintains insertion order, like `vector`.
52-
- `stable_vector`: A vector with stable indexes
55+
- `ordered_map`: A map that preserves the insertion order, similar to `vector`.
56+
- `ordered_set`: A set that maintains insertion order, like `vector`.
57+
- `stable_vector`: A vector with stable indexes
5358
- **Safe Arithmetic Operations**: Functions for performing arithmetic with overflow detection:
54-
- `add_overflow`
55-
- `sub_overflow`
56-
- `mul_overflow`
57-
- `div_overflow`
58-
- **Type Comparisons for Functions**: Templates that allow comparing function types, treating lambdas and function pointers as equivalent when they share the same signature.
59-
- **Managment Utilities**:
60-
- `flags`: A class which represents multiple values of given flag-like enum
61-
- `id_manager`: Manager which helps with managing ids
62-
- `assert`: Macros for easy defining your own assert
59+
- `add_overflow`
60+
- `sub_overflow`
61+
- `mul_overflow`
62+
- `div_overflow`
63+
- **Type Comparisons for Functions**: Templates that allow comparing function types, treating lambdas and function
64+
pointers as equivalent when they share the same signature.
65+
- **Management Utilities**:
66+
- `flags`: A class which represents multiple values of given flag-like enum
67+
- `id_manager`: Manager which helps with managing ids
68+
- `assert`: Macros for easy defining your own assert
6369
- **Events**:
64-
- `events_handler`: Event handler
70+
- `events_handler`: Event handler
71+
72+
## Installation
73+
74+
After installing, you can use `find_package(mstd)`.
75+
76+
### Components
77+
78+
You can also include components `find_pcakage(mstd COMPONENTS comp)`. They work the same way as [Compilation defines options](#compilation-defines-options), but
79+
they provide separate components you need to include.
80+
81+
| Component Name | Option | Target Name |
82+
|:---------------------|:---------------------------------|:---------------------------|
83+
| CXX20 | `MSTD_ENABLE_CXX20` | mstd::CXX20 |
84+
| NO_ASSERT_ON_RELEASE | `MSTD_DISABLE_ASSERT_ON_RELEASE` | mstd::NO_ASSERT_ON_RELEASE |
85+
| FOR_EACH_MACROS | `MSTD_ENABLE_FOR_EACH_MACROS` | mstd::FOR_EACH_MACROS |
86+
| ENUMS_MACROS | `MSTD_ENABLE_ENUMS_MACROS` | mstd::ENUMS_MACROS |
87+
| CLONE_FUNC_MACROS | `MSTD_ENABLE_CLONE_FUNC_MACROS` | mstd::CLONE_FUNC_MACROS |
88+
| EXTRA_MACROS | `MSTD_ENABLE_EXTRA_MACROS` | mstd::EXTRA_MACROS |
6589

6690
## Macros
6791

68-
Before including the `mstd.hpp` or `macros.hpp` header, you can define certain macros to enable specific sets of utility functions and features within the library.
92+
Before including the `mstd.hpp` or `macros.hpp` header, you can define certain macros to enable specific sets of utility
93+
functions and features within the library.
6994

7095
### Available Macros:
7196

72-
- **USE_FOR_EACH_MACROS**: This macro enables access to the `DO_FOR_EACH` macro, which allows you to iterate over multiple elements and apply a function to each element.
97+
- **MSTD_ENABLE_FOR_EACH_MACROS**: This macro enables access to the `DO_FOR_EACH` macro, which allows you to iterate over
98+
multiple elements and apply a function to each element.
7399

74100
Example usage:
75101
```cpp
76-
#define USE_FOR_EACH_MACROS
102+
#define MSTD_ENABLE_FOR_EACH_MACROS
77103
#include <mstd/mstd.hpp>
78104

79105
#define TO_STR(x) #x
80106
// Example of DO_FOR_EACH with TO_STR macro
81107
DO_FOR_EACH(TO_STR, 1, 2, 3); // Outputs: "1" "2" "3"
82108
```
83109
84-
- **USE_ENUMS_MACROS**: This macro enables access to the `ENUM` macro, which allows you to define enums or enum classes along with helper functions such as `to_string()` and `size<Enum>()`.
110+
- **MSTD_ENABLE_ENUMS_MACROS**: This macro enables access to the `ENUM` macro, which allows you to define enums or enum classes
111+
along with helper functions such as `to_string()` and `size<Enum>()`.
85112
86113
Example usage:
87114
```cpp
88-
#define USE_ENUMS_MACROS
115+
#define MSTD_ENABLE_ENUMS_MACROS
89116
#include <mstd/mstd.hpp>
90117
91118
// Defining an enum using ENUM macro
@@ -96,11 +123,13 @@ Before including the `mstd.hpp` or `macros.hpp` header, you can define certain m
96123
std::cout << size<Color>() << std::endl; // Outputs: 3 (the number of elements in the enum)
97124
```
98125

99-
- **USE_CLONE_FUNC_MACROS**: This macro enables access to macros that help you define basic cloning functions like `Clone()` and `CloneTo()` for your custom classes. Specifically, it uses the `CloneFuncInClassDefinition` macro to automatically generate the `Clone()` function that returns a pointer to a cloned object.
126+
- **MSTD_ENABLE_CLONE_FUNC_MACROS**: This macro enables access to macros that help you define basic cloning functions like
127+
`Clone()` and `CloneTo()` for your custom classes. Specifically, it uses the `CloneFuncInClassDefinition` macro to
128+
automatically generate the `Clone()` function that returns a pointer to a cloned object.
100129

101130
Example usage:
102131
```cpp
103-
#define USE_CLONE_FUNC_MACROS
132+
#define MSTD_ENABLE_CLONE_FUNC_MACROS
104133
#include <mstd/mstd.hpp>
105134

106135
// Example of a class with Clone() function returning a pointer using CloneFuncInClassDefinition macro
@@ -121,9 +150,9 @@ Before including the `mstd.hpp` or `macros.hpp` header, you can define certain m
121150
To enable these macros, define them before including `mstd.hpp`:
122151
123152
```cpp
124-
#define USE_FOR_EACH_MACROS
125-
#define USE_ENUMS_MACROS
126-
#define USE_CLONE_FUNC_MACROS
153+
#define MSTD_ENABLE_FOR_EACH_MACROS
154+
#define MSTD_ENABLE_ENUMS_MACROS
155+
#define MSTD_ENABLE_CLONE_FUNC_MACROS
127156
#include <mstd/mstd.hpp>
128157
```
129158

@@ -192,4 +221,5 @@ int main() {
192221

193222
## License
194223

195-
This project is licensed under the **BSD 3-Clause License with Attribution Requirement**. See the [`LICENSE`](./LICENSE) file for more details.
224+
This project is licensed under the **BSD 3-Clause License with Attribution Requirement**. See the [LICENSE](./LICENSE "License")
225+
file for more details.

cmake/get_cpm.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
set(CPM_USE_LOCAL_PACKAGES OFF)
22
# Storage location
3-
set(CPM_SOURCE_CACHE ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
3+
if(NOT CPM_SOURCE_CACHE)
4+
set(CPM_SOURCE_CACHE ${CMAKE_SOURCE_DIR}/third_party)
5+
endif()
46

57
# Set download location
6-
set(CPM_DOWNLOAD_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cpm/CPM.cmake")
8+
if(NOT CPM_DOWNLOAD_LOCATION)
9+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_SOURCE_DIR}/third_party/cpm/CPM.cmake")
10+
endif()
711

812
# download CPM.cmake
913
# Expand relative path. This is important if the provided path contains a tilde (~)

cmake/mstdConfig.cmake.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ endif()
1212
set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
1313
set(@PROJECT_NAME@_PCH_PATH "${@PROJECT_NAME@_INCLUDE_DIR}/@PROJECT_NAME@/pch.hpp")
1414

15-
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake)
15+
if(NOT TARGET @PROJECT_NAMESPACE@@PROJECT_NAME@)
16+
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake)
17+
endif()
1618

1719
set(@PROJECT_NAME@_components CXX20 NO_ASSERT_ON_RELEASE FOR_EACH_MACROS ENUMS_MACROS CLONE_FUNC_MACROS EXTRA_MACROS)
1820

cmake/third_party.cmake

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
if(NOT MSTD_FMT_EXTERNAL OR MSTD_BUILD_TESTS OR MSTD_BUILD_COVERAGE)
1+
if(NOT MSTD_FMT_EXTERNAL AND NOT TARGET fmt::fmt)
2+
set(DOWNLOAD_FMT ON)
3+
else()
4+
set(DOWNLOAD_FMT OFF)
5+
endif()
6+
7+
if ((MSTD_BUILD_TESTS OR MSTD_BUILD_COVERAGE) AND NOT TARGET gtest_main)
8+
set(DOWNLOAD_GTEST ON)
9+
else()
10+
set(DOWNLOAD_GTEST OFF)
11+
endif()
12+
13+
if(DOWNLOAD_FMT OR DOWNLOAD_GTEST)
214
include(${CMAKE_CURRENT_LIST_DIR}/get_cpm.cmake)
315
endif()
416

517
# FMT
6-
if(NOT MSTD_FMT_EXTERNAL)
18+
if(DOWNLOAD_FMT)
719
CPMAddPackage("gh:fmtlib/fmt#12.1.0")
820
endif()
921

1022
# GOOGLE TESTS
11-
if(MSTD_BUILD_TESTS OR MSTD_BUILD_COVERAGE)
23+
if(DOWNLOAD_GTEST)
1224
CPMAddPackage("gh:google/googletest#v1.17.0")
1325
endif()

mstd/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ target_precompile_headers(${PROJECT_NAME} INTERFACE "$<BUILD_INTERFACE:${BUILD_H
4444
"$<INSTALL_INTERFACE:${${PROJECT_NAME}_PCH_PATH}>"
4545
)
4646

47-
target_compile_features(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:$<IF:$<BOOL:${MSTD_ENABLE_CXX20}>, cxx_std_20, cxx_std_17>>
48-
$<INSTALL_INTERFACE:cxx_std_17>
49-
)
47+
target_compile_features(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:$<IF:$<BOOL:${MSTD_ENABLE_CXX20}>, cxx_std_20, cxx_std_17>>)
5048

5149
# region LINK_LIBRARIES
5250
if(NOT TARGET ${PROJECT_NAMESPACE}fmt_imported)
@@ -59,7 +57,9 @@ target_link_libraries(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:fmt::fmt>
5957
# endregion
6058

6159
# set headers folder
62-
target_include_directories(${PROJECT_NAME} INTERFACE "$<BUILD_INTERFACE:${BUILD_HEADERS_PATHS}>")
60+
target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE "$<BUILD_INTERFACE:${BUILD_HEADERS_PATHS}>"
61+
$<INSTALL_INTERFACE:${INSTALL_HEADERS_PATH}>
62+
)
6363

6464
# region COMPILE_DEFINITIONS
6565
target_compile_definitions(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:

mstd/include/main/mstd/config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#pragma endregion
2929

3030
#pragma region LAST_UPDATE
31-
#define MSTD_LAST_UPDATE_DAY 15
31+
#define MSTD_LAST_UPDATE_DAY 16
3232
#define MSTD_LAST_UPDATE_MONTH 04
3333
#define MSTD_LAST_UPDATE_YEAR 2026
3434

0 commit comments

Comments
 (0)