summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/CMakeLists.txt242
1 files changed, 119 insertions, 123 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 6cdac70..ff2adff 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -1,8 +1,7 @@
# 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)
+option(BUILD_CORE_TESTS "Whether to make executable tests or not." OFF)
set(TARGET_LOCALE "en_US" CACHE STRING "Locale to build.")
@@ -95,138 +94,135 @@ list(APPEND CPLT_CORE_SOURCES
src/Utils/IO/FileStream.cpp
)
-function(add_executable_variant TARGET_NAME)
- message("CpltCore: generating executable ${TARGET_NAME}")
+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
- ${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
- SQLiteCpp
- )
+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()
- 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()
+add_executable(CpltCore ${CPLT_CORE_SOURCES})
+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(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=$<BOOL:${BUILD_CORE_WITH_DX11_BACKEND}>
- BUILD_CORE_WITH_DX12_BACKEND=$<BOOL:${BUILD_CORE_WITH_DX12_BACKEND}>
- )
+if(NOT BUILD_CORE_TESTS)
+ target_compile_definitions(CpltCore PRIVATE DOCTEST_CONFIG_DISABLE=1)
+endif()
- 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(NOT TARGET_LOCALE STREQUAL "en_US")
+ target_compile_definitions(CpltCore
+ PRIVATE
+ TARGET_LOCALE=${TARGET_LOCALE}
+ TARGET_LOCALE_FILE="Locale/${TARGET_LOCALE}.h"
+ )
+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=$<BOOL:${BUILD_CORE_WITH_METAL_BACKEND}>
- )
- 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=$<BOOL:${BUILD_CORE_WITH_DX11_BACKEND}>
+ BUILD_CORE_WITH_DX12_BACKEND=$<BOOL:${BUILD_CORE_WITH_DX12_BACKEND}>
+ )
- 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=$<BOOL:${BUILD_CORE_WITH_OPENGL2_BACKEND}>
- BUILD_CORE_WITH_OPENGL3_BACKEND=$<BOOL:${BUILD_CORE_WITH_OPENGL3_BACKEND}>
- BUILD_CORE_WITH_VULKAN_BACKEND=$<BOOL:${BUILD_CORE_WITH_VULKAN_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()
- # 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(APPLE)
+ message("CpltCore: - building with Metal backend ${BUILD_CORE_WITH_METAL_BACKEND}")
+ target_compile_definitions(CpltCore
+ PRIVATE
+ BUILD_CORE_WITH_METAL_BACKEND=$<BOOL:${BUILD_CORE_WITH_METAL_BACKEND}>
+ )
+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()
+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=$<BOOL:${BUILD_CORE_WITH_OPENGL2_BACKEND}>
+ BUILD_CORE_WITH_OPENGL3_BACKEND=$<BOOL:${BUILD_CORE_WITH_OPENGL3_BACKEND}>
+ BUILD_CORE_WITH_VULKAN_BACKEND=$<BOOL:${BUILD_CORE_WITH_VULKAN_BACKEND}>
+ )
- function(handle_msvc_style_compiler)
- # No console window when targeting windows
- target_link_options(${TARGET_NAME} PRIVATE /SUBSYSTEM:windows /ENTRY:mainCRTStartup)
- endfunction()
+ # 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(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()
+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()
- # 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()
+ function(handle_msvc_style_compiler)
+ # No console window when targeting windows
+ target_link_options(CpltCore PRIVATE /SUBSYSTEM:windows /ENTRY:mainCRTStartup)
+ endfunction()
- if(CMAKE_UNITY_BUILD)
- message("CpltCore: - using unity build")
- set_target_properties(${TARGET_NAME} PROPERTIES
- UNITY_BUILD_MODE GROUP
- UNITY_BUILD_UNIQUE_ID "CPLT_UNITY_ID"
- )
- else()
- message("CpltCore: - using regular build")
- endif()
-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()
-add_executable_variant(CpltCore_main)
-target_compile_definitions(CpltCore_main PRIVATE DOCTEST_CONFIG_DISABLE=1)
+ # Use updated __cplusplus macro
+ # https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus
+ target_compile_options(CpltCore PUBLIC /Zc:__cplusplus)
+ endif()
+endif()
-add_executable_variant(CpltCore_test)
+if(CMAKE_UNITY_BUILD)
+ message("CpltCore: - using unity build")
+ set_target_properties(CpltCore PROPERTIES
+ UNITY_BUILD_MODE GROUP
+ UNITY_BUILD_UNIQUE_ID "CPLT_UNITY_ID"
+ )
+else()
+ message("CpltCore: - using regular build")
+endif()