mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-02 04:37:54 +08:00
175 lines
4.8 KiB
CMake
175 lines
4.8 KiB
CMake
cmake_minimum_required (VERSION 2.8)
|
|
cmake_policy(VERSION 2.8)
|
|
|
|
project (LearnOpenGL)
|
|
|
|
IF(NOT CMAKE_BUILD_TYPE)
|
|
SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
|
|
ENDIF(NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
|
|
|
|
if(WIN32)
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
|
endif(WIN32)
|
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/lib)
|
|
|
|
list(APPEND CMAKE_CXX_FLAGS "-std=c++11")
|
|
|
|
# find the required packages
|
|
find_package(GLM REQUIRED)
|
|
message(STATUS "GLM included at ${GLM_INCLUDE_DIR}")
|
|
find_package(GLFW3 REQUIRED)
|
|
message(STATUS "Found GLFW3 in ${GLFW3_INCLUDE_DIR}")
|
|
find_package(ASSIMP REQUIRED)
|
|
message(STATUS "Found ASSIMP in ${ASSIMP_INCLUDE_DIR}")
|
|
find_package(SOIL REQUIRED)
|
|
message(STATUS "Found SOIL in ${SOIL_INCLUDE_DIR}")
|
|
find_package(GLEW REQUIRED)
|
|
message(STATUS "Found GLEW in ${GLEW_INCLUDE_DIR}")
|
|
|
|
if(WIN32)
|
|
set(LIBS glfw3 opengl32 glew32s SOIL assimp)
|
|
elseif(UNIX AND NOT APPLE)
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
|
|
find_package(OpenGL REQUIRED)
|
|
add_definitions(${OPENGL_DEFINITIONS})
|
|
find_package(X11 REQUIRED)
|
|
# note that the order is important for setting the libs
|
|
# use pkg-config --libs $(pkg-config --print-requires --print-requires-private glfw3) in a terminal to confirm
|
|
set(LIBS ${GLFW3_LIBRARY} X11 Xrandr Xinerama Xi Xxf86vm Xcursor GL dl pthread GLEW SOIL assimp)
|
|
elseif(APPLE)
|
|
INCLUDE_DIRECTORIES(/System/Library/Frameworks)
|
|
FIND_LIBRARY(COCOA_LIBRARY Cocoa)
|
|
FIND_LIBRARY(OpenGL_LIBRARY OpenGL)
|
|
FIND_LIBRARY(IOKit_LIBRARY IOKit)
|
|
MARK_AS_ADVANCED(COCOA_LIBRARY OpenGL_LIBRARY)
|
|
SET(APPLE_LIBS ${COCOA_LIBRARY} ${IOKit_LIBRARY} ${OpenGL_LIBRARY})
|
|
SET(APPLE_LIBS ${APPLE_LIBS} glfw3 GLEW assimp SOIL)
|
|
set(LIBS ${LIBS} ${APPLE_LIBS})
|
|
else()
|
|
set(LIBS )
|
|
endif(WIN32)
|
|
|
|
set(CHAPTERS
|
|
1.getting_started
|
|
2.lighting
|
|
3.model_loading
|
|
4.advanced_opengl
|
|
5.advanced_lighting
|
|
6.pbr
|
|
7.in_practice
|
|
)
|
|
|
|
set(1.getting_started
|
|
1.hello_window
|
|
2.hello_triangle
|
|
3.shaders
|
|
4.textures
|
|
5.transformations
|
|
6.coordinate_systems
|
|
7.camera
|
|
)
|
|
|
|
set(2.lighting
|
|
1.colors
|
|
2.basic_lighting
|
|
3.materials
|
|
4.lighting_maps
|
|
5.light_casters
|
|
6.multiple_lights
|
|
)
|
|
|
|
set(3.model_loading
|
|
1.model_loading
|
|
)
|
|
|
|
set(4.advanced_opengl
|
|
1.depth_testing
|
|
2.stencil_testing
|
|
3.1.blending_discard
|
|
3.2.blending_sort
|
|
5.framebuffers
|
|
6.cubemaps
|
|
8.advanced_glsl
|
|
9.geometry_shader
|
|
10.instancing
|
|
11.anti_aliasing
|
|
)
|
|
|
|
set(5.advanced_lighting
|
|
1.advanced_lighting
|
|
2.gamma_correction
|
|
3.1.shadow_mapping
|
|
3.2.point_shadows
|
|
# 3.3.csm
|
|
4.normal_mapping
|
|
5.parallax_mapping
|
|
6.hdr
|
|
7.bloom
|
|
8.deferred_shading
|
|
9.ssao
|
|
)
|
|
|
|
set(6.pbr
|
|
1.1.lighting
|
|
1.2.lighting_textured
|
|
# 2.1.1.ibl_irradiance_conversion
|
|
# 2.1.2.ibl_irradiance
|
|
# 2.2.ibl_specular
|
|
)
|
|
|
|
set(7.in_practice
|
|
1.debugging
|
|
# 2.text_rendering
|
|
)
|
|
|
|
|
|
|
|
configure_file(configuration/root_directory.h.in configuration/root_directory.h)
|
|
include_directories(${CMAKE_BINARY_DIR}/configuration)
|
|
|
|
# first create relevant static libraries requried for other projects
|
|
add_library(STB_IMAGE "src/stb_image.cpp")
|
|
set(LIBS ${LIBS} STB_IMAGE)
|
|
|
|
# then create a project file per tutorial
|
|
foreach(CHAPTER ${CHAPTERS})
|
|
foreach(DEMO ${${CHAPTER}})
|
|
file(GLOB SOURCE
|
|
"src/${CHAPTER}/${DEMO}/*.h"
|
|
"src/${CHAPTER}/${DEMO}/*.cpp"
|
|
)
|
|
set(NAME "${CHAPTER}_${DEMO}")
|
|
add_executable(${NAME} ${SOURCE})
|
|
target_link_libraries(${NAME} ${LIBS})
|
|
if(WIN32)
|
|
set_target_properties(${NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/${CHAPTER}")
|
|
elseif(UNIX)
|
|
set_target_properties(${NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin/${CHAPTER}")
|
|
endif(WIN32)
|
|
# copy shader files to build directory
|
|
file(GLOB SHADERS
|
|
"src/${CHAPTER}/${DEMO}/*.vs"
|
|
"src/${CHAPTER}/${DEMO}/*.frag"
|
|
"src/${CHAPTER}/${DEMO}/*.gs"
|
|
)
|
|
foreach(SHADER ${SHADERS})
|
|
if(WIN32)
|
|
# configure_file(${SHADER} "test")
|
|
add_custom_command(TARGET ${NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SHADER} $<TARGET_FILE_DIR:${NAME}>)
|
|
elseif(UNIX)
|
|
file(COPY ${SHADER} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin/${CHAPTER})
|
|
endif(WIN32)
|
|
|
|
endforeach(SHADER)
|
|
# if compiling for visual studio, also use configure file for each project (specifically to set up working directory)
|
|
if(MSVC)
|
|
configure_file(${CMAKE_SOURCE_DIR}/configuration/visualstudio.vcxproj.user.in ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.vcxproj.user @ONLY)
|
|
endif(MSVC)
|
|
endforeach(DEMO)
|
|
endforeach(CHAPTER)
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/includes)
|