1
0
mirror of https://github.com/slendidev/smath.git synced 2026-03-17 02:26:50 +02:00
Files
smath/CMakeLists.txt
Slendi 224b924772 Add optional interop headers
Those headers are used for interoping with various popular C++
libraries. For now, those libraries are Eigen, GLM, HandmadeMath,
Raylib, and SFML. Some other ones may be added in the future.

Those are disabled by default, as most projects I would imagine would
not use them. But in case you need any of them for special reasons like
I did, they are there.

Signed-off-by: Slendi <slendi@socopon.com>
2026-03-12 01:34:35 +02:00

116 lines
3.1 KiB
CMake

cmake_minimum_required(VERSION 3.15)
project(SmathExamples LANGUAGES CXX VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(SMATH_BUILD_EXAMPLES "Build example programs" ON)
option(SMATH_BUILD_TESTS "Build unit tests" ON)
option(SMATH_BUILD_MODULES "Enable C++20 modules support" OFF)
option(SMATH_ENABLE_LEGACY_HEADER "Install legacy include <smath.hpp> shim" OFF)
option(SMATH_INSTALL_INTEROP_HEADERS "Install interop headers" OFF)
if(SMATH_BUILD_MODULES)
message(STATUS "Building smath C++ module")
add_subdirectory(src/modules)
endif()
add_library(smath INTERFACE)
target_include_directories(smath
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<$<BOOL:${SMATH_ENABLE_LEGACY_HEADER}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>>
$<INSTALL_INTERFACE:include>
)
add_library(smath::smath ALIAS smath)
include(CMakePackageConfigHelpers)
install(TARGETS smath
EXPORT smathTargets
)
install(FILES include/smath/smath.hpp DESTINATION include/smath)
if(SMATH_INSTALL_INTEROP_HEADERS)
install(DIRECTORY include/smath/interop DESTINATION include/smath)
endif()
if(SMATH_ENABLE_LEGACY_HEADER)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/smath_legacy_header.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/smath.hpp"
@ONLY
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/smath.hpp" DESTINATION include)
endif()
install(EXPORT smathTargets
NAMESPACE smath::
FILE smathTargets.cmake
DESTINATION lib/cmake/smath
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/smathConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/smathConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/smathConfig.cmake"
INSTALL_DESTINATION "lib/cmake/smath"
)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/smath.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/smath.pc"
@ONLY
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/smath.pc"
DESTINATION lib/pkgconfig
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/smathConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/smathConfigVersion.cmake"
DESTINATION lib/cmake/smath
)
if(SMATH_BUILD_EXAMPLES)
file(GLOB EXAMPLE_SOURCES "${CMAKE_SOURCE_DIR}/examples/*.cpp")
foreach(EXAMPLE_FILE ${EXAMPLE_SOURCES})
get_filename_component(EXAMPLE_NAME ${EXAMPLE_FILE} NAME_WE)
add_executable(${EXAMPLE_NAME} ${EXAMPLE_FILE})
target_link_libraries(${EXAMPLE_NAME} PRIVATE smath::smath)
endforeach()
endif()
if(SMATH_BUILD_TESTS)
enable_testing()
find_package(GTest QUIET)
if(NOT GTest_FOUND)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()
file(GLOB TEST_SOURCES "${CMAKE_SOURCE_DIR}/tests/*.cpp")
add_executable(smath_tests ${TEST_SOURCES})
target_link_libraries(smath_tests PRIVATE
smath::smath
GTest::gtest_main
)
include(GoogleTest)
gtest_discover_tests(smath_tests)
endif()