289 lines
9.5 KiB
CMake
289 lines
9.5 KiB
CMake
cmake_minimum_required (VERSION 3.23)
|
|
|
|
#--- v1.0.0 ---
|
|
#------------------------------------------------
|
|
#--- Setup compiler settings ---
|
|
#------------------------------------------------
|
|
# Set C language standard
|
|
set(CMAKE_C_STANDARD 17)
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
set(CMAKE_C_EXTENSIONS OFF) # Only standard features, no compiler-specific extensions
|
|
|
|
# Set C++ language standard
|
|
set(CMAKE_CXX_STANDARD 23)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF) # Only standard features, no compiler-specific extensions
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- Project configuration ---
|
|
#------------------------------------------------
|
|
# Define the project settings
|
|
project("quokkaNoid")
|
|
|
|
# Source directory
|
|
set(SRC_DIR "src")
|
|
|
|
# Resource files (add resource files here if needed)
|
|
set(RESOURCE_FILES "")
|
|
|
|
#------------------------------------------------
|
|
#--- Sanity checks ---
|
|
#------------------------------------------------
|
|
# Ensure build type is set (Debug, Release, etc.)
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be set")
|
|
endif()
|
|
|
|
# Ensure DEV_LIB environment variable is defined (used for external libraries)
|
|
if(NOT DEFINED ENV{DEV_LIB})
|
|
message(FATAL_ERROR "DEV_LIB environment variable must be defined")
|
|
endif()
|
|
set(DEV_LIB $ENV{DEV_LIB})
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- Include directories ---
|
|
#------------------------------------------------
|
|
# General include directories (add your common include paths here)
|
|
set(GENERAL_INCLUDE_DIRS
|
|
"src"
|
|
"sdi_toolBox_1.0.x"
|
|
"${DEV_LIB}/boost_1_87_0"
|
|
"${DEV_LIB}/SDL2/SDL2-2.30.4/include"
|
|
)
|
|
|
|
# Additional include directories for Debug configuration
|
|
set(DEBUG_INCLUDE_DIRS
|
|
# "path/to/debug/include"
|
|
)
|
|
|
|
# Additional include directories for Release configuration
|
|
set(RELEASE_INCLUDE_DIRS
|
|
# "path/to/debug/include"
|
|
)
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- Library directories ---
|
|
#------------------------------------------------
|
|
# General library directories (add your common library paths here)
|
|
set(GENERAL_LIBRARY_DIRS
|
|
${CMAKE_BINARY_DIR}
|
|
"${DEV_LIB}/boost_1_87_0/stage/lib"
|
|
"${DEV_LIB}/SDL2/SDL2-2.30.4/lib/x64"
|
|
)
|
|
|
|
# Additional library directories for Debug configuration
|
|
set(DEBUG_LIBRARY_DIRS
|
|
# "path/to/debug/lib"
|
|
)
|
|
|
|
# Additional library directories for Release configuration
|
|
set(RELEASE_LIBRARY_DIRS
|
|
# "path/to/debug/lib"
|
|
)
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- Preprocessor definitions ---
|
|
#------------------------------------------------
|
|
# General preprocessor definitions (add your common defines here)
|
|
set(GENERAL_PREPROCESSOR_DEFINITIONS
|
|
"_CRT_SECURE_NO_DEPRECATE"
|
|
"_CRT_NONSTDC_NO_DEPRECATE"
|
|
"_UNICODE"
|
|
"_WINDOWS"
|
|
"NOMINMAX"
|
|
"UNICODE"
|
|
"WIN32"
|
|
"WIN32_LEAN_AND_MEAN"
|
|
|
|
#"SDL_STATIC"
|
|
)
|
|
|
|
# Additional preprocessor definitions for Debug configuration
|
|
set(DEBUG_PREPROCESSOR_DEFINITIONS
|
|
"_DEBUG"
|
|
"DEBUG"
|
|
"WXDEBUG"
|
|
)
|
|
|
|
# Additional preprocessor definitions for Release configuration
|
|
set(RELEASE_PREPROCESSOR_DEFINITIONS
|
|
"NDEBUG"
|
|
)
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- Libraries and DLLs ---
|
|
#------------------------------------------------
|
|
# General libraries to link (add your common libraries here)
|
|
set(GENERAL_LIB
|
|
"SDL2main.lib"
|
|
"SDL2.lib"
|
|
"SDL2_image.lib"
|
|
"SDL2_ttf.lib"
|
|
)
|
|
|
|
# Additional libraries for Debug configuration
|
|
set(DEBUG_LIB
|
|
# "libDebug.lib"
|
|
)
|
|
|
|
# Additional libraries for Release configuration
|
|
set(RELEASE_LIB
|
|
# "libRelease.lib"
|
|
)
|
|
|
|
# General DLLs to copy after build (add your common DLLs here)
|
|
set(GENERAL_BIN
|
|
"${DEV_LIB}/SDL2/SDL2-2.30.4/lib/x64/SDL2.dll"
|
|
"${DEV_LIB}/SDL2/SDL2-2.30.4/lib/x64/SDL2_image.dll"
|
|
"${DEV_LIB}/SDL2/SDL2-2.30.4/lib/x64/SDL2_ttf.dll"
|
|
)
|
|
|
|
# Additional DLLs for Debug configuration
|
|
set(DEBUG_BIN
|
|
# "path/to/debug/dll"
|
|
)
|
|
|
|
# Additional DLLs for Release configuration
|
|
set(RELEASE_BIN
|
|
# "path/to/release/dll"
|
|
)
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- MSVC Debug Information Format Policy ---
|
|
#------------------------------------------------
|
|
# Ensure CMake policy CMP0141 is set to NEW to control the MSVC debug information format.
|
|
# This sets CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to "EditAndContinue" for Debug and RelWithDebInfo configurations,
|
|
# and to "ProgramDatabase" for other configurations, but only when using the MSVC compiler.
|
|
if (POLICY CMP0141)
|
|
cmake_policy(SET CMP0141 NEW)
|
|
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
|
|
endif()
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- Source files gathering ---
|
|
#------------------------------------------------
|
|
# Collect all C and C++ source files recursively
|
|
file(GLOB_RECURSE SOURCES_C "${SRC_DIR}/*.c")
|
|
file(GLOB_RECURSE SOURCES_CPP "${SRC_DIR}/*.cpp")
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- Target definition ---
|
|
#------------------------------------------------
|
|
# Define the main executable target
|
|
add_executable(${PROJECT_NAME}
|
|
${SOURCES_C}
|
|
${SOURCES_CPP}
|
|
${RESOURCE_FILES}
|
|
)
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- Target properties setup ---
|
|
#------------------------------------------------
|
|
# Setup include directories
|
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
|
${GENERAL_INCLUDE_DIRS}
|
|
$<$<CONFIG:Debug>:${DEBUG_INCLUDE_DIRS}>
|
|
$<$<CONFIG:Release>:${RELEASE_INCLUDE_DIRS}>
|
|
)
|
|
|
|
# Setup library directories
|
|
target_link_directories(${PROJECT_NAME} PRIVATE
|
|
${GENERAL_LIBRARY_DIRS}
|
|
$<$<CONFIG:Debug>:${DEBUG_LIBRARY_DIRS}>
|
|
$<$<CONFIG:Release>:${RELEASE_LIBRARY_DIRS}>
|
|
)
|
|
|
|
# Setup preprocessor definitions
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
|
${GENERAL_PREPROCESSOR_DEFINITIONS}
|
|
$<$<CONFIG:Debug>:${DEBUG_PREPROCESSOR_DEFINITIONS}>
|
|
$<$<CONFIG:Release>:${RELEASE_PREPROCESSOR_DEFINITIONS}>
|
|
)
|
|
|
|
# Setup linked libraries
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
|
${GENERAL_LIB}
|
|
$<$<CONFIG:Debug>:${DEBUG_LIB}>
|
|
$<$<CONFIG:Release>:${RELEASE_LIB}>
|
|
)
|
|
|
|
# Setup compiler and linker options (MSVC specific)
|
|
if(MSVC)
|
|
target_compile_options(${PROJECT_NAME} PRIVATE /MP)
|
|
target_link_options(${PROJECT_NAME} PRIVATE "/ignore:4099" /PROFILE)
|
|
endif()
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- Post-build: Copy DLLs ---
|
|
#------------------------------------------------
|
|
# Copy DLLs to the output directory after build
|
|
if(GENERAL_BIN OR DEBUG_BIN OR RELEASE_BIN)
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
${GENERAL_BIN}
|
|
$<$<CONFIG:Debug>:${DEBUG_BIN}>
|
|
$<$<CONFIG:Release>:${RELEASE_BIN}>
|
|
${CMAKE_BINARY_DIR}
|
|
)
|
|
endif()
|
|
|
|
|
|
#------------------------------------------------
|
|
#--- Project compilation log ---
|
|
#------------------------------------------------
|
|
# Print project and environment information for diagnostics
|
|
message(STATUS "---------------------------------------------------")
|
|
message(STATUS "---------------------------------------------------")
|
|
message(STATUS "---------------------------------------------------")
|
|
message(STATUS "--- Platform Information --------------------------")
|
|
message(STATUS "System Name: ${CMAKE_SYSTEM_NAME}")
|
|
message(STATUS "Processor: ${CMAKE_SYSTEM_PROCESSOR}")
|
|
message(STATUS "CMake Generator: ${CMAKE_GENERATOR}")
|
|
message(STATUS "Install Prefix: ${CMAKE_INSTALL_PREFIX}")
|
|
message(STATUS "---------------------------------------------------")
|
|
message(STATUS "--- Compiler/Language Settings --------------------")
|
|
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
|
|
message(STATUS "Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
|
|
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
|
|
message(STATUS "Common Compiler Flags: ${CMAKE_CXX_FLAGS}")
|
|
message(STATUS "Debug Compiler Flags: ${CMAKE_CXX_FLAGS_DEBUG}")
|
|
message(STATUS "Release Compiler Flags: ${CMAKE_CXX_FLAGS_RELEASE}")
|
|
message(STATUS "Common Linker Flags: ${CMAKE_EXE_LINKER_FLAGS}")
|
|
message(STATUS "Debug Linker Flags: ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
|
|
message(STATUS "Release Linker Flags: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
|
|
message(STATUS "---------------------------------------------------")
|
|
message(STATUS "--- Path Information ------------------------------")
|
|
message(STATUS "Source Dir: ${CMAKE_CURRENT_SOURCE_DIR}")
|
|
message(STATUS "Binary Dir: ${CMAKE_CURRENT_BINARY_DIR}")
|
|
if(MSVC)
|
|
message(STATUS "---------------------------------------------------")
|
|
message(STATUS "--- Microsoft Visual C++ (MSVC) Information -------")
|
|
# Check the major compiler version
|
|
if(MSVC_VERSION GREATER_EQUAL 1950)
|
|
message(STATUS "MSVC Compiler Version: ${MSVC_VERSION} (Visual Studio 2026 or newer)")
|
|
elseif(MSVC_VERSION GREATER_EQUAL 1930)
|
|
message(STATUS "MSVC Compiler Version: ${MSVC_VERSION} (Visual Studio 2022)")
|
|
endif()
|
|
message(STATUS "MSVC Toolset Version: ${MSVC_TOOLSET_VERSION}")
|
|
message(STATUS "CPP Compiler Version: ${CMAKE_CXX_COMPILER_VERSION}")
|
|
message(STATUS "C Compiler Version: ${CMAKE_C_COMPILER_VERSION}")
|
|
endif()
|
|
message(STATUS "---------------------------------------------------")
|
|
message(STATUS "--- Project Information ---------------------------")
|
|
message(STATUS "Project Name: ${PROJECT_NAME}")
|
|
message(STATUS "Preset Name: ${PRESET_NAME}")
|
|
message(STATUS "---------------------------------------------------")
|
|
message(STATUS "---------------------------------------------------")
|
|
message(STATUS "---------------------------------------------------")
|
|
|