75 lines
2.5 KiB
CMake
75 lines
2.5 KiB
CMake
cmake_minimum_required(VERSION 3.27)
|
|
project(HelloAstro)
|
|
|
|
# Define platform-specific paths and libraries
|
|
if(WIN32)
|
|
# GLFW
|
|
set(GLFW_PATH "C:/libs/glfw-3.3.8.bin.WIN64")
|
|
include_directories(${GLFW_PATH}/include)
|
|
link_directories(${GLFW_PATH}/lib-vc2022)
|
|
|
|
# GLEW
|
|
set(GLEW_PATH "C:/libs/glew-2.2.0")
|
|
include_directories(${GLEW_PATH}/include)
|
|
link_directories(${GLEW_PATH}/lib/Release/x64)
|
|
|
|
# OpenGL
|
|
find_package(OpenGL REQUIRED)
|
|
elseif(UNIX)
|
|
find_package(PkgConfig REQUIRED)
|
|
pkg_search_module(GLFW REQUIRED glfw3)
|
|
find_package(GLEW REQUIRED)
|
|
find_package(OpenGL REQUIRED)
|
|
elseif(APPLE)
|
|
message(FATAL_ERROR "macOS is not supported yet.")
|
|
endif()
|
|
|
|
add_executable(${PROJECT_NAME} src/hello.cpp src/io.cpp)
|
|
|
|
if(WIN32)
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
"${GLEW_PATH}/bin/Release/x64/glew32.dll"
|
|
$<TARGET_FILE_DIR:${PROJECT_NAME}>
|
|
)
|
|
|
|
target_link_libraries(${PROJECT_NAME} glfw3)
|
|
target_link_libraries(${PROJECT_NAME} glew32)
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${GLEW_INCLUDE_DIRS})
|
|
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
|
|
elseif(UNIX)
|
|
include_directories(${GLFW_INCLUDE_DIRS})
|
|
target_link_libraries(${PROJECT_NAME} ${GLFW_LIBRARIES})
|
|
target_link_libraries(${PROJECT_NAME} GLEW::GLEW)
|
|
target_link_libraries(${PROJECT_NAME} OpenGL::GL)
|
|
endif()
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/vert.glsl
|
|
${CMAKE_CURRENT_BINARY_DIR}/vert.glsl COPYONLY)
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/frag.glsl
|
|
${CMAKE_CURRENT_BINARY_DIR}/frag.glsl COPYONLY)
|
|
|
|
# Append Git version to built executable after it has been built
|
|
find_package(Git)
|
|
if (GIT_FOUND)
|
|
if (WIN32)
|
|
set(TARGET_EXTENSION ".exe")
|
|
elseif(UNIX)
|
|
set(TARGET_EXTENSION "")
|
|
endif()
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND}
|
|
-DTARGET_DIR=$<TARGET_FILE_DIR:${PROJECT_NAME}>
|
|
-DPROJECT_NAME=${PROJECT_NAME}
|
|
-DTARGET_EXTENSION=${TARGET_EXTENSION}
|
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/add_git_version_to_executable.cmake
|
|
)
|
|
else()
|
|
message("Git not found - will not rename the exectuable.")
|
|
endif()
|
|
|
|
# Include header-only libraries
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib/astro/include)
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib/glm)
|
|
|