aboutsummaryrefslogtreecommitdiff
path: root/app/CMakeLists.txt
blob: fbbdfa1e1f47ab5a2fda0c2d63078aefd13faf2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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}/source/*.h
    ${CMAKE_CURRENT_LIST_DIR}/source/*.c
    ${CMAKE_CURRENT_LIST_DIR}/source/*.m
    ${CMAKE_CURRENT_LIST_DIR}/source/*.hpp
    ${CMAKE_CURRENT_LIST_DIR}/source/*.cpp
    ${CMAKE_CURRENT_LIST_DIR}/source/*.mm
)

add_executable(CpltCore ${CPLT_CORE_SOURCES_SPECIAL} ${CPLT_CORE_SOURCES_NORMAL})
set_target_properties(CpltCore
PROPERTIES
    CXX_STANDARD 20
    CXX_STANDARD_REQUIRED ON
    CXX_EXTENSIONS OFF
)

set(CPLT_CORE_SOURCES_NORMAL_UNITY_EXCLUDED
    source/Cplt/Entrypoint/main.cpp
    source/Cplt/Entrypoint/Backend_OpenGL2.cpp
    source/Cplt/Entrypoint/Backend_OpenGL3.cpp
    source/Cplt/Entrypoint/Backend_Vulkan.cpp
    source/Cplt/Entrypoint/Backend_DirectX11.cpp
    source/Cplt/Entrypoint/Backend_DirectX12.cpp
    source/Cplt/Entrypoint/Backend_Metal.mm
    source/Cplt/UI/UI_DatabaseView.cpp
    source/Cplt/UI/UI_Items.cpp
    source/Cplt/UI/UI_MainWindow.cpp
    source/Cplt/UI/UI_Settings.cpp
    source/Cplt/UI/UI_Templates.cpp
    source/Cplt/UI/UI_Utils.cpp
    source/Cplt/UI/UI_Workflows.cpp
    source/Cplt/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}/source
)
target_link_libraries(CpltCore
PRIVATE
    ${CONAN_LIBS}
    icon-font-headers
    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=$<BOOL:${BUILD_CORE_WITH_DX11_BACKEND}>
        BUILD_CORE_WITH_DX12_BACKEND=$<BOOL:${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=$<BOOL:${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=$<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}>
    )

    # 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()

target_flag_exceptions(CpltCore ON)
target_flag_rtti(CpltCore OFF)
target_use_windows_subsystem(CpltCore)

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()