-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
668 lines (602 loc) · 26.8 KB
/
CMakeLists.txt
File metadata and controls
668 lines (602 loc) · 26.8 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# Require a minimum CMake version of 3.14.0
# - Needed for improved C++17 support
# - Better handling of target_link_libraries
# - Enhanced find_package functionality
# - Improved generator expressions
# - Modern CMake best practices
# FATAL_ERROR will stop processing if a lower version is used
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
project(EzyCad)
# CMP0167: Use legacy FindBoost module (avoids "FindBoost module is removed" warning in CMake 3.30+)
if(POLICY CMP0167)
cmake_policy(SET CMP0167 OLD)
endif()
# Set C++20 as the required standard for all targets
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Add custom CMake modules path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
# Detect Emscripten early (for optional branching)
if(CMAKE_CXX_COMPILER MATCHES "em\\+\\+")
set(EMSCRIPTEN_BUILD TRUE)
endif()
# Python (optional embedded console) — native only.
set(EZYCAD_HAVE_PYTHON FALSE)
set(EZYCAD_PYTHON_LINK_MODE "")
set(EZYCAD_PYTHON_RUNTIME_DLL "")
if(NOT EMSCRIPTEN_BUILD)
option(EZYCAD_ENABLE_PYTHON "Embed Python console (requires Python 3 development libraries)" ON)
if(EZYCAD_ENABLE_PYTHON)
find_package(Python3 3.8 QUIET COMPONENTS Interpreter Development)
if(Python3_FOUND)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/EzyCadPython.cmake")
ezycad_configure_embedded_python()
if(EZYCAD_HAVE_PYTHON)
message(STATUS "Python console: enabled (${Python3_VERSION}, ${Python3_EXECUTABLE})")
endif()
else()
message(STATUS "Python console: disabled (Python 3 development libraries not found; set EZYCAD_ENABLE_PYTHON=OFF to silence)")
endif()
endif()
endif()
# Lua (for script console) - built for native and Emscripten (C sources compile with emcc)
# Tarball has no CMake; we build the lib from sources
include(FetchContent)
if(EZYCAD_HAVE_PYTHON)
set(PYBIND11_FINDPYTHON ON)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.13.6
)
FetchContent_MakeAvailable(pybind11)
endif()
FetchContent_Declare(
lua
URL https://www.lua.org/ftp/lua-5.4.6.tar.gz
)
FetchContent_Populate(lua)
set(LUA_SRC_DIR ${lua_SOURCE_DIR}/lua-5.4.6/src)
if(NOT EXISTS ${LUA_SRC_DIR})
set(LUA_SRC_DIR ${lua_SOURCE_DIR}/src)
endif()
if(NOT EXISTS ${LUA_SRC_DIR})
message(FATAL_ERROR "Lua source not found in ${lua_SOURCE_DIR}")
endif()
set(LUA_LIB_SOURCES
${LUA_SRC_DIR}/lapi.c ${LUA_SRC_DIR}/lcode.c ${LUA_SRC_DIR}/lctype.c
${LUA_SRC_DIR}/ldebug.c ${LUA_SRC_DIR}/ldo.c ${LUA_SRC_DIR}/ldump.c
${LUA_SRC_DIR}/lfunc.c ${LUA_SRC_DIR}/lgc.c ${LUA_SRC_DIR}/llex.c
${LUA_SRC_DIR}/lmem.c ${LUA_SRC_DIR}/lobject.c ${LUA_SRC_DIR}/lopcodes.c
${LUA_SRC_DIR}/lparser.c ${LUA_SRC_DIR}/lstate.c ${LUA_SRC_DIR}/lstring.c
${LUA_SRC_DIR}/ltable.c ${LUA_SRC_DIR}/ltm.c ${LUA_SRC_DIR}/lundump.c
${LUA_SRC_DIR}/lvm.c ${LUA_SRC_DIR}/lzio.c
${LUA_SRC_DIR}/lauxlib.c ${LUA_SRC_DIR}/lbaselib.c ${LUA_SRC_DIR}/lcorolib.c
${LUA_SRC_DIR}/ldblib.c ${LUA_SRC_DIR}/liolib.c ${LUA_SRC_DIR}/lmathlib.c
${LUA_SRC_DIR}/loadlib.c ${LUA_SRC_DIR}/loslib.c ${LUA_SRC_DIR}/lstrlib.c
${LUA_SRC_DIR}/ltablib.c ${LUA_SRC_DIR}/lutf8lib.c ${LUA_SRC_DIR}/linit.c
)
add_library(lua STATIC ${LUA_LIB_SOURCES})
target_include_directories(lua PUBLIC ${LUA_SRC_DIR})
target_compile_features(lua PUBLIC c_std_99)
# Set binary directory paths
# Combines CMAKE_BINARY_DIR and project-specific binary dir for flexibility
set(BINARY_DIR ${${PROJECT_NAME}_BINARY_DIR})
# Detect if we're using Emscripten compiler (for WebAssembly builds)
if(CMAKE_CXX_COMPILER MATCHES "/em\\+\\+(-[a-zA-Z0-9.])?(\.bat)?$")
message(" * C++ compiler: Emscripten")
set(CMAKE_CXX_COMPILER_ID "Emscripten")
else()
message(" * C++ compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
set(GLFW_VERSION "3.3.0.1")
set(GLEW_VERSION "2.1.0")
set(BOOST_VERSION "1.87.0")
if(MSVC_VERSION)
find_program(NUGET nuget)
if(NOT NUGET)
message(FATAL_ERROR "Cannot find nuget command line tool.\nInstall it with e.g. choco install nuget.commandline")
endif()
# Output must be under the build tree (CMAKE_BINARY_DIR), not the shell CWD, or clean out-of-source configures fail.
execute_process(COMMAND ${NUGET} install glfw -Version ${GLFW_VERSION} -OutputDirectory "${CMAKE_BINARY_DIR}/thirdParty")
execute_process(COMMAND ${NUGET} install unofficial-flayan-glew -Version ${GLEW_VERSION} -OutputDirectory "${CMAKE_BINARY_DIR}/thirdParty")
execute_process(COMMAND ${NUGET} install boost -Version ${BOOST_VERSION} -OutputDirectory "${CMAKE_BINARY_DIR}/thirdParty")
# Include Boost from NuGet installation on Windows
INCLUDE_DIRECTORIES(${PROJECT_NAME} ${BINARY_DIR}/thirdParty/boost.${BOOST_VERSION}/lib/native/include)
else()
# On Linux, use system Boost installation
find_package(Boost REQUIRED)
if(Boost_FOUND)
INCLUDE_DIRECTORIES(${PROJECT_NAME} ${Boost_INCLUDE_DIRS})
endif()
endif()
# imgui_demo.cpp omitted: large and unused here; add back if you need ImGui::ShowDemoWindow.
file(GLOB imguiSrc
"third_party/imgui/imgui_impl_glfw.cpp"
"third_party/imgui/imgui_impl_opengl3.cpp"
"third_party/imgui/imgui.cpp"
"third_party/imgui/imgui_draw.cpp"
"third_party/imgui/imgui_widgets.cpp"
"third_party/imgui/imgui_tables.cpp"
"third_party/imgui/emscripten/emscripten_mainloop_stub.h")
file(GLOB srcs CONFIGURE_DEPENDS "src/*.cpp" "src/*.h" "src/*.inl")
#list(FILTER srcs EXCLUDE REGEX ".*main\\.cpp$")
get_filename_component(full_path_main_cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp ABSOLUTE)
list(REMOVE_ITEM srcs ${full_path_main_cpp})
# Ensure settings.cpp is always in the library (persistence for native + Emscripten)
set(settings_cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/settings.cpp)
list(REMOVE_ITEM srcs "src/settings.cpp" ${settings_cpp})
list(APPEND srcs ${settings_cpp})
set(gui_settings_cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/gui_settings.cpp)
list(REMOVE_ITEM srcs "src/gui_settings.cpp" ${gui_settings_cpp})
list(APPEND srcs ${gui_settings_cpp})
set(gui_mode_cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/gui_mode.cpp)
list(REMOVE_ITEM srcs "src/gui_mode.cpp" ${gui_mode_cpp})
list(APPEND srcs ${gui_mode_cpp})
# Define source files for the application
# Including ImGui sources and main application file
set(App_SRCS ${imguiSrc} ${srcs})
set(EZYCAD_IMGUI_TEXT_EDITOR_CPP "${CMAKE_SOURCE_DIR}/third_party/ImGuiColorTextEdit/TextEditor.cpp")
if(NOT EXISTS "${EZYCAD_IMGUI_TEXT_EDITOR_CPP}")
# Pinned commit (upstream has no release tags); bump when intentionally upgrading the editor.
FetchContent_Declare(
ImGuiColorTextEdit
GIT_REPOSITORY https://github.com/BalazsJako/ImGuiColorTextEdit.git
GIT_TAG ca2f9f1462e3b60e56351bc466acda448c5ea50d
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(ImGuiColorTextEdit)
set(_ige_fetch "${imguicolortextedit_SOURCE_DIR}")
set(_ige_stage "${CMAKE_BINARY_DIR}/ImGuiColorTextEdit_fetch/ImGuiColorTextEdit")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/ImGuiColorTextEdit_fetch")
file(COPY "${_ige_fetch}/" DESTINATION "${_ige_stage}")
set(EZYCAD_IMGUI_TEXT_EDITOR_CPP "${_ige_stage}/TextEditor.cpp")
include_directories("${CMAKE_BINARY_DIR}/ImGuiColorTextEdit_fetch")
if(NOT EXISTS "${EZYCAD_IMGUI_TEXT_EDITOR_CPP}")
message(FATAL_ERROR "ImGuiColorTextEdit fetch did not provide TextEditor.cpp (see third_party/README.md).")
endif()
endif()
list(APPEND App_SRCS "${EZYCAD_IMGUI_TEXT_EDITOR_CPP}")
# Configure platform-specific GUI settings
# WIN32 for Windows GUI application
# MACOSX_BUNDLE for MacOS GUI application
if(WIN32)
set(GUI_TYPE WIN32)
endif(WIN32)
if(APPLE)
set(GUI_TYPE MACOSX_BUNDLE)
endif(APPLE)
add_library(${PROJECT_NAME}_lib ${App_SRCS} ${imguiImplSrcs} third_party/tinyfiledialogs/tinyfiledialogs.c)
target_link_libraries(${PROJECT_NAME}_lib PUBLIC lua)
if(EZYCAD_HAVE_PYTHON)
target_compile_definitions(${PROJECT_NAME}_lib PRIVATE EZYCAD_HAVE_PYTHON=1)
if(EZYCAD_PYTHON_LINK_MODE STREQUAL "imported_target")
target_link_libraries(${PROJECT_NAME}_lib PUBLIC ezycad_embed_python)
target_link_libraries(${PROJECT_NAME}_lib PRIVATE pybind11::pybind11)
elseif(EZYCAD_PYTHON_LINK_MODE STREQUAL "python3_target")
target_link_libraries(${PROJECT_NAME}_lib PUBLIC Python3::Python)
target_link_libraries(${PROJECT_NAME}_lib PRIVATE pybind11::embed)
else()
message(FATAL_ERROR "EZYCAD_HAVE_PYTHON is ON but EZYCAD_PYTHON_LINK_MODE is not set.")
endif()
endif()
# Open CASCADE Technology
find_package(OpenCASCADE REQUIRED NO_DEFAULT_PATH)
if(OpenCASCADE_FOUND)
message (STATUS "Using OpenCASCADE from \"${OpenCASCADE_DIR}\"" )
INCLUDE_DIRECTORIES(${PROJECT_NAME} ${OpenCASCADE_INCLUDE_DIR})
LINK_DIRECTORIES(${PROJECT_NAME} ${OpenCASCADE_LIBRARY_DIR})
else()
message(WARNING "Could not find OpenCASCADE, please set OpenCASCADE_DIR variable." )
set(OCCT_LIBRARY_DIR)
set(OCCT_BIN_DIR)
endif()
# OCCT 3rd-party DLL path must not contain backticks — a common mistake is pasting
# -DOCCT_3RD_PARTY_DIR=... from Markdown and including the closing ` of `...`.
if(DEFINED OCCT_3RD_PARTY_DIR)
string(REGEX REPLACE "[`]" "" OCCT_3RD_PARTY_DIR "${OCCT_3RD_PARTY_DIR}")
string(STRIP "${OCCT_3RD_PARTY_DIR}" OCCT_3RD_PARTY_DIR)
set(OCCT_3RD_PARTY_DIR "${OCCT_3RD_PARTY_DIR}" CACHE PATH "OCCT 3rd-party DLL root (freetype, ffmpeg, …)" FORCE)
endif()
file(GLOB ICON_ASSETS CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/res/icons/*.png")
file(GLOB WEB_FILES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/web/*.html")
set(WEB_FILES_REL)
foreach(f ${WEB_FILES})
file(RELATIVE_PATH f_rel "${CMAKE_SOURCE_DIR}" "${f}")
list(APPEND WEB_FILES_REL "${f_rel}")
endforeach()
set(OpenCASCADE_LIBS
TKFillet
TKOffset
TKRWMesh
TKDEGLTF
TKDEOBJ
TKDEPLY
TKBinXCAF
TKBin
TKBinL
TKXCAF
TKVCAF
TKCAF
TKV3d
TKHLR
TKMesh
TKService
TKShHealing
TKPrim
TKTopAlgo
TKGeomAlgo
TKBRep
TKGeomBase
TKG3d
TKG2d
TKMath
TKLCAF
TKCDF
TKernel
TKDESTEP
TKDEIGES
TKDESTL)
# Configure Emscripten-specific settings if using Emscripten compiler
if(CMAKE_CXX_COMPILER_ID STREQUAL "Emscripten")
# Set compiler flags for Emscripten build
message("flags " ${CMAKE_CXX_FLAGS} )
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-s USE_SDL=2 \
-s USE_BOOST_HEADERS=1 \
-fexceptions \
-O3"
)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \
--bind \
-s ALLOW_MEMORY_GROWTH=1 \
-s NO_EXIT_RUNTIME=0 \
-fexceptions \
-s ASSERTIONS=1 \
-O3 \
-s FULL_ES3=1 \
-s USE_WEBGL2=1 \
-s USE_GLFW=3 \
-s USE_ZLIB=1 \
-s EXPORTED_FUNCTIONS=\"['_main', '_on_file_selected', '_on_import_file_selected', '_on_sketch_underlay_selected', '_on_save_file_selected', '_emscripten_save_settings_on_unload']\" \
-s EXPORTED_RUNTIME_METHODS=\"['ccall']\" \
-s FETCH=1 \
--preload-file ${CMAKE_SOURCE_DIR}/third_party/imgui/fonts/DroidSans.ttf@/DroidSans.ttf \
--preload-file ${CMAKE_SOURCE_DIR}/third_party/imgui/fonts/Cousine-Regular.ttf@/Cousine-Regular.ttf \
--preload-file ${CMAKE_SOURCE_DIR}/imgui.ini@/imgui.ini \
--preload-file ${CMAKE_SOURCE_DIR}/res/ezycad_settings.json@/res/ezycad_settings.json \
--preload-file ${CMAKE_SOURCE_DIR}/res/default.ezy@/res/default.ezy \
--preload-file ${CMAKE_SOURCE_DIR}/res/examples@/res/examples \
--preload-file ${CMAKE_SOURCE_DIR}/res/scripts/lua@/res/scripts/lua \
--shell-file ${CMAKE_SOURCE_DIR}/web/EzyCad.html"
)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG} \
-s USE_SDL=2 \
-s USE_BOOST_HEADERS=1 \
-fexceptions \
-gsource-map \
-O0"
)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \
--bind \
-s ALLOW_MEMORY_GROWTH=1 \
-s NO_EXIT_RUNTIME=0 \
-fexceptions \
-s ASSERTIONS=1 \
-gsource-map \
--source-map-base http://localhost:8000/ \
-O0 \
-s FULL_ES3=1 \
-s USE_WEBGL2=1 \
-s USE_GLFW=3 \
-s USE_ZLIB=1 \
-s EXPORTED_FUNCTIONS=\"['_main', '_on_file_selected', '_on_import_file_selected', '_on_sketch_underlay_selected', '_on_save_file_selected', '_emscripten_save_settings_on_unload']\" \
-s EXPORTED_RUNTIME_METHODS=\"['ccall']\" \
-s FETCH=1 \
--preload-file ${CMAKE_SOURCE_DIR}/third_party/imgui/fonts/DroidSans.ttf@/DroidSans.ttf \
--preload-file ${CMAKE_SOURCE_DIR}/third_party/imgui/fonts/Cousine-Regular.ttf@/Cousine-Regular.ttf \
--preload-file ${CMAKE_SOURCE_DIR}/imgui.ini@/imgui.ini \
--preload-file ${CMAKE_SOURCE_DIR}/res/ezycad_settings.json@/res/ezycad_settings.json \
--preload-file ${CMAKE_SOURCE_DIR}/res/default.ezy@/res/default.ezy \
--preload-file ${CMAKE_SOURCE_DIR}/res/examples@/res/examples \
--preload-file ${CMAKE_SOURCE_DIR}/res/scripts/lua@/res/scripts/lua \
--shell-file ${CMAKE_SOURCE_DIR}/web/EzyCad.html"
)
endif()
# Add each ICON_ASSETS file to the preload flags
foreach(icon_file ${ICON_ASSETS})
get_filename_component(icon_filename ${icon_file} NAME)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} \
--preload-file ${icon_file}@/res/icons/${icon_filename}")
endforeach()
list(APPEND OpenCASCADE_LIBS TKOpenGles)
add_executable(${PROJECT_NAME}
"src/main.cpp"
${App_SRCS}
${imguiImplSrcs}
third_party/tinyfiledialogs/tinyfiledialogs.c)
# Copy EzyCad.html and default settings to the build directory for Emscripten
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/web/EzyCad.html
$<TARGET_FILE_DIR:${PROJECT_NAME}>/EzyCad.html
COMMENT "Copying EzyCad.html to build directory"
)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${PROJECT_NAME}>/res
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/res/ezycad_settings.json
$<TARGET_FILE_DIR:${PROJECT_NAME}>/res/ezycad_settings.json
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/res/default.ezy
$<TARGET_FILE_DIR:${PROJECT_NAME}>/res/default.ezy
COMMENT "Copying res/ezycad_settings.json and res/default.ezy for Emscripten"
)
file(GLOB RES_EXAMPLE_FILES_EM "${CMAKE_SOURCE_DIR}/res/examples/*.ezy")
if(RES_EXAMPLE_FILES_EM)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${PROJECT_NAME}>/res/examples
COMMENT "Creating res/examples for Emscripten"
)
foreach(example_file ${RES_EXAMPLE_FILES_EM})
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${example_file}
$<TARGET_FILE_DIR:${PROJECT_NAME}>/res/examples/
COMMENT "Copying example for Emscripten"
)
endforeach()
endif()
target_link_libraries(
${PROJECT_NAME}
lua
${OpenCASCADE_LIBS})
else()
list(APPEND OpenCASCADE_LIBS TKOpenGl)
set(GLEW_LOCATION ${BINARY_DIR}/thirdParty/unofficial-flayan-glew.${GLEW_VERSION}/build/native)
set(GLFW_ROOT_DIR ${BINARY_DIR}/thirdParty/glfw.${GLFW_VERSION}/build/native)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
# For non-Emscripten builds, find and link required libraries
find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)
add_executable(${PROJECT_NAME} "src/main.cpp")
# Copy default settings and examples so native build finds res/ at runtime
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${PROJECT_NAME}>/res
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/res/ezycad_settings.json
$<TARGET_FILE_DIR:${PROJECT_NAME}>/res/ezycad_settings.json
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/res/default.ezy
$<TARGET_FILE_DIR:${PROJECT_NAME}>/res/default.ezy
COMMENT "Copying res/ezycad_settings.json and res/default.ezy for native"
)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${PROJECT_NAME}>/res/icons
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/res/icons
$<TARGET_FILE_DIR:${PROJECT_NAME}>/res/icons
COMMENT "Copying res/icons for native")
file(GLOB RES_EXAMPLE_FILES "${CMAKE_SOURCE_DIR}/res/examples/*.ezy")
if(RES_EXAMPLE_FILES)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${PROJECT_NAME}>/res/examples
COMMENT "Creating res/examples for native"
)
foreach(example_file ${RES_EXAMPLE_FILES})
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${example_file}
$<TARGET_FILE_DIR:${PROJECT_NAME}>/res/examples/
COMMENT "Copying example ${example_file}"
)
endforeach()
endif()
file(GLOB RES_LUA_SCRIPTS "${CMAKE_SOURCE_DIR}/res/scripts/lua/*.lua")
if(RES_LUA_SCRIPTS)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${PROJECT_NAME}>/res/scripts/lua
COMMENT "Creating res/scripts/lua for native"
)
foreach(lua_file ${RES_LUA_SCRIPTS})
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${lua_file}
$<TARGET_FILE_DIR:${PROJECT_NAME}>/res/scripts/lua/
COMMENT "Copying Lua script ${lua_file}"
)
endforeach()
endif()
file(GLOB RES_PYTHON_SCRIPTS "${CMAKE_SOURCE_DIR}/res/scripts/python/*.py")
if(RES_PYTHON_SCRIPTS)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${PROJECT_NAME}>/res/scripts/python
COMMENT "Creating res/scripts/python for native"
)
foreach(py_file ${RES_PYTHON_SCRIPTS})
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${py_file}
$<TARGET_FILE_DIR:${PROJECT_NAME}>/res/scripts/python/
COMMENT "Copying Python script ${py_file}"
)
endforeach()
endif()
target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_lib)
target_link_libraries(${PROJECT_NAME} ${BINARY_DIR}/thirdParty/unofficial-flayan-glew.${GLEW_VERSION}/build/native/lib/x64/dynamic/glew32.lib)
target_link_libraries(${PROJECT_NAME} ${GLFW3_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${OpenCASCADE_LIBS})
if(EZYCAD_HAVE_PYTHON AND EZYCAD_PYTHON_LINK_MODE STREQUAL "imported_target"
AND EZYCAD_PYTHON_RUNTIME_DLL AND EXISTS "${EZYCAD_PYTHON_RUNTIME_DLL}")
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${EZYCAD_PYTHON_RUNTIME_DLL}"
$<TARGET_FILE_DIR:${PROJECT_NAME}>
COMMENT "Copy Python DLL next to EzyCad.exe")
endif()
include_directories(${BINARY_DIR}/thirdParty/unofficial-flayan-glew.${GLEW_VERSION}/build/native/include)
include_directories(${GLFW3_INCLUDE_PATH})
# MSVC-specific configuration
if(MSVC_VERSION)
message("Compiler is MSVC")
# Set working directory for Visual Studio debugging
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
# Configure MSVC compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHc /MP")
set(DLLS_COMMON
${BINARY_DIR}/thirdParty/unofficial-flayan-glew.redist.${GLEW_VERSION}/build/native/bin/x64/dynamic/glew32.dll
${BINARY_DIR}/thirdParty/glfw.${GLFW_VERSION}/build/native/bin/dynamic/v142/x64/glfw3.dll
${OpenCASCADE_BINARY_DIR}/TKBO.dll
${OpenCASCADE_BINARY_DIR}/TKBool.dll
${OpenCASCADE_BINARY_DIR}/TKXSBase.dll
${OpenCASCADE_BINARY_DIR}/TKDE.dll
${OCCT_3RD_PARTY_DIR}/freetype-2.13.3-x64/bin/freetype.dll
${OCCT_3RD_PARTY_DIR}/freeimage-3.18.0-x64/bin/FreeImage.dll
${OCCT_3RD_PARTY_DIR}/openvr-1.14.15-64/bin/win64/openvr_api.dll
${OCCT_3RD_PARTY_DIR}/ffmpeg-3.3.4-64/bin/avcodec-57.dll
${OCCT_3RD_PARTY_DIR}/ffmpeg-3.3.4-64/bin/avformat-57.dll
${OCCT_3RD_PARTY_DIR}/ffmpeg-3.3.4-64/bin/avutil-55.dll
${OCCT_3RD_PARTY_DIR}/ffmpeg-3.3.4-64/bin/swscale-4.dll
${OCCT_3RD_PARTY_DIR}/tbb-2021.13.0-x64/bin/tbb12.dll
${OCCT_3RD_PARTY_DIR}/jemalloc-vc14-64/bin/jemalloc.dll
)
foreach(lib ${OpenCASCADE_LIBS})
list(APPEND DLLS_COMMON ${OpenCASCADE_BINARY_DIR}/${lib}.dll)
endforeach(lib)
set(FONT_ASSETS
${CMAKE_SOURCE_DIR}/third_party/imgui/fonts/DroidSans.ttf
${CMAKE_SOURCE_DIR}/third_party/imgui/fonts/Cousine-Regular.ttf)
set(CONFIG_ASSETS ${CMAKE_SOURCE_DIR}/imgui.ini)
# Copy DLLs and assets to Release configurations
foreach(file ${DLLS_RELEASE} ${DLLS_COMMON} ${FONT_ASSETS} ${CONFIG_ASSETS})
file(COPY "${file}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/Release")
file(COPY "${file}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo")
file(COPY "${file}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/MinSizeRel")
endforeach(file)
# Copy DLLs and assets to Debug configuration
foreach(file ${DLLS_DEBUG} ${DLLS_COMMON} ${FONT_ASSETS} ${CONFIG_ASSETS})
file(COPY "${file}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/Debug")
endforeach(file)
endif()
endif()
# Platform-specific configurations
if(WIN32)
# Windows-specific linking (TBB commented out)
#target_link_libraries(${PROJECT_NAME} debug ${TBB_tbb_LIBRARY_DEBUG} optimized ${TBB_tbb_LIBRARY_RELEASE})
endif(WIN32)
if(APPLE)
# MacOS-specific linking for OpenGL and system frameworks
SET(CMAKE_CXX_LINK_FLAGS "-framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo")
endif(APPLE)
# Add include directories for all third-party dependencies
include_directories(.)
include_directories("third_party")
include_directories("third_party/imgui")
include_directories("third_party/json/include")
# Define preprocessor macros for GLM
add_definitions(-DGLM_ENABLE_EXPERIMENTAL)
add_definitions(-DGLM_FORCE_RADIANS)
# Link OpenGL libraries
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} ${OPENGL_gl_LIBRARY})
source_group("imgui" FILES ${imguiSrc})
source_group("src" FILES ${srcs})
source_group("web" FILES ${WEB_FILES_REL})
# Add README to VS solution
if(MSVC)
# Create a source group for documentation files
set(DOC_FILES
${CMAKE_CURRENT_SOURCE_DIR}/README.md
${CMAKE_CURRENT_SOURCE_DIR}/ezycad_code_style.md
${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md
${CMAKE_CURRENT_SOURCE_DIR}/usage.md
${CMAKE_CURRENT_SOURCE_DIR}/usage-settings.md
${CMAKE_CURRENT_SOURCE_DIR}/usage-sketch.md
${CMAKE_CURRENT_SOURCE_DIR}/scripting.md
${CMAKE_CURRENT_SOURCE_DIR}/bugs.md
${CMAKE_CURRENT_SOURCE_DIR}/LICENSE
)
#source_group("Documentation" FILES ${DOC_FILES})
# Add to project but exclude from build
target_sources(${PROJECT_NAME} PRIVATE ${DOC_FILES})
set_source_files_properties(${DOC_FILES} PROPERTIES HEADER_FILE_ONLY TRUE)
endif()
# Add Google Test only for non-Emscripten builds
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Emscripten")
# Download and configure Google Test
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1 # Adjust version as needed
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# Enable testing
enable_testing()
# Create a test executable
file(GLOB TEST_SRCS CONFIGURE_DEPENDS "tests/*.cpp" "tests/*.h")
add_executable(${PROJECT_NAME}_tests ${TEST_SRCS})
# Add src directory to include paths for tests
target_include_directories(${PROJECT_NAME}_tests PRIVATE
${CMAKE_SOURCE_DIR}/src
)
# Link against Google Test and your project's libraries
target_link_libraries(${PROJECT_NAME}_tests
GTest::gtest_main
GTest::gmock_main
${GLFW3_LIBRARY}
${PROJECT_NAME}_lib
${OpenCASCADE_LIBS}
${OPENGL_LIBRARIES}
${OPENGL_gl_LIBRARY}
)
# Add tests to CTest
include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME}_tests)
endif()
# web/*.html listed in IDE (single target_sources; Emscripten + native)
if(WEB_FILES_REL)
target_sources(${PROJECT_NAME} PRIVATE ${WEB_FILES_REL})
endif()
# Runtime assets: show res/ in the IDE (matches POST_BUILD copy to output dir)
file(GLOB_RECURSE RES_FILES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/res/*")
if(RES_FILES)
source_group(TREE "${CMAKE_SOURCE_DIR}/res" PREFIX "res" FILES ${RES_FILES})
set(RES_FILES_REL)
foreach(f ${RES_FILES})
file(RELATIVE_PATH f_rel "${CMAKE_SOURCE_DIR}" "${f}")
list(APPEND RES_FILES_REL "${f_rel}")
endforeach()
target_sources(${PROJECT_NAME} PRIVATE ${RES_FILES_REL})
set_source_files_properties(${RES_FILES_REL} PROPERTIES HEADER_FILE_ONLY TRUE)
endif()
# Add .clang-format and .gitignore to EzyCad and EzyCad_lib so they appear in VS and other IDEs (at project root)
set(CLANG_FORMAT_FILE ${CMAKE_SOURCE_DIR}/.clang-format)
if(EXISTS ${CLANG_FORMAT_FILE})
source_group("" FILES ${CLANG_FORMAT_FILE})
target_sources(${PROJECT_NAME}_lib PRIVATE ${CLANG_FORMAT_FILE})
target_sources(${PROJECT_NAME} PRIVATE ${CLANG_FORMAT_FILE})
set_source_files_properties(${CLANG_FORMAT_FILE} PROPERTIES HEADER_FILE_ONLY TRUE)
endif()
set(GITIGNORE_FILE ${CMAKE_SOURCE_DIR}/.gitignore)
if(EXISTS ${GITIGNORE_FILE})
source_group("" FILES ${GITIGNORE_FILE})
target_sources(${PROJECT_NAME}_lib PRIVATE ${GITIGNORE_FILE})
target_sources(${PROJECT_NAME} PRIVATE ${GITIGNORE_FILE})
set_source_files_properties(${GITIGNORE_FILE} PROPERTIES HEADER_FILE_ONLY TRUE)
endif()