-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
115 lines (108 loc) · 4.47 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
cmake_minimum_required(VERSION 3.7)
project(heX-Ray CXX)
# CMake project for hexray. It uses SDL2 and OpenEXR (with its dependencies).
# For Windows users: make sure you've unpacked your SDL and OpenEXR in either
# - your user dir, subdir "develop\SDK", e.g. C:\Users\YOUR_USER\develop\SDK\SDL2-2.30.1
# - in C:\SDK, e.g. C:\SDK\SDL2-2.30.1
# - or in arbitrary directory provided in CMAKE_PREFIX_PATH
# For Linux and Mac OS X users: you don't need to do anything besides installing SDL2 with your package manager
if (WIN32)
option(HEXRAY_BUILD_OPENEXR "Build OpenEXR as part of the CMake configuration" OFF)
set(CMAKE_PREFIX_PATH "~/develop/SDK;c:\\SDK;${CMAKE_PREFIX_PATH}")
if (CMAKE_GENERATOR STREQUAL "NMake Makefiles")
message("If you get an error about 'nmake' missing, be sure to call CMake with -G 'MinGW Makefiles'")
endif()
if (CMAKE_GENERATOR STREQUAL "MinGW Makefiles")
set(HEXRAY_MSYS_ROOT "C:\\msys64" CACHE STRING "Root directory to MSYS installation to find installed packages automatically")
set(CMAKE_PREFIX_PATH "${HEXRAY_MSYS_ROOT}/ucrt64/lib/cmake;${CMAKE_PREFIX_PATH}")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Additional search directories for vcpkg
set(CMAKE_PREFIX_PATH "~/develop/SDK/x64-windows;c:\\SDK\\x64-windows;${CMAKE_PREFIX_PATH}")
# Explicitly require standard conformance to ensure portability.
add_compile_options("/Zc:__cplusplus" "/permissive-")
endif()
if (HEXRAY_BUILD_OPENEXR)
set(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/openexr;${CMAKE_PREFIX_PATH}")
# First check if it was already built, or available in the prefix path.
find_package(OpenEXR QUIET)
if (NOT OpenEXR_FOUND)
include(scripts/build_openexr.cmake)
endif()
endif()
endif()
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
if (NOT TARGET OpenEXR::OpenEXR)
find_package(OpenEXR REQUIRED)
endif()
add_executable(hexray
src/bbox.h
src/bitmap.cpp
src/bitmap.h
src/camera.cpp
src/camera.h
src/color.h
src/constants.h
src/environment.cpp
src/environment.h
src/geometry.cpp
src/geometry.h
src/heightfield.cpp
src/heightfield.h
src/lights.cpp
src/lights.h
src/main.cpp
src/main.h
src/mesh.cpp
src/mesh.h
src/matrix.cpp
src/matrix.h
src/node.h
src/scene.cpp
src/scene.h
src/sdl.cpp
src/sdl.h
src/shading.cpp
src/shading.h
src/threading.cpp
src/threading.h
src/util.cpp
src/util.h
src/vector.h
)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(STATUS "Setting aggressive optimization flags (per Lecture 13)")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math -march=haswell -mtune=haswell")
target_compile_options(hexray PRIVATE -Wall)
target_link_libraries(hexray stdc++fs)
else()
set(_additional_release_flags "/Ox /Ob2 /Oi /Ot /GT /GL /GS- /arch:SSE2 /fp:fast") # /arch:AVX may also be added
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${_additional_release_flags}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${_additional_release_flags}")
unset(_additional_release_flags)
target_compile_options(hexray PRIVATE /W4)
endif()
target_link_libraries(hexray ${SDL2_LIBRARIES} OpenEXR::OpenEXR)
set_property(TARGET hexray PROPERTY CXX_STANDARD 17)
# Additional configuration for easy debugging in Visual Studio
if (CMAKE_GENERATOR MATCHES "Visual Studio.*")
# Set the startup project directly to be ready for running and debugging.
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT hexray)
set (_debug_path "${SDL2_BINDIR};$<TARGET_FILE_DIR:OpenEXR::OpenEXR>;$<TARGET_FILE_DIR:Imath::Imath>")
if (TARGET libdeflate::libdeflate_shared)
set (_debug_path "${_debug_path};$<TARGET_FILE_DIR:libdeflate::libdeflate_shared>")
endif()
# Set the PATH environment variable to include the SDL2 binary directory to load dependencies without manual copies.
set_target_properties(hexray PROPERTIES VS_DEBUGGER_ENVIRONMENT
"PATH=${_debug_path};$ENV{PATH}"
)
endif()
# Configure the VSCode launch file
if (WIN32 AND CMAKE_GENERATOR STREQUAL "MinGW Makefiles")
# Backslashes need to be escaped additionally for the json generation.
string(REPLACE "\\" "\\\\" _msys_root_escaped "${HEXRAY_MSYS_ROOT}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json.in.mingw ${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json @ONLY)
else()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json.in.linux ${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json @ONLY)
endif()