BLT/CMakeLists.txt

159 lines
5.9 KiB
CMake
Raw Normal View History

2024-04-06 17:02:10 -04:00
cmake_minimum_required(VERSION 3.20)
2024-02-24 03:30:31 -05:00
include(cmake/color.cmake)
2023-11-22 23:25:29 -05:00
2024-06-30 13:54:10 -04:00
set(BLT_VERSION 0.17.27)
2023-11-22 23:25:29 -05:00
set(BLT_TEST_VERSION 0.0.1)
2024-01-08 08:58:14 -05:00
set(BLT_TARGET BLT)
2023-11-22 23:25:29 -05:00
project(BLT VERSION ${BLT_VERSION})
2022-12-23 13:50:27 -05:00
2023-11-22 23:06:29 -05:00
set(CMAKE_CXX_STANDARD 17)
2022-12-23 13:50:27 -05:00
2023-07-28 01:35:01 -04:00
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
option(ENABLE_TSAN "Enable the thread data race sanitizer" OFF)
2023-11-22 23:25:29 -05:00
2022-12-23 13:50:27 -05:00
option(BUILD_STD "Build the BLT standard utilities." ON)
option(BUILD_PROFILING "Build the BLT profiler extension" ON)
2024-02-06 00:20:37 -05:00
option(BUILD_FS "Build the BLT FS utilities including the NBT + eNBT extension" ON)
option(BUILD_PARSE "Build the BLT parsers" ON)
2023-11-22 23:25:29 -05:00
option(BUILD_TESTS "Build the BLT test set" OFF)
2023-11-22 23:25:29 -05:00
2024-03-11 11:51:13 -04:00
option(BLT_DISABLE_STATS "Disable tracking stats in certain objects. Enabling this will cause stat functions to return 0" OFF)
option(BLT_DISABLE_LOGGING "Disable blt::logging (all macros and will safely disable logging function!)" OFF)
option(BLT_DISABLE_TRACE "Disable blt::logging BLT_TRACE macro" OFF)
option(BLT_DISABLE_DEBUG "Disable blt::logging BLT_DEBUG macro" OFF)
option(BLT_DISABLE_INFO "Disable blt::logging BLT_INFO macro" OFF)
option(BLT_DISABLE_WARN "Disable blt::logging BLT_WARN macro" OFF)
option(BLT_DISABLE_ERROR "Disable blt::logging BLT_ERROR macro" OFF)
option(BLT_DISABLE_FATAL "Disable blt::logging BLT_FATAL macro" OFF)
2022-12-23 13:50:27 -05:00
2024-03-11 11:51:13 -04:00
if(${BLT_DISABLE_STATS})
add_compile_definitions(BLT_DISABLE_STATS)
endif ()
2023-07-10 18:45:43 -04:00
configure_file(include/blt/config.h.in config/blt/config.h @ONLY)
2024-02-24 03:30:31 -05:00
message("Enabling library compilation")
if (${BUILD_STD} OR ${BUILD_PROFILING})
2024-04-25 19:35:05 -04:00
message(STATUS "Building ${Yellow}standard${ColourReset} cxx files")
2022-12-25 23:25:32 -05:00
file(GLOB_RECURSE STD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/std/*.cpp")
2024-02-24 03:30:31 -05:00
else ()
2022-12-23 13:50:27 -05:00
set(STD_FILES "")
2024-02-24 03:30:31 -05:00
endif ()
2022-12-23 13:50:27 -05:00
2024-02-24 03:30:31 -05:00
if (${BUILD_PROFILING})
2024-04-25 19:35:05 -04:00
message(STATUS "Building ${Yellow}profiling${ColourReset} cxx files")
2022-12-25 23:25:32 -05:00
file(GLOB_RECURSE PROFILING_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/profiling/*.cpp")
2024-02-24 03:30:31 -05:00
else ()
2022-12-23 13:50:27 -05:00
set(PROFILING_FILES "")
2024-02-24 03:30:31 -05:00
endif ()
2022-12-23 13:50:27 -05:00
2024-02-24 03:30:31 -05:00
if (${BUILD_FS})
2024-04-25 19:35:05 -04:00
message(STATUS "Building ${Yellow}filesystem${ColourReset} cxx files")
2024-02-06 00:20:37 -05:00
file(GLOB_RECURSE FS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/fs/*.cpp")
2024-02-24 03:30:31 -05:00
else ()
2024-02-06 00:20:37 -05:00
set(FS_FILES "")
2024-02-24 03:30:31 -05:00
endif ()
2023-01-26 00:59:36 -05:00
2024-02-24 03:30:31 -05:00
if (${BUILD_PARSE})
2024-04-25 19:35:05 -04:00
message(STATUS "Building ${Yellow}parser${ColourReset} cxx files")
file(GLOB_RECURSE PARSE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/parse/*.cpp")
2024-02-24 03:30:31 -05:00
else ()
set(PARSE_FILES "")
2024-02-24 03:30:31 -05:00
endif ()
2024-02-24 03:30:31 -05:00
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libraries/parallel-hashmap)
message("Found Parallel Hashmaps library, using ${Yellow}phmap${ColourReset} over ${Red}std::unordered_map${ColourReset}")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libraries/parallel-hashmap)
2024-02-24 03:30:31 -05:00
else()
message("Parallel Hashmaps library not found! using ${Yellow}std::unordered_map${ColourReset}")
endif ()
2023-07-29 13:38:19 -04:00
#include zlib if the user has it.
find_package(ZLIB QUIET)
if (${ZLIB_FOUND})
include_directories(${ZLIB_INCLUDE_DIRS})
2024-02-24 03:30:31 -05:00
else ()
message("ZLIB was not found, this is fine however if you wish you use gzip with NBT it is required.")
2024-02-24 03:30:31 -05:00
endif ()
2022-12-27 00:51:37 -05:00
2022-12-27 00:59:49 -05:00
include_directories(include/)
2023-04-08 12:44:31 -04:00
include_directories(${CMAKE_CURRENT_BINARY_DIR}/config/)
2022-12-23 13:50:27 -05:00
2024-04-25 19:35:05 -04:00
add_library(${BLT_TARGET} ${STD_FILES} ${PROFILING_FILES} ${FS_FILES} ${PARSE_FILES})
string(REPLACE "+" "\\+" escaped_source ${CMAKE_CURRENT_SOURCE_DIR})
string(APPEND escaped_source "/src/blt/.*/")
list(TRANSFORM STD_FILES REPLACE ${escaped_source} "")
list(TRANSFORM PROFILING_FILES REPLACE ${escaped_source} "")
list(TRANSFORM FS_FILES REPLACE ${escaped_source} "")
list(TRANSFORM PARSE_FILES REPLACE ${escaped_source} "")
message("Standard Files ${Magenta}${STD_FILES}${ColourReset}")
message("Profiler Files ${Magenta}${PROFILING_FILES}${ColourReset}")
message("FS Files ${Magenta}${FS_FILES}${ColourReset}")
message("Parser Files ${Magenta}${PARSE_FILES}${ColourReset}")
2022-12-25 23:23:12 -05:00
message("Source: ${CMAKE_SOURCE_DIR}")
2022-12-25 23:24:58 -05:00
message("Current Source: ${CMAKE_CURRENT_SOURCE_DIR}")
2024-02-24 03:30:31 -05:00
message("Binary: ${CMAKE_BINARY_DIR}")
message("Current Binary: ${CMAKE_CURRENT_BINARY_DIR}")
2022-12-25 23:23:12 -05:00
2024-02-24 03:30:31 -05:00
if (${ZLIB_FOUND})
2024-02-16 00:23:11 -05:00
target_link_libraries(${BLT_TARGET} PUBLIC ZLIB::ZLIB)
2024-02-24 03:30:31 -05:00
endif ()
include(cmake/warnings.cmake)
2024-02-16 00:23:11 -05:00
target_include_directories(${BLT_TARGET} PUBLIC include/)
target_include_directories(${BLT_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/config/)
2024-02-24 03:30:31 -05:00
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libraries/parallel-hashmap)
message("Including Parallel Hashmap directory")
2024-01-08 08:58:14 -05:00
target_include_directories(${BLT_TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/libraries/parallel-hashmap)
2024-02-24 03:30:31 -05:00
endif ()
2024-02-24 03:30:31 -05:00
message("BLT ${Yellow}${BLT_VERSION}${ColourReset} Successfully included!")
2024-01-08 09:17:17 -05:00
message("Installing to ${CMAKE_INSTALL_LIBDIR} with headers at ${CMAKE_INSTALL_INCLUDEDIR}")
2024-01-08 13:25:56 -05:00
file(GLOB_RECURSE BLT_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
2024-02-24 03:30:31 -05:00
foreach (S ${BLT_HEADER_FILES})
2024-01-08 13:25:56 -05:00
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/include/" "" SO ${S})
string(REGEX REPLACE "\/[A-Z|a-z|0-9|_|-]*\\.h" "/" SA ${SO})
list(APPEND BLT_F_HEADERS ${SA})
2024-01-08 13:45:13 -05:00
install(FILES ${S} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${SA})
2024-01-08 13:25:56 -05:00
endforeach ()
install(FILES ${CMAKE_BINARY_DIR}/config/blt/config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/blt/)
2024-02-24 03:30:31 -05:00
set_target_properties(${BLT_TARGET} PROPERTIES VERSION ${BLT_VERSION})
2024-01-08 13:25:56 -05:00
set_target_properties(${BLT_TARGET} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})
2024-01-08 09:17:17 -05:00
install(TARGETS ${BLT_TARGET}
CONFIGURATIONS RelWithDebInfo
2024-01-08 13:45:13 -05:00
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
2024-01-08 09:17:17 -05:00
2024-02-24 03:30:31 -05:00
if (${BUILD_TESTS})
message("Building test version ${BLT_TEST_VERSION}")
2023-11-22 23:25:29 -05:00
project(BLT_TESTS VERSION ${BLT_TEST_VERSION})
include_directories(tests/include)
file(GLOB_RECURSE TEST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/tests/src/*.cpp")
message("Using files ${TEST_FILES}")
add_executable(BLT_TESTS ${TEST_FILES})
2024-02-26 11:02:16 -05:00
target_link_libraries(BLT_TESTS PRIVATE BLT)
2023-11-22 23:25:29 -05:00
2024-02-24 03:30:31 -05:00
include(cmake/warnings.cmake)
include(cmake/sanitizers.cmake)
2023-11-22 23:25:29 -05:00
message("Built tests")
2024-02-24 03:30:31 -05:00
endif ()
2023-11-22 23:25:29 -05:00
project(BLT)