# ======================================================== # CMake Configuration for the Sortiva Project # ======================================================== cmake_minimum_required(VERSION 3.22) project(sortiva LANGUAGES CXX VERSION 1.0.0 ) # ======================================================== # Global Settings # ======================================================== set(CMAKE_CXX_STANDARD 20) # Use C++20 set(CMAKE_CXX_STANDARD_REQUIRED ON) # Enforce C++20 standard set(CMAKE_CXX_EXTENSIONS OFF) # Disable compiler-specific extensions set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile commands (useful for IDEs) set(USE_FOLDERS ON) # Organize targets into folders (for IDEs) set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) # Build static libraries by default # ======================================================== # Helper Functions: # Puts Targets into a Folder # Finds all files in a dir wich are defined file-types # ======================================================== # This function puts targets into a specified folder. # It checks if the target exists and gets the actual target (if it is aliased). # It then sets the folder property for the target. function(put_targets_into_folder) set(oneValueArgs FOLDER) set(multiValueArgs TARGETS) cmake_parse_arguments(ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) foreach(target ${ARGS_TARGETS}) # Check if target exists if (NOT TARGET ${target}) message(FATAL_ERROR "${target} target not found") endif() # Get the actual target (if it is aliased) get_target_property(actual_target ${target} ALIASED_TARGET) if (NOT actual_target) set(actual_target ${target}) endif() # Set the folder property for the target set_target_properties(${actual_target} PROPERTIES FOLDER ${ARGS_FOLDER}) endforeach() endfunction() function(find_files var_name path) set(sources) foreach(ext ${ARGN}) file(GLOB_RECURSE files "${path}/*.${ext}") list(APPEND sources ${files}) endforeach() set(${var_name} ${${var_name}} ${sources} PARENT_SCOPE) endfunction() # ======================================================== # FetchContent Setup # ======================================================== # FetchContent allows us to retrieve external libraries (e.g., Sol2, Google Test) dynamically. include(FetchContent) # Set FetchContent to work offline if needed set(FETCHCONTENT_UPDATES_DISCONNECTED ON) # Prevent automatic updates set(FETCHCONTENT_QUIET OFF) # Display download progress set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile_commands.json # ======================================================== # External Dependencies (currently not needed) # ======================================================== # # --- Add Sol2 (Lua C++ Binding Library) # FetchContent_Declare( # sol2 # GIT_REPOSITORY https://github.com/ThePhD/sol2.git # GIT_TAG v3.3.0 # ) # FetchContent_MakeAvailable(sol2) # # # --- Add Lua # FetchContent_Declare( # lua # GIT_REPOSITORY "https://github.com/marovira/lua" # GIT_TAG "5.4.4" # ) # FetchContent_MakeAvailable(lua) # # set(LUA_BUILD_INTERPRETER ON CACHE BOOL "Build the Lua interpreter" FORCE) # set(SOL2_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) # ======================================================== # Helper Function: Set Common Target Properties # ======================================================== # This function defines common properties (such as libraries and include directories) # that are shared among all targets. function(set_common_properties target) #target_link_libraries(${target} PRIVATE sol2::sol2) # Link with Sol2 #target_compile_definitions(${target} PRIVATE SOL_ALL_SAFETIES_ON=1) target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) # Include project headers #target_sources(${target} PRIVATE ${SVA_COMMON_FILES}) # Include common files #target_link_libraries(${target} PRIVATE lua::lua) endfunction() # ======================================================== # Executable # ======================================================== set(GUI_TARGET_NAME "${PROJECT_NAME}") # --- Create GUI Executable find_files(SVA_GUI_FILES "./src/" hpp cpp h c hxx cxx) add_executable(${GUI_TARGET_NAME} ${SVA_GUI_FILES} ) target_compile_definitions(${GUI_TARGET_NAME} PUBLIC "$<$:_DEBUG>") source_group(TREE ${PROJECT_SOURCE_DIR}/src/ PREFIX "Source" FILES ${SVA_GUI_FILES}) # --------------- # RAYLIB # --------------- # Dependencies set(RAYLIB_VERSION 5.5) find_package(raylib ${RAYLIB_VERSION} QUIET) # QUIET or REQUIRED if (NOT raylib_FOUND) # If there's none, fetch and build raylib include(FetchContent) FetchContent_Declare( raylib DOWNLOAD_EXTRACT_TIMESTAMP OFF URL https://github.com/raysan5/raylib/archive/refs/tags/${RAYLIB_VERSION}.tar.gz ) FetchContent_GetProperties(raylib) if (NOT raylib_POPULATED) # Have we downloaded raylib yet? set(FETCHCONTENT_QUIET NO) FetchContent_MakeAvailable(raylib) set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples endif() endif() target_link_libraries(${GUI_TARGET_NAME} PRIVATE raylib) # Checks if OSX and links appropriate frameworks (Only required on MacOS) if (APPLE) target_link_libraries(${PROJECT_NAME} "-framework IOKit") target_link_libraries(${PROJECT_NAME} "-framework Cocoa") target_link_libraries(${PROJECT_NAME} "-framework OpenGL") endif() set_common_properties(${GUI_TARGET_NAME}) put_targets_into_folder( FOLDER "ThirdParty/raylib" TARGETS raylib uninstall ) #put_targets_into_folder( # FOLDER "ThirdParty/lua" # TARGETS # lua lua_lib #) put_targets_into_folder( FOLDER "ThirdParty/glfw" TARGETS glfw update_mappings ) # Option to create an includes target set(SVA_CREATE_INCLUDES_TARGET ON CACHE BOOL "Create an includes target") if(${SVA_CREATE_INCLUDES_TARGET}) set(INCLUDES_TARGET_NAME "includes") set(INCLUDE_FILES) find_files( INCLUDE_FILES "include/" hpp h hxx ) message(STATUS "Include files: ${INCLUDE_FILES}") add_custom_target(${INCLUDES_TARGET_NAME} SOURCES ${INCLUDE_FILES} ) source_group(TREE ${PROJECT_SOURCE_DIR}/include/ PREFIX "Source" FILES ${INCLUDE_FILES}) endif()