More CMake cleanup, esp with build/target options and branching

This commit is contained in:
NaifBanana 2025-12-27 22:49:02 -06:00
parent 4ac700e481
commit 0bb5bff559
2 changed files with 30 additions and 7 deletions

View File

@ -2,13 +2,24 @@ cmake_minimum_required(VERSION 3.10)
project(NBEngine VERSION 0.1.0 LANGUAGES C CXX)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "Targeting Release build")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ./release)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ./release)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Targeting Debug build")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ./debug)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ./debug)
add_compile_definitions(_NB_GL_DEBUG_ON)
set(NB_LOGGING ON)
set(NB_BUILD_TESTS ON)
add_compile_definitions(_NB_DEBUG)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
message(STATUS "Building for Windows")
set(NB_TARGET_WINDOWS ON)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(STATUS "Building for Linux")
set(NB_TARGET_LINUX ON)
endif()
find_package(OpenGL)
@ -20,9 +31,8 @@ set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_TESTS)
if (BUILD_TESTS)
if(NB_BUILD_TESTS)
message(STATUS "Building tests")
include(FetchContent)
FetchContent_Declare(
gtest
@ -36,4 +46,15 @@ if (BUILD_TESTS)
set(GTEST_COLOR ON)
endif()
if (NB_LOGGING)
message(STATUS "Building with automatic logging")
add_compile_definitions(_NB_AUTO_LOG)
endif()
if (NB_TARGET_WINDOWS)
add_compile_definitions(_TARGET_WINDOWS)
elseif (NB_TARGET_LINUX)
add_compile_definitions(_TARGET_LINUX)
endif()
add_subdirectory(./engine)

View File

@ -4,4 +4,6 @@ add_library(NBCore
./src/Errors.cpp
)
add_subdirectory(./tests)
if (NB_BUILD_TESTS)
add_subdirectory(./tests)
endif()