79 lines
2.2 KiB
CMake
79 lines
2.2 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
project(MyOpenGLProject)
|
|
|
|
# Set C++ standard
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
# Only build on Windows
|
|
if(WIN32)
|
|
|
|
# Use FetchContent to download GLFW and ImGui
|
|
include(FetchContent)
|
|
|
|
FetchContent_Declare(
|
|
glad
|
|
GIT_REPOSITORY https://github.com/Dav1dde/glad.git
|
|
GIT_TAG v2.0.7 # Latest version at the time of writing
|
|
)
|
|
FetchContent_MakeAvailable(glad)
|
|
|
|
# Download GLFW
|
|
FetchContent_Declare(
|
|
glfw
|
|
GIT_REPOSITORY https://github.com/glfw/glfw.git
|
|
GIT_TAG 3.4 # Latest stable version
|
|
)
|
|
FetchContent_MakeAvailable(glfw)
|
|
|
|
# Download ImGui
|
|
FetchContent_Declare(
|
|
imgui
|
|
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
|
GIT_TAG v1.91.1 # Latest stable version
|
|
)
|
|
|
|
FetchContent_MakeAvailable(imgui)
|
|
# Set up ImGui backends for GLFW and OpenGL3
|
|
set(IMGUI_BACKENDS "${imgui_SOURCE_DIR}/backends")
|
|
set(IMGUI_SOURCES
|
|
${imgui_SOURCE_DIR}/imgui.cpp
|
|
${imgui_SOURCE_DIR}/imgui_demo.cpp
|
|
${imgui_SOURCE_DIR}/imgui_draw.cpp
|
|
${imgui_SOURCE_DIR}/imgui_tables.cpp
|
|
${imgui_SOURCE_DIR}/imgui_widgets.cpp
|
|
${IMGUI_BACKENDS}/imgui_impl_glfw.cpp
|
|
${IMGUI_BACKENDS}/imgui_impl_opengl3.cpp
|
|
)
|
|
|
|
set(glad_SOURCE_DIR src/vendor/glad)
|
|
|
|
add_library(glad ${glad_SOURCE_DIR}/src/glad.c)
|
|
target_include_directories(glad PUBLIC ${glad_SOURCE_DIR}/include)
|
|
|
|
set (APP_SOURCES
|
|
src/main.cpp
|
|
)
|
|
|
|
# Define your executable and include ImGui and backend sources
|
|
add_executable(MyOpenGLApp WIN32 ${APP_SOURCES} ${IMGUI_SOURCES})
|
|
|
|
# Include directories for ImGui, GLEW, and GLFW
|
|
target_include_directories(MyOpenGLApp PRIVATE
|
|
${imgui_SOURCE_DIR}
|
|
${IMGUI_BACKENDS}
|
|
${glfw_SOURCE_DIR}/include
|
|
${glad_SOURCE_DIR}/include
|
|
)
|
|
|
|
# Link against Windows-specific libraries, GLEW, GLFW, and OpenGL
|
|
target_link_libraries(MyOpenGLApp PRIVATE
|
|
glfw
|
|
glad
|
|
)
|
|
|
|
# Define GLEW_STATIC for static linking of GLEW
|
|
# target_compile_definitions(MyOpenGLApp PRIVATE GLEW_STATIC)
|
|
|
|
else()
|
|
message(FATAL_ERROR "This project is only supported on Windows.")
|
|
endif() |