43 lines
1.7 KiB
Text
43 lines
1.7 KiB
Text
|
|
cmake_minimum_required(VERSION 3.16)
|
||
|
|
project(card_raytracer CXX)
|
||
|
|
|
||
|
|
# The original card.cc is sacred and must NOT be modified. We compile it
|
||
|
|
# verbatim. Because the file is golfed C++ from the early 2010s, we relax
|
||
|
|
# a few things so a modern compiler accepts it untouched:
|
||
|
|
# - C++14 (default constructor v(){} is fine; pow(float,int) overload exists)
|
||
|
|
# - -w silences the unavoidable warnings (implicit float->int conversions
|
||
|
|
# in the final printf, narrowing, unused result of operator new, etc.)
|
||
|
|
# We can't fix them — we'd have to edit card.cc, which we won't.
|
||
|
|
set(CMAKE_CXX_STANDARD 14)
|
||
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||
|
|
|
||
|
|
add_executable(card card.cc)
|
||
|
|
add_executable(card_explained card_explained.cc)
|
||
|
|
|
||
|
|
# Per-compiler flags. The original is golfed and triggers warnings we can't
|
||
|
|
# fix without editing it (forbidden). The de-obfuscated version keeps full
|
||
|
|
# warnings on so it stays honest.
|
||
|
|
if(MSVC)
|
||
|
|
target_compile_options(card PRIVATE /w /O2)
|
||
|
|
target_compile_options(card_explained PRIVATE /W4 /O2)
|
||
|
|
else()
|
||
|
|
target_compile_options(card PRIVATE -w -O3)
|
||
|
|
target_compile_options(card_explained PRIVATE -Wall -Wextra -O3)
|
||
|
|
endif()
|
||
|
|
|
||
|
|
# Convenience targets: render an image from each binary.
|
||
|
|
# Run with: cmake --build build --target image
|
||
|
|
add_custom_target(image
|
||
|
|
COMMAND card > aek.ppm
|
||
|
|
DEPENDS card
|
||
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||
|
|
COMMENT "Rendering aek.ppm from the original card (512x512 @ 64 spp)"
|
||
|
|
)
|
||
|
|
|
||
|
|
add_custom_target(image_explained
|
||
|
|
COMMAND card_explained > aek_explained.ppm
|
||
|
|
DEPENDS card_explained
|
||
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||
|
|
COMMENT "Rendering aek_explained.ppm from the de-obfuscated card"
|
||
|
|
)
|