option(BUILD_CORE_TESTS "Whether to make executable tests 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() message("CpltCore: generating executable CpltCore") 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_SPECIAL ${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_SPECIAL ${CMAKE_SOURCE_DIR}/3rdparty/imgui/backend/imgui_impl_win32.cpp ) endif() file(GLOB_RECURSE CPLT_CORE_SOURCES_NORMAL ${CMAKE_CURRENT_LIST_DIR}/src/*.h ${CMAKE_CURRENT_LIST_DIR}/src/*.c ${CMAKE_CURRENT_LIST_DIR}/src/*.m ${CMAKE_CURRENT_LIST_DIR}/src/*.hpp ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp ${CMAKE_CURRENT_LIST_DIR}/src/*.mm ) add_executable(CpltCore ${CPLT_CORE_SOURCES_SPECIAL} ${CPLT_CORE_SOURCES_NORMAL}) set(CPLT_CORE_SOURCES_NORMAL_UNITY_EXCLUDED 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 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 src/Utils/IO/FileStream.cpp ) set_source_files_properties( ${CPLT_CORE_SOURCES_SPECIAL} ${CPLT_CORE_SOURCES_NORMAL_UNITY_EXCLUDED} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON ) target_include_directories(CpltCore 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(CpltCore PRIVATE ${CONAN_LIBS} imgui implot imgui-node-editor SQLiteCpp ) if(NOT BUILD_CORE_TESTS) target_compile_definitions(CpltCore PRIVATE DOCTEST_CONFIG_DISABLE=1) endif() if(NOT TARGET_LOCALE STREQUAL "en_US") target_compile_definitions(CpltCore 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(CpltCore PRIVATE BUILD_CORE_WITH_DX11_BACKEND=$ BUILD_CORE_WITH_DX12_BACKEND=$ ) if(BUILD_CORE_WITH_DX11_BACKEND) target_link_libraries(CpltCore PRIVATE dxgi.lib d3d11.lib) endif() if(BUILD_CORE_WITH_DX12_BACKEND) target_link_libraries(CpltCore PRIVATE dxgi.lib d3d12.lib) endif() endif() if(APPLE) message("CpltCore: - building with Metal backend ${BUILD_CORE_WITH_METAL_BACKEND}") target_compile_definitions(CpltCore 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(CpltCore 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(CpltCore PRIVATE ${Vulkan_INCLUDE_DIRS}) target_link_libraries(CpltCore 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(CpltCore PRIVATE -Wl,-subsystem:windows) target_link_options(CpltCore PRIVATE -Wl,-entry:mainCRTStartup) endfunction() function(handle_msvc_style_compiler) # No console window when targeting windows target_link_options(CpltCore 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(CpltCore PUBLIC /Zc:__cplusplus) endif() endif() if(CMAKE_UNITY_BUILD) message("CpltCore: - using unity build") set_target_properties(CpltCore PROPERTIES UNITY_BUILD_MODE BATCH UNITY_BUILD_UNIQUE_ID "CPLT_UNITY_ID" ) else() message("CpltCore: - using regular build") endif()