# We use a custom flag instead of letting user set CMAKE_UNITY_BUILD because we don't want stuff in 3rdparty to be built with unity build # (they may not support them, and configuring each is very time consuming) option(BUILD_CORE_WITH_UNITY_BUILD OFF) option(BUILD_CORE_MAIN "Whether to compile the main executable or not." ON) option(BUILD_CORE_TESTS "Whether to compile the tests executable or not." OFF) set(TARGET_LOCALE "en_US" CACHE STRING "Locale to build.") option(BUILD_CORE_WITH_OPENGL2_BACKEND ON) option(BUILD_CORE_WITH_OPENGL3_BACKEND ON) option(BUILD_CORE_WITH_VULKAN_BACKEND ON) if(WIN32) option(BUILD_CORE_WITH_DX11_BACKEND ON) option(BUILD_CORE_WITH_DX12_BACKEND ON) elseif(APPLE) option(BUILD_CORE_WITH_METAL_BACKEND ON) endif() macro(add_source_group GROUP_NAME) list(APPEND CPLT_CORE_SOURCES ${ARGN}) set_source_files_properties(${ARGN} PROPERTIES UNITY_GROUP "${GROUP_NAME}" ) endmacro() list(APPEND CPLT_CORE_SOURCES # Entrypoint src/Entrypoint/main.cpp src/Entrypoint/Backend_OpenGL2.cpp src/Entrypoint/Backend_OpenGL3.cpp src/Entrypoint/Backend_Vulkan.cpp src/Entrypoint/Backend_DirectX11.cpp src/Entrypoint/Backend_DirectX12.cpp src/Entrypoint/Backend_Metal.mm ) add_source_group(Model src/Model/Assets.cpp src/Model/Database.cpp src/Model/Filter.cpp src/Model/GlobalStates.cpp src/Model/Items.cpp src/Model/Project.cpp ) add_source_group(Model.Template src/Model/Template/Template_Main.cpp src/Model/Template/Template_RTTI.cpp src/Model/Template/TableTemplate.cpp src/Model/Template/TableTemplateIterator.cpp ) add_source_group(Model.Workflow src/Model/Workflow/Evaluation.cpp src/Model/Workflow/Value_Main.cpp src/Model/Workflow/Value_RTTI.cpp src/Model/Workflow/Workflow_Main.cpp src/Model/Workflow/Workflow_RTTI.cpp ) add_source_group(Model.Workflow.Nodes src/Model/Workflow/Nodes/DocumentNodes.cpp src/Model/Workflow/Nodes/UserInputNodes.cpp src/Model/Workflow/Nodes/NumericNodes.cpp#include "DataStream.hpp" src/Model/Workflow/Nodes/TextNodes.cpp ) add_source_group(Model.Workflow.Value src/Model/Workflow/Values/Basic.cpp src/Model/Workflow/Values/Database.cpp src/Model/Workflow/Values/Dictionary.cpp src/Model/Workflow/Values/List.cpp ) list(APPEND CPLT_CORE_SOURCES # UI src/UI/UI_DatabaseView.cpp src/UI/UI_Items.cpp src/UI/UI_MainWindow.cpp src/UI/UI_Settings.cpp src/UI/UI_Templates.cpp src/UI/UI_Utils.cpp src/UI/UI_Workflows.cpp ) add_source_group(Utils src/Utils/IO/Archive.cpp src/Utils/IO/DataStream.cpp src/Utils/Sigslot.cpp src/Utils/StandardDirectories.cpp src/Utils/Time.cpp ) function(add_executable_variant TARGET_NAME) message("CpltCore: generating executable ${TARGET_NAME}") if(BUILD_CORE_WITH_OPENGL2_BACKEND OR BUILD_CORE_WITH_OPENGL3_BACKEND OR BUILD_CORE_WITH_VULKAN_BACKEND OR BUILD_CORE_WITH_METAL_BACKEND) list(APPEND CPLT_CORE_SOURCES ${CMAKE_SOURCE_DIR}/3rdparty/imgui/backend/imgui_impl_glfw.cpp ) endif() if(BUILD_CORE_WITH_DX11_BACKEND OR BUILD_CORE_WITH_DX12_BACKEND) list(APPEND CPLT_CORE_SOURCES ${CMAKE_SOURCE_DIR}/3rdparty/imgui/backend/imgui_impl_win32.cpp ) endif() add_executable(${TARGET_NAME} ${CPLT_CORE_SOURCES}) target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src ${CMAKE_SOURCE_DIR}/3rdparty/iconfontheaders ${CMAKE_SOURCE_DIR}/3rdparty/imgui ${CMAKE_SOURCE_DIR}/3rdparty/imgui-node-editor ) target_link_libraries(${TARGET_NAME} PRIVATE ${CONAN_LIBS} imgui implot imgui-node-editor ) target_compile_definitions(${TARGET_NAME} PRIVATE PLATFORM_WIN32=$ PLATFORM_MACOS=$ PLATFORM_LINUX=$ ) if(NOT TARGET_LOCALE STREQUAL "en_US") target_compile_definitions(${TARGET_NAME} PRIVATE TARGET_LOCALE=${TARGET_LOCALE} TARGET_LOCALE_FILE="Locale/${TARGET_LOCALE}.h" ) endif() if(WIN32) message("CpltCore: - building with DirectX11 backend ${BUILD_CORE_WITH_DX11_BACKEND}") message("CpltCore: - building with DirectX12 backend ${BUILD_CORE_WITH_DX12_BACKEND}") target_compile_definitions(${TARGET_NAME} PRIVATE BUILD_CORE_WITH_DX11_BACKEND=$ BUILD_CORE_WITH_DX12_BACKEND=$ ) if(BUILD_CORE_WITH_DX11_BACKEND) target_link_libraries(${TARGET_NAME} PRIVATE dxgi.lib d3d11.lib) endif() if(BUILD_CORE_WITH_DX12_BACKEND) target_link_libraries(${TARGET_NAME} PRIVATE dxgi.lib d3d12.lib) endif() endif() if(APPLE) message("CpltCore: - building with Metal backend ${BUILD_CORE_WITH_METAL_BACKEND}") target_compile_definitions(${TARGET_NAME} PRIVATE BUILD_CORE_WITH_METAL_BACKEND=$ ) endif() if(NOT APPLE) message("CpltCore: - building with OpenGL2 backend ${BUILD_CORE_WITH_OPENGL2_BACKEND}") message("CpltCore: - building with OpenGL3 backend ${BUILD_CORE_WITH_OPENGL3_BACKEND}") message("CpltCore: - building with Vulkan backend ${BUILD_CORE_WITH_VULKAN_BACKEND}") target_compile_definitions(${TARGET_NAME} PRIVATE BUILD_CORE_WITH_OPENGL2_BACKEND=$ BUILD_CORE_WITH_OPENGL3_BACKEND=$ BUILD_CORE_WITH_VULKAN_BACKEND=$ ) # TODO conditionally add opengl libraries if(BUILD_CORE_WITH_VULKAN_BACKEND) find_package(Vulkan REQUIRED FATAL_ERROR) target_include_directories(${TARGET_NAME} PRIVATE ${Vulkan_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} PRIVATE ${Vulkan_LIBRARIES}) endif() endif() if(WIN32) function(handle_gnu_style_compiler) # No console window when targeting windows # Supposedly the flag -mwindows would automatically make the executable use GUI subsystem # But, when subsystem is set to GUI, linker will only search WinMain and wWinMain but not the standard main (it seems like) # so creating GUI executable fails and the linker silently reverts to the default, CUI subsystem target_link_options(${TARGET_NAME} PRIVATE -Wl,-subsystem:windows) target_link_options(${TARGET_NAME} PRIVATE -Wl,-entry:mainCRTStartup) endfunction() function(handle_msvc_style_compiler) # No console window when targeting windows target_link_options(${TARGET_NAME} PRIVATE /SUBSYSTEM:windows /ENTRY:mainCRTStartup) endfunction() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # GCC (MinGW) handle_gnu_style_compiler() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") # MSVC-style argument clang (clang-cl.exe) handle_msvc_style_compiler() elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU") # GNU-style argument clang (clang.exe and clang++.exe) handle_gnu_style_compiler() endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") handle_msvc_style_compiler() # Use updated __cplusplus macro # https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus target_compile_options(${TARGET_NAME} PUBLIC /Zc:__cplusplus) endif() endif() if(CMAKE_UNITY_BUILD) message("CpltCore: - using unity build") set_target_properties(${TARGET_NAME} PROPERTIES UNITY_BUILD_MODE GROUP) else() message("CpltCore: - using regular build") endif() endfunction() add_executable_variant(CpltCore_main) target_compile_definitions(CpltCore_main PRIVATE DOCTEST_CONFIG_DISABLE=1) add_executable_variant(CpltCore_test)