-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
200 lines (170 loc) · 6.39 KB
/
CMakeLists.txt
File metadata and controls
200 lines (170 loc) · 6.39 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
cmake_minimum_required(VERSION 3.14)
# Set C++ standard BEFORE project() to ensure it's applied correctly
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Enable C language support for standard headers like float.h
project(OpenGL_loader LANGUAGES CXX C)
# Use FetchContent to download GLFW
include(FetchContent)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG 3.3.8
)
FetchContent_MakeAvailable(glfw)
# Find OpenGL
find_package(OpenGL QUIET)
# Collect all source files
file(GLOB_RECURSE SRC_FILES
"src/*.cpp"
"src/*.c"
)
# Explicitly ensure critical files are included (GLOB_RECURSE should find them, but explicit inclusion ensures they're always compiled)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/io/fbx_rig_analyzer.cpp")
list(APPEND SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/io/fbx_rig_analyzer.cpp")
endif()
# Explicitly ensure scene.cpp is included (critical for Scene::init)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/io/scene.cpp")
list(APPEND SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/io/scene.cpp")
endif()
# Explicitly ensure viewport_selection.cpp is included (critical for ViewportSelectionManager)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/viewport_selection.cpp")
list(APPEND SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/viewport_selection.cpp")
endif()
# Explicitly ensure debug_panel.cpp is included (critical for DebugPanel)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/io/ui/debug_panel.cpp")
list(APPEND SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/io/ui/debug_panel.cpp")
endif()
# Explicitly ensure logger.cpp is included (critical for Logger singleton)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/utils/logger.cpp")
list(APPEND SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/utils/logger.cpp")
endif()
# Remove duplicates in case GLOB already found them
list(REMOVE_DUPLICATES SRC_FILES)
file(GLOB IMGUI_SOURCES
"Dependencies/imgui/*.cpp"
)
file(GLOB OPENFBX_SOURCES
"Dependencies/openFBX/*.cpp"
"Dependencies/openFBX/*.c"
)
file(GLOB IMGUIZMO_SOURCES
"Dependencies/ImGuizmo/*.cpp"
)
# Create executable with all source files
add_executable(OpenGL_loader
${SRC_FILES}
${IMGUI_SOURCES}
${OPENFBX_SOURCES}
${IMGUIZMO_SOURCES}
Dependencies/include/glm/detail/glm.cpp
Dependencies/lib/gl3w/GL/gl3w.c
Dependencies/lib/usynergy/uSynergy.c
)
# Configure include directories
target_include_directories(OpenGL_loader PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Dependencies
${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/imgui
${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/ImGuizmo
${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/include
${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/openFBX
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/lib/gl3w
${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/lib/gl3w/GL
)
# Define preprocessor macros
target_compile_definitions(OpenGL_loader PRIVATE
IMGUI_IMPL_OPENGL_LOADER_GLAD
)
# Generate compile_commands.json for better IntelliSense support
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Add GLFW include directory
target_include_directories(OpenGL_loader PRIVATE
${glfw_SOURCE_DIR}/include
)
# Add OpenGL include directories if found
if(OpenGL_FOUND)
target_include_directories(OpenGL_loader PRIVATE
${OPENGL_INCLUDE_DIRS}
)
endif()
# Link libraries
target_link_libraries(OpenGL_loader PRIVATE
glfw
)
# Link OpenGL
if(OpenGL_FOUND)
target_link_libraries(OpenGL_loader PRIVATE
OpenGL::GL
)
else()
# Fallback for systems where find_package doesn't work
if(WIN32)
target_link_libraries(OpenGL_loader PRIVATE
opengl32
)
else()
# Linux/Unix fallback
target_link_libraries(OpenGL_loader PRIVATE
GL
)
endif()
endif()
# Link Assimp if available
# Use v142 for Visual Studio 2019
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/lib/assimp/assimp-vc142-mt.lib")
target_link_libraries(OpenGL_loader PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/lib/assimp/assimp-vc142-mt.lib"
)
target_include_directories(OpenGL_loader PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/include/assimp"
)
set(ASSIMP_DLL_NAME "assimp-vc142-mt.dll")
message(STATUS "Using Assimp v142 (VS 2019)")
else()
message(WARNING "Assimp v142 library not found! Animation may not work correctly.")
endif()
# Windows-specific libraries
if(WIN32)
target_link_libraries(OpenGL_loader PRIVATE
legacy_stdio_definitions
)
# Hide console window for Release builds (Windows subsystem)
# Only applies to Release configuration, Debug keeps console for debugging
if(MSVC)
# Use generator expression to only apply to Release builds
set_target_properties(OpenGL_loader PROPERTIES
LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup"
)
message(STATUS "Console window will be hidden in Release builds (Windows subsystem)")
endif()
# Copy required DLLs to output directory
# Always copy zlib.dll if it exists
if(EXISTS "${CMAKE_SOURCE_DIR}/Dependencies/zlib.dll")
add_custom_command(TARGET OpenGL_loader POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/Dependencies/zlib.dll"
"$<TARGET_FILE_DIR:OpenGL_loader>"
COMMENT "Copying zlib.dll to output directory"
)
endif()
# Copy Assimp DLL if available
if(DEFINED ASSIMP_DLL_NAME AND EXISTS "${CMAKE_SOURCE_DIR}/Dependencies/${ASSIMP_DLL_NAME}")
add_custom_command(TARGET OpenGL_loader POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/Dependencies/${ASSIMP_DLL_NAME}"
"$<TARGET_FILE_DIR:OpenGL_loader>"
COMMENT "Copying ${ASSIMP_DLL_NAME} to output directory"
)
endif()
# Copy Assets folder to output directory
# CRITICAL: Use copy_directory which will update all files, including shaders
# This ensures shader changes are always copied to the build directory on every build
add_custom_command(TARGET OpenGL_loader POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/Assets"
"$<TARGET_FILE_DIR:OpenGL_loader>/Assets"
COMMENT "Copying Assets directory (including shaders) to build directory"
)
endif()