2025-01-18 17:24:36 +03:00
|
|
|
cmake_minimum_required(VERSION 3.10)
|
|
|
|
|
|
|
|
|
|
# Project and C standard configuration
|
|
|
|
|
project(bhlib LANGUAGES C)
|
|
|
|
|
set(CMAKE_C_STANDARD 90)
|
|
|
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
|
|
|
|
2025-01-29 09:19:34 +03:00
|
|
|
# Asan profile
|
|
|
|
|
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
|
|
|
|
|
|
|
|
|
if(isMultiConfig)
|
|
|
|
|
if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES)
|
|
|
|
|
list(APPEND CMAKE_CONFIGURATION_TYPES Asan)
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
set(allowedBuildTypes Asan Debug Release RelWithDebInfo MinSizeRel)
|
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}")
|
|
|
|
|
|
|
|
|
|
if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
|
|
|
|
|
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS_ASAN
|
|
|
|
|
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address,undefined -fno-omit-frame-pointer" CACHE STRING
|
|
|
|
|
"Flags used by the C compiler for Asan build type or configuration." FORCE
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS_ASAN
|
|
|
|
|
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address,undefined -fno-omit-frame-pointer" CACHE STRING
|
|
|
|
|
"Flags used by the C++ compiler for Asan build type or configuration." FORCE
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_ASAN
|
2025-01-29 22:41:39 +03:00
|
|
|
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address,undefined" CACHE STRING
|
2025-01-29 09:19:34 +03:00
|
|
|
"Linker flags to be used to create executables for Asan build type." FORCE
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS_ASAN
|
2025-01-29 22:41:39 +03:00
|
|
|
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address,undefined" CACHE STRING
|
2025-01-29 09:19:34 +03:00
|
|
|
"Linker lags to be used to create shared libraries for Asan build type." FORCE
|
|
|
|
|
)
|
|
|
|
|
|
2025-01-18 17:24:36 +03:00
|
|
|
# Project includes
|
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
|
include(CheckIncludeFile)
|
|
|
|
|
include(CheckSymbolExists)
|
|
|
|
|
|
|
|
|
|
# Unit testing and coverage configuration
|
2025-02-28 21:44:01 +03:00
|
|
|
set(ENABLE_TESTING ON CACHE BOOL "Enable unit-testing")
|
|
|
|
|
set(ENABLE_COVERAGE OFF CACHE BOOL "Enable coverage")
|
|
|
|
|
set(ENABLE_EXAMPLES ON CACHE BOOL "Enable building examples")
|
|
|
|
|
set(ENABLE_LTO ON CACHE BOOL "Enable LTO support")
|
|
|
|
|
|
|
|
|
|
# Enable IPO/LTO
|
|
|
|
|
if(ENABLE_LTO)
|
|
|
|
|
check_ipo_supported(RESULT LTO_SUPPORTED)
|
|
|
|
|
if(LTO_SUPPORTED)
|
|
|
|
|
message(STATUS "IPO/LTO enabled")
|
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
|
endif()
|
2025-01-18 17:24:36 +03:00
|
|
|
endif()
|
|
|
|
|
|
2025-02-28 21:44:01 +03:00
|
|
|
# Enable testing
|
|
|
|
|
if(ENABLE_TESTING)
|
2025-01-18 17:24:36 +03:00
|
|
|
include(CTest)
|
|
|
|
|
enable_testing()
|
2025-02-28 21:44:01 +03:00
|
|
|
endif()
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
# Set library code
|
|
|
|
|
set(BH_SOURCE
|
2025-02-02 21:40:31 +03:00
|
|
|
src/Algo.c
|
2025-02-28 09:09:58 +03:00
|
|
|
src/Args.c
|
2025-02-02 21:40:31 +03:00
|
|
|
src/Hashmap.c
|
|
|
|
|
src/IO.c
|
2025-02-28 10:08:05 +03:00
|
|
|
src/Math/Box2f.c
|
|
|
|
|
src/Math/Box3f.c
|
|
|
|
|
src/Math/Line.c
|
|
|
|
|
src/Math/Mat3f.c
|
|
|
|
|
src/Math/Mat4f.c
|
|
|
|
|
src/Math/Misc.c
|
|
|
|
|
src/Math/Plane.c
|
|
|
|
|
src/Math/Quat4f.c
|
|
|
|
|
src/Math/Ray2f.c
|
|
|
|
|
src/Math/Ray3f.c
|
|
|
|
|
src/Math/Vec2f.c
|
|
|
|
|
src/Math/Vec2i.c
|
|
|
|
|
src/Math/Vec3f.c
|
|
|
|
|
src/Math/Vec3i.c
|
|
|
|
|
src/Math/Vec4f.c
|
|
|
|
|
src/Math/Vec4i.c
|
2025-02-02 21:40:31 +03:00
|
|
|
src/Queue.c
|
2025-02-28 21:44:01 +03:00
|
|
|
src/Util.c
|
2025-01-18 17:24:36 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
set(BH_HEADER
|
2025-02-02 21:40:31 +03:00
|
|
|
include/BH/Common.h
|
|
|
|
|
include/BH/Algo.h
|
2025-02-28 09:09:58 +03:00
|
|
|
include/BH/Args.h
|
2025-02-02 21:40:31 +03:00
|
|
|
include/BH/Hashmap.h
|
|
|
|
|
include/BH/IO.h
|
|
|
|
|
include/BH/Math.h
|
|
|
|
|
include/BH/Queue.h
|
2025-02-28 21:44:01 +03:00
|
|
|
include/BH/Util.h
|
2025-01-18 17:24:36 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
set(BH_INCLUDE_DIRS
|
|
|
|
|
include
|
|
|
|
|
${PROJECT_BINARY_DIR}/include
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Determine platform
|
|
|
|
|
if(WIN32)
|
|
|
|
|
message(STATUS "Platform - Win32")
|
|
|
|
|
|
|
|
|
|
# Add platform dependent files
|
|
|
|
|
list(APPEND BH_SOURCE
|
2025-02-28 10:13:37 +03:00
|
|
|
src/Platform/Win32/File.c
|
2025-01-18 17:24:36 +03:00
|
|
|
)
|
|
|
|
|
elseif(UNIX)
|
|
|
|
|
message(STATUS "Platform: Unix (Linux/BSD/MacOS X)")
|
|
|
|
|
|
|
|
|
|
# Add platform dependent files
|
|
|
|
|
list(APPEND BH_SOURCE
|
2025-02-28 10:13:37 +03:00
|
|
|
src/Platform/Posix/File.c
|
2025-01-18 17:24:36 +03:00
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
message(STATUS "Platform: Unknown")
|
|
|
|
|
|
|
|
|
|
# Add platform dependent files
|
|
|
|
|
list(APPEND BH_SOURCE
|
2025-02-28 10:13:37 +03:00
|
|
|
src/Platform/Dummy/File.c
|
2025-01-18 17:24:36 +03:00
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Library
|
2025-02-03 10:56:40 +03:00
|
|
|
add_library(BHLib STATIC ${BH_SOURCE} ${BH_HEADER})
|
|
|
|
|
target_include_directories(BHLib PUBLIC ${BH_INCLUDE_DIRS})
|
|
|
|
|
target_link_libraries(BHLib PUBLIC m)
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
# Enable all compiler warnings
|
|
|
|
|
if(MSVC)
|
2025-02-28 10:28:17 +03:00
|
|
|
target_compile_options(BHLib PRIVATE /W4 /WX)
|
2025-01-18 17:24:36 +03:00
|
|
|
else()
|
2025-02-28 10:28:17 +03:00
|
|
|
target_compile_options(BHLib PRIVATE -Wall -Wextra -Wpedantic -Werror -fstrict-aliasing)
|
2025-01-18 17:24:36 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Coverage
|
2025-02-28 21:44:01 +03:00
|
|
|
if(ENABLE_COVERAGE)
|
2025-02-03 10:56:40 +03:00
|
|
|
target_compile_options(BHLib PRIVATE -coverage)
|
|
|
|
|
target_link_options(BHLib PRIVATE -coverage)
|
2025-01-18 17:24:36 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Tests
|
2025-02-28 21:44:01 +03:00
|
|
|
if(ENABLE_TESTING)
|
2025-01-18 17:24:36 +03:00
|
|
|
add_subdirectory(unit)
|
|
|
|
|
add_subdirectory(test)
|
|
|
|
|
endif()
|
2025-02-28 21:44:01 +03:00
|
|
|
|
|
|
|
|
if(ENABLE_EXAMPLES)
|
|
|
|
|
add_subdirectory(doc/Examples)
|
|
|
|
|
endif()
|