-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix downstream issues with cmake and minor folder renames
Signed-off-by: Ian <[email protected]>
- Loading branch information
Showing
89 changed files
with
555 additions
and
5,209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,227 +1,179 @@ | ||
cmake_minimum_required(VERSION 3.18.0) | ||
|
||
|
||
# ---------------------------------------------------------------------- | ||
# Project Setup and Metadata | ||
# ---------------------------------------------------------------------- | ||
set(CCMATH_TARGET_NAME "ccmath") | ||
set(CCMATH_BUILD_VERSION 0.2.0) | ||
|
||
project( | ||
ccmath | ||
${CCMATH_TARGET_NAME} | ||
VERSION ${CCMATH_BUILD_VERSION} | ||
DESCRIPTION "A C++17 Compile Time <cmath> Library" | ||
HOMEPAGE_URL "https://github.com/Rinzii/ccmath" | ||
LANGUAGES CXX | ||
) | ||
|
||
# Determine if this is the root project or a subproject. | ||
set(is_root_project OFF) | ||
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) | ||
set(is_root_project ON) | ||
endif () | ||
if (NOT CCMATH_SOURCE_DIR) | ||
set(CCMATH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
# Include helper CMake files for project configuration | ||
include(cmake/config/ProjectIsTopLevel.cmake) | ||
include(cmake/config/ProjectOptions.cmake) | ||
|
||
|
||
# ---------------------------------------------------------------------- | ||
# Color Diagnostics (Only if at top-level with Ninja) | ||
# ---------------------------------------------------------------------- | ||
if (CCMATH_PROJECT_IS_TOP_LEVEL) | ||
if (CMAKE_GENERATOR STREQUAL "Ninja") | ||
# Enable colored output for C++ compilers | ||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") | ||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") | ||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics") | ||
endif () | ||
# Enable colored output for C compilers | ||
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") | ||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always") | ||
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") | ||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics") | ||
endif () | ||
endif () | ||
endif () | ||
|
||
# TODO: Possibly change this to instead use cmakes more modern target_compile_features | ||
# TODO: Changing this to use target_compile_features will require adjustments of the CI | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
message(STATUS "CCMath: Version: ${PROJECT_VERSION}") | ||
|
||
# | ||
# User-facing options | ||
# | ||
include(cmake/config/UserOptions.cmake) # To see the options, look at this file | ||
|
||
add_library(ccmath-compile-options INTERFACE) | ||
add_library(ccmath::ccmath-compile-options ALIAS ccmath-compile-options) | ||
|
||
# | ||
# Compiler Flags and Conditions | ||
# | ||
|
||
# MSVC Compiler Options | ||
if (MSVC) | ||
# Set MSVC-specific compilation flags | ||
target_compile_options(ccmath-compile-options INTERFACE | ||
/W4 # Enable high warning level | ||
/permissive- # Enforce standard C++ conformance | ||
/Zc:__cplusplus # Properly define __cplusplus macro for the compiler version | ||
/EHsc # Enable standard exception handling | ||
) | ||
|
||
# Define NOMINMAX on Windows platforms to avoid macro conflicts with std::min/std::max | ||
if (WIN32) | ||
target_compile_definitions(ccmath-compile-options INTERFACE NOMINMAX) | ||
endif () | ||
message(STATUS "CCMath: Version: ${CCMATH_BUILD_VERSION}") | ||
|
||
# Treat warnings as errors if CCMATH_STRICT_WARNINGS is set | ||
if (CCMATH_STRICT_WARNINGS) | ||
target_compile_options(ccmath-compile-options INTERFACE /WX) # Warnings as errors | ||
endif () | ||
# Load user-configurable options (e.g., BUILD_EXAMPLES, BUILD_TESTS, etc.) | ||
include(cmake/config/UserOptions.cmake) | ||
|
||
# Clang, GCC, and IntelLLVM Compiler Options | ||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|IntelLLVM") | ||
|
||
# ---------------------------------------------------------------------- | ||
# Compiler Warning Options | ||
# ---------------------------------------------------------------------- | ||
# Collect common warning flags for various compilers and conditions. | ||
set( | ||
ccmath_warning_options | ||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wconversion -Wpedantic -Werror=return-type -Wundef -Wshadow -Wnull-dereference> | ||
$<$<CXX_COMPILER_ID:Clang>:-Wpedantic-macros> | ||
$<$<CXX_COMPILER_ID:MSVC>:/W4 /permissive- /we4715> | ||
) | ||
|
||
# Generic options for Clang, GCC, and IntelLLVM | ||
target_compile_options(ccmath-compile-options INTERFACE | ||
-Wall # Enable common warnings | ||
-Wextra # Enable additional warnings | ||
-Wconversion # Warn on implicit type conversions | ||
-Wpedantic # Enforce strict standard compliance | ||
# Define NOMINMAX on Windows to avoid macro conflicts with min/max | ||
$<$<BOOL:${WIN32}>:-DNOMINMAX> | ||
# Turn on -Werror or /WX if requested | ||
if (CCMATH_ENABLE_WARNINGS_AS_ERRORS) | ||
set( | ||
ccmath_warning_options | ||
${ccmath_warning_options} | ||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Werror> | ||
$<$<CXX_COMPILER_ID:MSVC>:/WX> | ||
) | ||
endif () | ||
|
||
# Add Clang-specific options | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
target_compile_options(ccmath-compile-options INTERFACE | ||
-Wpedantic-macros # Warn about non-standard macro usage | ||
) | ||
endif () | ||
|
||
# Treat specific warnings as errors if CCMATH_STRICT_WARNINGS is set | ||
if (CCMATH_STRICT_WARNINGS) | ||
target_compile_options(ccmath-compile-options INTERFACE | ||
-Werror=return-type # Treat missing return type warnings as errors | ||
) | ||
endif () | ||
|
||
# Add aggressive debug options for developers if CCMATH_DEV_AGGRESSIVE_DEBUG is set | ||
if (CCMATH_DEV_AGGRESIVE_DEBUG) | ||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|IntelLLVM") | ||
|
||
target_compile_options(ccmath-compile-options INTERFACE | ||
-Wwrite-strings # Warn about writeable string literals | ||
-g3 # Maximum debug information | ||
) | ||
elseif (MSVC) | ||
target_compile_options(ccmath-compile-options INTERFACE | ||
/Zi # Generate full debugging information | ||
) | ||
endif () | ||
endif () | ||
|
||
# TODO: Decide if we plan to delete this or not | ||
# if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") | ||
# target_compile_options(ccmath-compile-options INTERFACE | ||
# -Wno-tautological-constant-compare | ||
# ) | ||
# endif() | ||
|
||
else () | ||
message(WARNING "CCMath: Unknown compiler. No specific flags applied.") | ||
# Add extra debug info flags if requested | ||
if (CCMATH_ENABLE_DEBUG_INFO) | ||
set( | ||
ccmath_warning_options | ||
${ccmath_warning_options} | ||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wwrite-strings -g3> | ||
$<$<CXX_COMPILER_ID:MSVC>:/Zi /analyze> | ||
) | ||
endif () | ||
|
||
add_library(ccmath INTERFACE) | ||
add_library(ccmath::ccmath ALIAS ccmath) | ||
|
||
include(cmake/helpers/CcmAddHeaders.cmake) | ||
# ---------------------------------------------------------------------- | ||
# Library Definition | ||
# ---------------------------------------------------------------------- | ||
add_library(${CCMATH_TARGET_NAME} INTERFACE) | ||
add_library(${CCMATH_TARGET_NAME}::${CCMATH_TARGET_NAME} ALIAS ${CCMATH_TARGET_NAME}) | ||
|
||
# Add public headers through a directory-level CMakeLists that sets variables, etc. | ||
# Collect all header files for installation or packaging | ||
include(cmake/helpers/CcmAddHeaders.cmake) # Helper for adding headers to interface | ||
add_subdirectory(include/ccmath) | ||
|
||
# Detect supported compiler features | ||
include(cmake/features/GetAllSupportedFeatures.cmake) | ||
|
||
# CCMath configuration and detection files | ||
include(cmake/config/features/GetAllSupportedFeatures.cmake) | ||
|
||
|
||
# Ensure proper include directories for consumers | ||
target_include_directories(ccmath INTERFACE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
target_include_directories(${CCMATH_TARGET_NAME} INTERFACE | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>" | ||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" | ||
) | ||
|
||
target_link_libraries(ccmath INTERFACE | ||
ccmath::ccmath-compile-options | ||
# Specify minimum C++ standard for library (likely C++17) | ||
target_compile_features( | ||
${CCMATH_TARGET_NAME} | ||
INTERFACE | ||
${CCMATH_DESIRED_CXX_STANDARD} | ||
) | ||
|
||
if (CCMATH_ENABLE_RUNTIME_SIMD) | ||
target_compile_definitions(ccmath INTERFACE CCM_CONFIG_USE_RT_SIMD) | ||
# Enable aggressive warning options only if requested | ||
if (CCMATH_ENABLE_AGGRESSIVE_WARNINGS) | ||
target_compile_options( | ||
${CCMATH_TARGET_NAME} | ||
INTERFACE | ||
${ccmath_warning_options} | ||
) | ||
endif () | ||
|
||
if (NOT CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS) | ||
target_compile_definitions(ccmath INTERFACE | ||
$<$<CONFIG:Debug>:CCM_CONFIG_DEBUG> | ||
$<$<CONFIG:RelWithDebInfo>:CCM_CONFIG_OPTIMIZE> | ||
$<$<CONFIG:Release>:CCM_CONFIG_AGGRESSIVELY_OPTIMIZE> | ||
$<$<CONFIG:MinSizeRel>:CCM_CONFIG_MINSIZE> | ||
) | ||
# Enable AddressSanitizer if requested | ||
if (CCMATH_ENABLE_SANITIZER_BUILD) | ||
add_compile_options(-fsanitize=address) | ||
add_link_options(-fsanitize=address) | ||
endif () | ||
|
||
if (CCMATH_DISABLE_ERRNO) | ||
target_compile_definitions(ccmath INTERFACE CCM_CONFIG_DISABLE_ERRNO) | ||
# Setup project specific compile definitions that must continue with the interface | ||
include(cmake/config/ProjectCompileDefinitions.cmake) | ||
|
||
# Setup the version header for the library | ||
set(CCMATH_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR}) | ||
set(CCMATH_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR}) | ||
set(CCMATH_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH}) | ||
configure_file("${PROJECT_SOURCE_DIR}/cmake/in/version.hpp.in" "${PROJECT_BINARY_DIR}/include/ccmath/version.hpp") | ||
|
||
|
||
# ---------------------------------------------------------------------- | ||
# Installation Rules | ||
# ---------------------------------------------------------------------- | ||
if (CCMATH_INSTALL) | ||
include(cmake/config/InstallRules.cmake) | ||
endif () | ||
|
||
# Generate version header | ||
configure_file(cmake/version.hpp.in "${CMAKE_CURRENT_BINARY_DIR}/include/ccmath/version.hpp" @ONLY) | ||
|
||
# Add optional subdirectories only if requested | ||
# ---------------------------------------------------------------------- | ||
# Subdirectories for Examples, Benchmarks, and Tests | ||
# ---------------------------------------------------------------------- | ||
# Only add these if the user explicitly asked for them in the options. | ||
if (CCMATH_BUILD_EXAMPLES OR CCMATH_BUILD_BENCHMARKS OR CCMATH_BUILD_TESTS) | ||
# Use SYSTEM to suppress warnings from thirdparty code if supported by the CMake version. | ||
# Use SYSTEM to suppress warnings from external code if supported by cmake | ||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.25) | ||
add_subdirectory(thirdparty SYSTEM) | ||
else () | ||
add_subdirectory(thirdparty) | ||
endif () | ||
endif () | ||
|
||
if (CCMATH_BUILD_EXAMPLES) | ||
add_subdirectory(example) | ||
endif () | ||
|
||
if (CCMATH_BUILD_BENCHMARKS) | ||
add_subdirectory(benchmark) | ||
endif () | ||
|
||
if (CCMATH_BUILD_TESTS) | ||
enable_testing() | ||
add_subdirectory(test) | ||
endif () | ||
|
||
# Installation and Packaging | ||
if (CCMATH_INSTALL) | ||
include(GNUInstallDirs) | ||
include(CMakePackageConfigHelpers) | ||
|
||
install(TARGETS | ||
ccmath | ||
ccmath-compile-options | ||
EXPORT ccmath-targets | ||
) | ||
|
||
install(DIRECTORY | ||
"${CMAKE_CURRENT_SOURCE_DIR}/include/" | ||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" | ||
FILES_MATCHING PATTERN "*.hpp" | ||
) | ||
|
||
install(FILES | ||
"${CMAKE_CURRENT_BINARY_DIR}/include/ccmath/version.hpp" | ||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ccmath" | ||
) | ||
|
||
install(EXPORT ccmath-targets | ||
FILE ccmath-targets.cmake | ||
NAMESPACE ccmath:: | ||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/ccmath" | ||
) | ||
|
||
configure_package_config_file( | ||
cmake/ccmath-config.cmake.in | ||
"${CMAKE_CURRENT_BINARY_DIR}/ccmath-config.cmake" | ||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/ccmath" | ||
) | ||
if (CCMATH_BUILD_EXAMPLES) | ||
# Use SYSTEM to suppress warnings from external code if supported by cmake | ||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.25) | ||
add_subdirectory(examples SYSTEM) | ||
else () | ||
add_subdirectory(examples) | ||
endif () | ||
endif () | ||
|
||
# Write a version file for strict version checking | ||
write_basic_package_version_file( | ||
"${CMAKE_CURRENT_BINARY_DIR}/ccmath-config-version.cmake" | ||
COMPATIBILITY SameMajorVersion | ||
) | ||
if (CCMATH_BUILD_BENCHMARKS) | ||
# Use SYSTEM to suppress warnings from external code if supported by cmake | ||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.25) | ||
add_subdirectory(benchmarks SYSTEM) | ||
else () | ||
add_subdirectory(benchmarks) | ||
endif () | ||
endif () | ||
|
||
install(FILES | ||
"${CMAKE_CURRENT_BINARY_DIR}/ccmath-config.cmake" | ||
"${CMAKE_CURRENT_BINARY_DIR}/ccmath-config-version.cmake" | ||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/ccmath" | ||
) | ||
if (CCMATH_BUILD_TESTS) | ||
include(CTest) | ||
enable_testing() | ||
# Use SYSTEM to suppress warnings from external code if supported by cmake | ||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.25) | ||
add_subdirectory(tests SYSTEM) | ||
else () | ||
add_subdirectory(tests) | ||
endif () | ||
endif () | ||
endif () |
Oops, something went wrong.