Skip to content

Commit 541db76

Browse files
authored
Merge branch 'main' into msvc
2 parents 9a39aa8 + ac3576b commit 541db76

11 files changed

Lines changed: 249 additions & 146 deletions

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ project_options(
3737
ENABLE_CLANG_TIDY
3838
ENABLE_VS_ANALYSIS
3939
# ENABLE_CONAN
40-
# ENABLE_IPO
40+
# ENABLE_INTERPROCEDURAL_OPTIMIZATION
41+
# ENABLE_NATIVE_OPTIMIZATION
4142
# ENABLE_DOXYGEN
4243
# ENABLE_COVERAGE
4344
# ENABLE_SANITIZER_ADDRESS
@@ -158,7 +159,8 @@ It accepts the following named flags:
158159
- `ENABLE_CLANG_TIDY`: Enable static analysis with clang-tidy
159160
- `ENABLE_VS_ANALYSIS`: Enable Visual Studio IDE code analysis if the generator is Visual Studio.
160161
- `ENABLE_CONAN`: Use Conan for dependency management
161-
- `ENABLE_IPO`: Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build
162+
- `ENABLE_INTERPROCEDURAL_OPTIMIZATION`: Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build
163+
- `ENABLE_NATIVE_OPTIMIZATION`: Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.).
162164
- `ENABLE_COVERAGE`: Enable coverage reporting for gcc/clang
163165
- `ENABLE_DOXYGEN`: Enable Doxygen documentation. The added `doxygen-docs` target can be built via `cmake --build ./build --target doxygen-docs`.
164166
- `WARNINGS_AS_ERRORS`: Treat compiler and static code analyzer warnings as errors. This also affects CMake warnings related to those.
@@ -316,3 +318,7 @@ dynamic_project_options(
316318
Add your executables, etc., as described above.
317319

318320
</details>
321+
322+
# License
323+
324+
This project can be used under the terms of either the [MIT license](./LICENSE.txt) or the [Unlicense](./Unlicense.txt) depending on your choice (as you wish). Both are permissive open-source licenses that allow any usage, commercial or non-commercial, copying, distribution, publishing, modification, etc. Feel free to choose whichever is more suitable for you.

Unlicense.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

src/CompilerWarnings.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,15 @@ function(
9999
# TODO support Intel compiler
100100
endif()
101101

102-
# use the same warning flags for C
102+
# Add C warnings
103103
set(PROJECT_WARNINGS_C "${PROJECT_WARNINGS_CXX}")
104+
list(
105+
REMOVE_ITEM
106+
PROJECT_WARNINGS_C
107+
-Wnon-virtual-dtor
108+
-Wold-style-cast
109+
-Woverloaded-virtual
110+
-Wuseless-cast)
104111

105112
set(PROJECT_WARNINGS_CUDA "${CUDA_WARNINGS}")
106113

src/DynamicProjectOptions.cmake

Lines changed: 116 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -19,128 +19,129 @@
1919
# set(<feature_name>_DEVELOPER_DEFAULT <value>) - set default for developer mode
2020
# set(<feature_name>_USER_DEFAULT <value>) - set default for user mode
2121

22-
option(ENABLE_DEVELOPER_MODE "Set up defaults for a developer of the project, and let developer change options" OFF)
23-
if(NOT ${ENABLE_DEVELOPER_MODE})
24-
message(
25-
STATUS
26-
"Developer mode is OFF. For developement, use `-DENABLE_DEVELOPER_MODE:BOOL=ON`. Building the project for the end-user..."
27-
)
28-
else()
29-
message(
30-
STATUS
31-
"Developer mode is ON. For production, use `-DENABLE_DEVELOPER_MODE:BOOL=OFF`. Building the project for the developer..."
32-
)
33-
endif()
34-
35-
if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND NOT WIN32)
36-
set(SUPPORTS_UBSAN ON)
37-
else()
38-
set(SUPPORTS_UBSAN OFF)
39-
endif()
40-
41-
if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND WIN32)
42-
set(SUPPORTS_ASAN OFF)
43-
else()
44-
set(SUPPORTS_ASAN ON)
45-
endif()
46-
47-
# ccache, clang-tidy, cppcheck are only supported with Ninja and Makefile based generators
48-
# note that it is possible to use Ninja with cl, so this still allows clang-tidy on Windows
49-
# with CL.
50-
#
51-
# We are only setting the default options here. If the user attempts to enable
52-
# these tools on a platform with unknown support, they are on their own.
53-
#
54-
# Also note, cppcheck has an option to be run on VCproj files, so we should investigate that
55-
# Further note: MSVC2022 has builtin support for clang-tidy, but I can find
56-
# no way to enable that via CMake
57-
if(CMAKE_GENERATOR MATCHES ".*Makefile*." OR CMAKE_GENERATOR MATCHES ".*Ninja*")
58-
set(MAKEFILE_OR_NINJA ON)
59-
else()
60-
set(MAKEFILE_OR_NINJA OFF)
61-
endif()
62-
63-
include(CMakeDependentOption)
64-
65-
# <option name>;<user mode default>;<developer mode default>;<description>
66-
set(options
67-
"ENABLE_CACHE\;${MAKEFILE_OR_NINJA}\;${MAKEFILE_OR_NINJA}\;Enable ccache on Unix"
68-
"WARNINGS_AS_ERRORS\;OFF\;ON\;Treat warnings as Errors"
69-
"ENABLE_CLANG_TIDY\;OFF\;${MAKEFILE_OR_NINJA}\;Enable clang-tidy analysis during compilation"
70-
"ENABLE_VS_ANALYSIS\;ON\;ON\;Enable Visual Studio IDE code analysis if the generator is Visual Studio."
71-
"ENABLE_CONAN\;OFF\;OFF\;Automatically integrate Conan for package management"
72-
"ENABLE_COVERAGE\;OFF\;OFF\;Analyze and report on coverage"
73-
"ENABLE_SANITIZER_ADDRESS\;OFF\;${SUPPORTS_ASAN}\;Make memory errors into hard runtime errors (windows/linux/macos)"
74-
"ENABLE_SANITIZER_UNDEFINED_BEHAVIOR\;OFF\;${SUPPORTS_UBSAN}\;Make certain types (numeric mostly) of undefined behavior into runtime errors"
75-
"ENABLE_CPPCHECK\;OFF\;${MAKEFILE_OR_NINJA}\;Enable cppcheck analysis during compilation"
76-
"ENABLE_IPO\;OFF\;OFF\;Enable whole-program optimization"
77-
"ENABLE_INCLUDE_WHAT_YOU_USE\;OFF\;OFF\;Enable include-what-you-use analysis during compilation"
78-
"ENABLE_PCH\;OFF\;OFF\;Enable pre-compiled-headers support"
79-
"ENABLE_DOXYGEN\;OFF\;OFF\;Build documentation with Doxygen"
80-
"ENABLE_USER_LINKER\;OFF\;OFF\;Allow custom linker settings"
81-
"ENABLE_BUILD_WITH_TIME_TRACE\;OFF\;OFF\;Generates report of where compile-time is spent"
82-
"ENABLE_UNITY\;OFF\;OFF\;Merge C++ files into larger C++ files, can speed up compilation sometimes"
83-
"ENABLE_SANITIZER_LEAK\;OFF\;OFF\;Make memory leaks into hard runtime errors"
84-
"ENABLE_SANITIZER_THREAD\;OFF\;OFF\;Make thread race conditions into hard runtime errors"
85-
"ENABLE_SANITIZER_MEMORY\;OFF\;OFF\;Make other memory errors into runtime errors")
86-
87-
foreach(option ${options})
88-
list(
89-
GET
90-
option
91-
0
92-
option_name)
93-
list(
94-
GET
95-
option
96-
1
97-
option_user_default)
98-
list(
99-
GET
100-
option
101-
2
102-
option_developer_default)
103-
list(
104-
GET
105-
option
106-
3
107-
option_description)
108-
109-
if(DEFINED ${option_name}_DEFAULT)
110-
if(DEFINED ${option_name}_DEVELOPER_DEFAULT OR DEFINED ${option_name}_USER_DEFAULT)
111-
message(
112-
SEND_ERROR
113-
"You have separately defined user/developer defaults and general defaults for ${option_name}. Please either provide a general default OR separate developer/user overrides"
114-
)
115-
endif()
116-
117-
set(option_user_default ${${option_name}_DEFAULT})
118-
set(option_developer_default ${${option_name}_DEFAULT})
22+
macro(dynamic_project_options)
23+
option(ENABLE_DEVELOPER_MODE "Set up defaults for a developer of the project, and let developer change options" OFF)
24+
if(NOT ${ENABLE_DEVELOPER_MODE})
25+
message(
26+
STATUS
27+
"Developer mode is OFF. For developement, use `-DENABLE_DEVELOPER_MODE:BOOL=ON`. Building the project for the end-user..."
28+
)
29+
else()
30+
message(
31+
STATUS
32+
"Developer mode is ON. For production, use `-DENABLE_DEVELOPER_MODE:BOOL=OFF`. Building the project for the developer..."
33+
)
11934
endif()
12035

121-
if(DEFINED ${option_name}_USER_DEFAULT)
122-
set(option_user_default ${${option_name}_USER_DEFAULT})
36+
if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND NOT WIN32)
37+
set(SUPPORTS_UBSAN ON)
38+
else()
39+
set(SUPPORTS_UBSAN OFF)
12340
endif()
12441

125-
if(DEFINED ${option_name}_DEVELOPER_DEFAULT)
126-
set(option_developer_default ${${option_name}_DEVELOPER_DEFAULT})
42+
if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND WIN32)
43+
set(SUPPORTS_ASAN OFF)
44+
else()
45+
set(SUPPORTS_ASAN ON)
12746
endif()
12847

129-
cmake_dependent_option(
130-
OPT_${option_name}
131-
"${option_description}"
132-
${option_developer_default}
133-
ENABLE_DEVELOPER_MODE
134-
${option_user_default})
135-
136-
if(OPT_${option_name})
137-
set(${option_name}_VALUE ${option_name})
48+
# ccache, clang-tidy, cppcheck are only supported with Ninja and Makefile based generators
49+
# note that it is possible to use Ninja with cl, so this still allows clang-tidy on Windows
50+
# with CL.
51+
#
52+
# We are only setting the default options here. If the user attempts to enable
53+
# these tools on a platform with unknown support, they are on their own.
54+
#
55+
# Also note, cppcheck has an option to be run on VCproj files, so we should investigate that
56+
# Further note: MSVC2022 has builtin support for clang-tidy, but I can find
57+
# no way to enable that via CMake
58+
if(CMAKE_GENERATOR MATCHES ".*Makefile*." OR CMAKE_GENERATOR MATCHES ".*Ninja*")
59+
set(MAKEFILE_OR_NINJA ON)
13860
else()
139-
unset(${option_name}_VALUE)
61+
set(MAKEFILE_OR_NINJA OFF)
14062
endif()
141-
endforeach()
14263

143-
macro(dynamic_project_options)
64+
include(CMakeDependentOption)
65+
66+
# <option name>;<user mode default>;<developer mode default>;<description>
67+
set(options
68+
"ENABLE_CACHE\;${MAKEFILE_OR_NINJA}\;${MAKEFILE_OR_NINJA}\;Enable ccache on Unix"
69+
"WARNINGS_AS_ERRORS\;OFF\;ON\;Treat warnings as Errors"
70+
"ENABLE_CLANG_TIDY\;OFF\;${MAKEFILE_OR_NINJA}\;Enable clang-tidy analysis during compilation"
71+
"ENABLE_VS_ANALYSIS\;ON\;ON\;Enable Visual Studio IDE code analysis if the generator is Visual Studio."
72+
"ENABLE_CONAN\;OFF\;OFF\;Automatically integrate Conan for package management"
73+
"ENABLE_COVERAGE\;OFF\;OFF\;Analyze and report on coverage"
74+
"ENABLE_SANITIZER_ADDRESS\;OFF\;${SUPPORTS_ASAN}\;Make memory errors into hard runtime errors (windows/linux/macos)"
75+
"ENABLE_SANITIZER_UNDEFINED_BEHAVIOR\;OFF\;${SUPPORTS_UBSAN}\;Make certain types (numeric mostly) of undefined behavior into runtime errors"
76+
"ENABLE_CPPCHECK\;OFF\;${MAKEFILE_OR_NINJA}\;Enable cppcheck analysis during compilation"
77+
"ENABLE_INTERPROCEDURAL_OPTIMIZATION\;OFF\;OFF\;Enable whole-program optimization (e.g. LTO)"
78+
"ENABLE_NATIVE_OPTIMIZATION\;OFF\;OFF\;Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.)."
79+
"ENABLE_INCLUDE_WHAT_YOU_USE\;OFF\;OFF\;Enable include-what-you-use analysis during compilation"
80+
"ENABLE_PCH\;OFF\;OFF\;Enable pre-compiled-headers support"
81+
"ENABLE_DOXYGEN\;OFF\;OFF\;Build documentation with Doxygen"
82+
"ENABLE_USER_LINKER\;OFF\;OFF\;Allow custom linker settings"
83+
"ENABLE_BUILD_WITH_TIME_TRACE\;OFF\;OFF\;Generates report of where compile-time is spent"
84+
"ENABLE_UNITY\;OFF\;OFF\;Merge C++ files into larger C++ files, can speed up compilation sometimes"
85+
"ENABLE_SANITIZER_LEAK\;OFF\;OFF\;Make memory leaks into hard runtime errors"
86+
"ENABLE_SANITIZER_THREAD\;OFF\;OFF\;Make thread race conditions into hard runtime errors"
87+
"ENABLE_SANITIZER_MEMORY\;OFF\;OFF\;Make other memory errors into runtime errors")
88+
89+
foreach(option ${options})
90+
list(
91+
GET
92+
option
93+
0
94+
option_name)
95+
list(
96+
GET
97+
option
98+
1
99+
option_user_default)
100+
list(
101+
GET
102+
option
103+
2
104+
option_developer_default)
105+
list(
106+
GET
107+
option
108+
3
109+
option_description)
110+
111+
if(DEFINED ${option_name}_DEFAULT)
112+
if(DEFINED ${option_name}_DEVELOPER_DEFAULT OR DEFINED ${option_name}_USER_DEFAULT)
113+
message(
114+
SEND_ERROR
115+
"You have separately defined user/developer defaults and general defaults for ${option_name}. Please either provide a general default OR separate developer/user overrides"
116+
)
117+
endif()
118+
119+
set(option_user_default ${${option_name}_DEFAULT})
120+
set(option_developer_default ${${option_name}_DEFAULT})
121+
endif()
122+
123+
if(DEFINED ${option_name}_USER_DEFAULT)
124+
set(option_user_default ${${option_name}_USER_DEFAULT})
125+
endif()
126+
127+
if(DEFINED ${option_name}_DEVELOPER_DEFAULT)
128+
set(option_developer_default ${${option_name}_DEVELOPER_DEFAULT})
129+
endif()
130+
131+
cmake_dependent_option(
132+
OPT_${option_name}
133+
"${option_description}"
134+
${option_developer_default}
135+
ENABLE_DEVELOPER_MODE
136+
${option_user_default})
137+
138+
if(OPT_${option_name})
139+
set(${option_name}_VALUE ${option_name})
140+
else()
141+
unset(${option_name}_VALUE)
142+
endif()
143+
endforeach()
144+
144145
project_options(
145146
${ENABLE_CONAN_VALUE}
146147
${ENABLE_CACHE_VALUE}
@@ -149,7 +150,8 @@ macro(dynamic_project_options)
149150
${ENABLE_CLANG_TIDY_VALUE}
150151
${ENABLE_VS_ANALYSIS_VALUE}
151152
${ENABLE_COVERAGE_VALUE}
152-
${ENABLE_IPO_VALUE}
153+
${ENABLE_INTERPROCEDURAL_OPTIMIZATION_VALUE}
154+
${ENABLE_NATIVE_OPTIMIZATION_VALUE}
153155
${ENABLE_INCLUDE_WHAT_YOU_USE_VALUE}
154156
${ENABLE_PCH_VALUE}
155157
${ENABLE_DOXYGEN_VALUE}

src/Index.cmake

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ include("${ProjectOptions_SRC_DIR}/PackageProject.cmake")
2727
# - ENABLE_CONAN: Use Conan for dependency management
2828
# - ENABLE_DOXYGEN: Enable doxygen doc builds of source
2929
# - DOXYGEN_THEME: the name of the Doxygen theme to use. Supported themes: `awesome-sidebar` (default), `awesome` and `original`.
30-
# - ENABLE_IPO: Enable Interprocedural Optimization, aka Link Time Optimization (LTO)
30+
# - ENABLE_INTERPROCEDURAL_OPTIMIZATION: Enable Interprocedural Optimization, aka Link Time Optimization (LTO)
31+
# - ENABLE_NATIVE_OPTIMIZATION: Enable the optimizations specific to the build machine (e.g. SSE4_1, AVX2, etc.).
3132
# - ENABLE_USER_LINKER: Enable a specific linker if available
3233
# - ENABLE_BUILD_WITH_TIME_TRACE: Enable -ftime-trace to generate time tracing .json files on clang
3334
# - ENABLE_UNITY: Enable Unity builds of projects
@@ -57,7 +58,8 @@ macro(project_options)
5758
ENABLE_CONAN
5859
ENABLE_VCPKG
5960
ENABLE_DOXYGEN
60-
ENABLE_IPO
61+
ENABLE_INTERPROCEDURAL_OPTIMIZATION
62+
ENABLE_NATIVE_OPTIMIZATION
6163
ENABLE_USER_LINKER
6264
ENABLE_BUILD_WITH_TIME_TRACE
6365
ENABLE_UNITY
@@ -91,10 +93,21 @@ macro(project_options)
9193
endif()
9294

9395
include("${ProjectOptions_SRC_DIR}/StandardProjectSettings.cmake")
96+
include("${ProjectOptions_SRC_DIR}/Optimization.cmake")
97+
98+
if(NOT
99+
"${ProjectOptions_IPO}"
100+
STREQUAL
101+
"")
102+
message(WARNING "Deprecation: Use ENABLE_INTERPROCEDURAL_OPTIMIZATION instead of ENABLE_IPO")
103+
set(ProjectOptions_ENABLE_INTERPROCEDURAL_OPTIMIZATION ${ProjectOptions_IPO})
104+
endif()
105+
if(${ProjectOptions_ENABLE_INTERPROCEDURAL_OPTIMIZATION})
106+
enable_interprocedural_optimization()
107+
endif()
94108

95-
if(${ProjectOptions_ENABLE_IPO})
96-
include("${ProjectOptions_SRC_DIR}/InterproceduralOptimization.cmake")
97-
enable_ipo()
109+
if(${ProjectOptions_ENABLE_NATIVE_OPTIMIZATION})
110+
enable_native_optimization()
98111
endif()
99112

100113
# Link this 'library' to set the c++ standard / compile-time options requested

src/InterproceduralOptimization.cmake

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)