-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
74 lines (60 loc) · 3.22 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
cmake_minimum_required(VERSION 3.17)
project(ray_tracing_one_week C)
set(CMAKE_C_STANDARD 11)
include(CheckLibraryExists)
include(CheckIncludeFile)
include(CheckSymbolExists)
CHECK_LIBRARY_EXISTS(m ceil "" HAVE_LIB_M)
if (HAVE_LIB_M)
set(EXTRA_LIBS ${EXTRA_LIBS} m)
endif ()
set(THREADING_IMPLEMENTATION "None")
find_package(Threads REQUIRED)
if (CMAKE_USE_PTHREADS_INIT)
set(THREADING_IMPLEMENTATION threads/rt_sync_unix.c threads/rt_thread_unix.c)
elseif (CMAKE_USE_WIN32_THREADS_INIT)
set(THREADING_IMPLEMENTATION threads/rt_sync_win32.c threads/rt_thread_win32.c)
else ()
message(FATAL_ERROR "The System does not contain the supported threading library (pthread or windows threads)")
endif ()
add_executable(ray_tracing_one_week rt_camera.c rt_colour.c rt_aabb.c rt_perlin.c rt_skybox_simple.c
# Materials
materials/rt_material.c rt_hit.c materials/rt_material_diffuse.c materials/rt_material_metal.c
materials/rt_material_dielectric.c materials/rt_material_diffuse_light.c materials/rt_material_isotropic.c
# Hittables
hittables/rt_hittable.c hittables/rt_sphere.c hittables/rt_hittable_list.c main.c hittables/rt_moving_sphere.c
hittables/rt_bvh.c hittables/rt_aa_rect.c hittables/rt_box.c hittables/rt_instance.c hittables/rt_const_medium.c
# Textures
textures/rt_texture.c textures/rt_texture_solid_colour.c textures/rt_texture_checker_pattern.c
textures/rt_texture_noise.c textures/rt_texture_image.c
# Scenes
scenes/rt_scenes.c
# Random number generation
random/rt_random.c random/rt_random.h
# Threading
${THREADING_IMPLEMENTATION} threads/rt_thread_pool.c)
target_compile_options(ray_tracing_one_week PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Winline>
$<$<CXX_COMPILER_ID:MSVC>:
/WX /W4>)
if (WIN32)
target_compile_definitions(ray_tracing_one_week PRIVATE WIN32_LEAN_AND_MEAN)
endif ()
if (CMAKE_BUILD_TYPE EQUAL "DEBUG")
# Enable inline optimization under debug configurations.
target_compile_options(ray_tracing_one_week PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-finline-functions>
$<$<CXX_COMPILER_ID:MSVC>:
/Ob>)
endif ()
# Copy assets into a build directory
add_custom_command(TARGET ray_tracing_one_week PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/assets $<TARGET_FILE_DIR:ray_tracing_one_week>/assets)
target_include_directories(ray_tracing_one_week PRIVATE ./ materials hittables textures deps threads)
target_link_libraries(ray_tracing_one_week ${EXTRA_LIBS} Threads::Threads)
set_target_properties(ray_tracing_one_week
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")