101 lines
3.3 KiB
CMake
101 lines
3.3 KiB
CMake
cmake_minimum_required(VERSION 3.10)
|
|
project(TerraVisor VERSION 0.0.3)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
configure_file(
|
|
"${PROJECT_SOURCE_DIR}/include/config.h.in"
|
|
"${PROJECT_BINARY_DIR}/config.h"
|
|
)
|
|
include_directories("${PROJECT_BINARY_DIR}")
|
|
|
|
# Find packages using vcpkg
|
|
find_package(GLEW CONFIG REQUIRED)
|
|
find_package(glfw3 CONFIG REQUIRED)
|
|
find_package(glm CONFIG REQUIRED)
|
|
find_package(assimp CONFIG REQUIRED)
|
|
|
|
# Set Debug and Release directories
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}")
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}")
|
|
|
|
# Add source files
|
|
file(GLOB_RECURSE SOURCES "${CMAKE_SOURCE_DIR}/source/*.cpp")
|
|
file(GLOB_RECURSE HEADERS "${CMAKE_SOURCE_DIR}/include/*.h")
|
|
file(GLOB SHADERS "${CMAKE_SOURCE_DIR}/shaders/*.glsl")
|
|
file(GLOB IMGUI_SOURCES
|
|
"${CMAKE_SOURCE_DIR}/imgui/*.cpp"
|
|
"${CMAKE_SOURCE_DIR}/imgui/backends/imgui_impl_glfw.cpp"
|
|
"${CMAKE_SOURCE_DIR}/imgui/backends/imgui_impl_opengl3.cpp"
|
|
)
|
|
file(GLOB FREEIMAGE_HEADER "${CMAKE_SOURCE_DIR}/dependencies/FreeImage/include/*.h")
|
|
|
|
# Add the executable
|
|
add_executable(TerraVisor ${SOURCES} ${HEADERS} ${IMGUI_SOURCES} ${FREEIMAGE_HEADER})
|
|
|
|
# Include directories (handled by find_package now)
|
|
include_directories(
|
|
${CMAKE_SOURCE_DIR}/include
|
|
${CMAKE_SOURCE_DIR}/imgui
|
|
${CMAKE_SOURCE_DIR}/imgui/backends
|
|
${CMAKE_SOURCE_DIR}/dependencies/FreeImage/include
|
|
)
|
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/dependencies/FreeImage/lib)
|
|
|
|
# Link libraries using vcpkg
|
|
if (UNIX)
|
|
target_link_libraries(TerraVisor PRIVATE
|
|
GLEW::GLEW
|
|
glfw
|
|
glm::glm
|
|
assimp::assimp
|
|
${CMAKE_SOURCE_DIR}/dependencies/FreeImage/lib/UNIX/libfreeimage.a
|
|
/vcpkg/installed/x64-linux/debug/lib/libtiffd.a
|
|
/vcpkg/installed/x64-linux/debug/lib/libjpeg.a
|
|
/vcpkg/installed/x64-linux/debug/lib/libz.a
|
|
/vcpkg/installed/x64-linux/debug/lib/liblzma.a
|
|
/usr/lib/x86_64-linux-gnu/libGL.so
|
|
/usr/lib/x86_64-linux-gnu/libGLU.so
|
|
/usr/lib/x86_64-linux-gnu/libX11.so
|
|
/usr/lib/x86_64-linux-gnu/libXext.so
|
|
-lm
|
|
-ldl
|
|
-lrt
|
|
)
|
|
else()
|
|
target_link_libraries(TerraVisor PRIVATE GLEW::GLEW glfw glm::glm assimp::assimp ${CMAKE_SOURCE_DIR}/dependencies/FreeImage/lib/WIN32/FreeImage.lib)
|
|
endif()
|
|
|
|
# Custom targets
|
|
add_custom_target(copy_shaders ALL
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
${CMAKE_SOURCE_DIR}/shaders ${CMAKE_BINARY_DIR}/shaders
|
|
)
|
|
add_custom_target(copy_hgt ALL
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
${CMAKE_SOURCE_DIR}/hgt ${CMAKE_BINARY_DIR}/hgt
|
|
)
|
|
# Set paths for FreeImage DLL
|
|
set(FREEIMAGE_DLL_PATH "${CMAKE_SOURCE_DIR}/dependencies/FreeImage/bin/FreeImage.dll")
|
|
|
|
# Add custom command to copy FreeImage.dll to the output directory for both Debug and Release
|
|
add_custom_command(TARGET TerraVisor POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
${FREEIMAGE_DLL_PATH}
|
|
$<TARGET_FILE_DIR:TerraVisor>
|
|
)
|
|
|
|
# Set subsystem based on build type
|
|
if (WIN32)
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
set_target_properties(TerraVisor PROPERTIES LINK_FLAGS "-Wl,--subsystem,windows")
|
|
else()
|
|
set_target_properties(TerraVisor PROPERTIES LINK_FLAGS "-Wl,--subsystem,console")
|
|
endif()
|
|
endif()
|
|
|
|
# Ensure shaders are copied before building the executable
|
|
add_dependencies(TerraVisor copy_shaders copy_hgt)
|