-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
87 lines (71 loc) · 2.54 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
cmake_minimum_required(VERSION 3.17)
project(HelloWorldWithDearImGui)
#-----------------------------------------------------------------------------------------------------------------------
# Download dependencies for GitHub
include(FetchContent)
FetchContent_Declare(
glew
GIT_REPOSITORY https://github.com/Perlmint/glew-cmake.git
GIT_TAG glew-cmake-2.2.0
)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw
GIT_TAG 3.3.2
)
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui
GIT_TAG v1.80
)
FetchContent_MakeAvailable(glew glfw imgui)
# FetchContent_Declare() normally supports EXCLUDE_FROM_ALL but apparently there is a bug
# See https://gitlab.kitware.com/cmake/cmake/-/issues/20167
# As a workaround, we exclude the directories manually
set_property(DIRECTORY ${glew_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES)
set_property(DIRECTORY ${glfw_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES)
#-----------------------------------------------------------------------------------------------------------------------
# Configure C++ version
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
#-----------------------------------------------------------------------------------------------------------------------
# Create executable
set(EXECUTABLE_NAME ${PROJECT_NAME})
add_executable(${EXECUTABLE_NAME}
main.cpp
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui.h
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_internal.h
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
)
# Add options for warning
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${EXECUTABLE_NAME}
PRIVATE
-Wall -Wextra -pedantic
)
endif ()
# Add a define to use the static version of Glew
target_compile_definitions(${EXECUTABLE_NAME}
PRIVATE
GLEW_STATIC
)
# Set the include path
target_include_directories(${EXECUTABLE_NAME}
PRIVATE
${imgui_SOURCE_DIR}/
)
# Link against the appropriate libraries
target_link_libraries(${EXECUTABLE_NAME}
PRIVATE
glfw
libglew_static
$<$<CXX_COMPILER_ID:GNU>:opengl32.a>
$<$<CXX_COMPILER_ID:MSVC>:opengl32.lib>
)