2021-08-10 22:52:19 +02:00
|
|
|
cmake_minimum_required(VERSION 3.10)
|
|
|
|
|
|
|
|
# So library linking is more sane.
|
|
|
|
cmake_policy(SET CMP0003 NEW)
|
|
|
|
|
|
|
|
# So syntax problems are errors.
|
|
|
|
cmake_policy(SET CMP0010 NEW)
|
|
|
|
|
|
|
|
# Input directories must have CMakeLists.txt
|
|
|
|
cmake_policy(SET CMP0014 NEW)
|
|
|
|
|
|
|
|
# Compile definitions.
|
|
|
|
cmake_policy(SET CMP0043 NEW)
|
|
|
|
|
|
|
|
# Use ROOT variables in find_package.
|
|
|
|
cmake_policy(SET CMP0074 NEW)
|
|
|
|
|
|
|
|
# Convert relative paths to absolute in target_sources()
|
|
|
|
cmake_policy(SET CMP0076 NEW)
|
|
|
|
|
|
|
|
# Copy files from source directory to destination directory, substituting any
|
|
|
|
# variables. Create destination directory if it does not exist.
|
|
|
|
|
|
|
|
macro(configure_files srcDir destDir)
|
|
|
|
message(STATUS "Configuring directory ${destDir}")
|
|
|
|
make_directory(${destDir})
|
|
|
|
|
|
|
|
file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*)
|
|
|
|
foreach(templateFile ${templateFiles})
|
|
|
|
set(srcTemplatePath ${srcDir}/${templateFile})
|
|
|
|
if(NOT IS_DIRECTORY ${srcTemplatePath})
|
|
|
|
message(STATUS "Configuring file ${templateFile}")
|
|
|
|
configure_file(
|
|
|
|
${srcTemplatePath}
|
|
|
|
${destDir}/${templateFile}
|
|
|
|
@ONLY)
|
|
|
|
endif(NOT IS_DIRECTORY ${srcTemplatePath})
|
|
|
|
endforeach(templateFile)
|
|
|
|
endmacro(configure_files)
|
|
|
|
|
|
|
|
# Initialize project
|
|
|
|
project(ComputeEngine)
|
|
|
|
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
|
|
|
set(default_build_type "Release")
|
|
|
|
|
|
|
|
# Add binary
|
|
|
|
add_library(${PROJECT_NAME} STATIC)
|
|
|
|
|
|
|
|
# Find GLFW
|
|
|
|
|
|
|
|
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
|
|
|
|
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
|
|
|
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
|
|
|
|
2023-06-04 18:27:34 +02:00
|
|
|
find_package(glfw3 REQUIRED)
|
2021-08-10 22:52:19 +02:00
|
|
|
|
|
|
|
# Find GLEW
|
|
|
|
find_package(GLEW REQUIRED)
|
|
|
|
|
|
|
|
if(GLEW_FOUND)
|
|
|
|
set(GLEW_INCLUDE_DIR ${GLEW_INCLUDE_DIRS})
|
|
|
|
message(STATUS "GLEW_INCLUDE_DIR: ${GLEW_INCLUDE_DIR}")
|
|
|
|
message(STATUS "GLEW_LIBRARIES: ${GLEW_LIBRARIES}")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "GLEW not found")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Find OpenGL
|
|
|
|
if(NOT WIN32)
|
|
|
|
find_package(OpenGL REQUIRED)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Find stb_image
|
2023-06-05 19:27:52 +02:00
|
|
|
find_package(Stb REQUIRED)
|
|
|
|
|
|
|
|
if(Stb_INCLUDE_DIR)
|
|
|
|
message(STATUS "Stb_INCLUDE_DIR: ${Stb_INCLUDE_DIR}")
|
2021-08-10 22:52:19 +02:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "stb_image not found")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Add source
|
|
|
|
add_subdirectory(src)
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
|
|
${GLFW_INCLUDE_DIR}
|
|
|
|
${OPENGL_INCLUDE_DIR}
|
2023-06-05 19:27:52 +02:00
|
|
|
${Stb_INCLUDE_DIR}
|
2021-08-10 22:52:19 +02:00
|
|
|
${GLEW_INCLUDE_DIR})
|
|
|
|
target_link_directories(${PROJECT_NAME} PUBLIC ${GLFW_LIB_DIR} ${GLEW_LIBRARIES})
|
2023-06-04 18:27:34 +02:00
|
|
|
|
2023-06-05 19:43:23 +02:00
|
|
|
if(WIN32)
|
2023-06-05 19:48:21 +02:00
|
|
|
target_link_libraries(${PROJECT_NAME} glfw GLEW::GLEW)
|
2023-06-05 19:43:23 +02:00
|
|
|
else()
|
2023-06-05 19:48:21 +02:00
|
|
|
target_link_libraries(${PROJECT_NAME} glfw OpenGL::GL GLEW::GLEW)
|
2023-06-05 19:43:23 +02:00
|
|
|
endif()
|
2021-08-10 22:52:19 +02:00
|
|
|
|
|
|
|
# Header files
|
|
|
|
file(COPY src/ComputeEngine.h DESTINATION ${CMAKE_BINARY_DIR}/include)
|
|
|
|
file(COPY src/Timer.h DESTINATION ${CMAKE_BINARY_DIR}/include)
|
|
|
|
file(COPY src/Texture.h DESTINATION ${CMAKE_BINARY_DIR}/include)
|
|
|
|
file(COPY src/UBO.h DESTINATION ${CMAKE_BINARY_DIR}/include)
|
|
|
|
file(COPY src/SSBO.h DESTINATION ${CMAKE_BINARY_DIR}/include)
|
|
|
|
file(COPY src/Shader.h DESTINATION ${CMAKE_BINARY_DIR}/include)
|
|
|
|
file(COPY src/Program.h DESTINATION ${CMAKE_BINARY_DIR}/include)
|
|
|
|
file(COPY src/GLUtils.h DESTINATION ${CMAKE_BINARY_DIR}/include)
|
|
|
|
|