-
Notifications
You must be signed in to change notification settings - Fork 23
/
CMakeLists.txt
118 lines (106 loc) · 3.04 KB
/
CMakeLists.txt
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
cmake_minimum_required (VERSION 3.1)
project(AppTinyMesh)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui OpenGL OpenGLWidgets)
if (Qt6Widgets_FOUND)
if (Qt6Widgets_VERSION VERSION_LESS 6.3.0)
message(FATAL_ERROR "Minimum Qt version is 6.3.0")
endif()
endif()
qt_standard_project_setup()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_RELEASE "-Ox")
endif()
# Add dependencies
find_package(OpenMP)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
# ------------------------------------------------------------------------------
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(APP AppTinyMesh)
set(SRC_DIR AppTinyMesh/Source)
set(INC_DIR AppTinyMesh/Include)
include_directories(${INC_DIR})
aux_source_directory(${SRC_DIR} SRC_FILES)
add_executable(${APP} WIN32
${SRC_FILES}
${INC_DIR}/box.h
${INC_DIR}/camera.h
${INC_DIR}/color.h
${INC_DIR}/GL.h
${INC_DIR}/glew.h
${INC_DIR}/implicits.h
${INC_DIR}/mathematics.h
${INC_DIR}/mesh.h
${INC_DIR}/meshcolor.h
${INC_DIR}/qte.h
${INC_DIR}/ray.h
${INC_DIR}/realtime.h
${INC_DIR}/shader-api.h
)
set_target_properties(${APP} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR})
# window target exe
if (WIN32)
find_library(GLEW_LIBRARIES
NAMES glew32
HINTS "./Libs/"
)
target_link_libraries(${APP}
${GLEW_LIBRARIES}
glu32.lib
opengl32
Qt6::Core
Qt6::Widgets
Qt6::Gui
Qt6::OpenGL
Qt6::OpenGLWidgets
)
# linux target exe
else()
find_package(GLEW REQUIRED)
target_link_libraries(${APP}
${GLEW_LIBRARIES}
GLU
glut
Qt6::Core
Qt6::Widgets
Qt6::Gui
Qt6::OpenGL
Qt6::OpenGLWidgets
)
endif()
# shader folder copy on post build (all platforms)
set(DATA_DIR AppTinyMesh/Shaders)
add_custom_command(
TARGET ${APP} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/${DATA_DIR}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Shaders
)
# windeployqt execution for copying all Qt (dll, platforms)
if (WIN32)
# find qmake executable
get_target_property(_qmake_executable Qt6::qmake IMPORTED_LOCATION)
get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY)
# run windeployqt
add_custom_command(
TARGET ${APP} POST_BUILD
COMMAND "${_qt_bin_dir}/windeployqt.exe" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/AppTinyMesh.exe
)
# copy glew32.dll
add_custom_command(
TARGET ${APP} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/Libs/glew32.dll
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/
)
endif()