From 018c12d3e908239198359a42db1958624b34096f Mon Sep 17 00:00:00 2001 From: scivision Date: Tue, 21 Feb 2023 21:41:45 -0500 Subject: [PATCH 1/2] modernize/simplify cmake. Make release take effect --- .gitpod.yml | 11 ++++------- CMakeLists.txt | 45 +++++++++++++++++++++------------------------ Readme.md | 10 +++++----- 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index 550e9cd..909c6cf 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -2,11 +2,8 @@ image: file: Dockerfile tasks: - command: > - mkdir --parents build && - cd build && - cmake .. && - make && - ./tinykaboom && + cmake -Bbuild && + cmake --build build && + build/tinykaboom && pnmtopng out.ppm > out.png && - open out.png && - cd .. + open out.png diff --git a/CMakeLists.txt b/CMakeLists.txt index de86bd7..f9aca84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,24 @@ -cmake_minimum_required (VERSION 2.8) -project (tinykaboom) - -include(CheckCXXCompilerFlag) - -function(enable_cxx_compiler_flag_if_supported flag) - string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set) - if(flag_already_set EQUAL -1) - check_cxx_compiler_flag("${flag}" flag_supported) - if(flag_supported) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) - endif() - unset(flag_supported CACHE) - endif() -endfunction() - -enable_cxx_compiler_flag_if_supported("-Wall") -enable_cxx_compiler_flag_if_supported("-Wextra") -enable_cxx_compiler_flag_if_supported("-pedantic") -enable_cxx_compiler_flag_if_supported("-std=c++11") -enable_cxx_compiler_flag_if_supported("-O3") -enable_cxx_compiler_flag_if_supported("-fopenmp") - -file(GLOB SOURCES *.h *.cpp) +cmake_minimum_required(VERSION 3.10...3.26) + +get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(NOT is_multi_config AND NOT (CMAKE_BUILD_TYPE OR DEFINED ENV{CMAKE_BUILD_TYPE})) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Release default") +endif() + +project(tinykaboom LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|Intel") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +find_package(OpenMP COMPONENTS CXX) + +set(SOURCES tinykaboom.cpp) add_executable(${PROJECT_NAME} ${SOURCES}) +target_link_libraries(${PROJECT_NAME} PRIVATE $<$:OpenMP::OpenMP_CXX>) +file(GENERATE OUTPUT .gitignore CONTENT "*") diff --git a/Readme.md b/Readme.md index c39522a..631bdd1 100644 --- a/Readme.md +++ b/Readme.md @@ -10,13 +10,13 @@ In my lectures I tend to avoid third party libraries as long as it is reasonable ![](https://raw.githubusercontent.com/ssloy/tinykaboom/master/out.jpg) ## compilation + ```sh git clone https://github.com/ssloy/tinykaboom.git cd tinykaboom -mkdir build -cd build -cmake .. -make +cmake -Bbuild +cmake --build build +build/tinykaboom ``` You can open the project in Gitpod, a free online dev evironment for GitHub: @@ -27,7 +27,7 @@ On open, the editor will compile & run the program as well as open the resulting Just change the code in the editor and rerun the script (use the terminal's history) to see updated images. ## Homework -The possibilities are infinte. For example, you can add the environment map and some transparency: +The possibilities are infinte. For example, you can add the environment map and some transparency: ![](https://raw.githubusercontent.com/ssloy/tinykaboom/homework_assignment/envmap1.jpg) Add other objects and illuminate them: From 12eccbde418b03ee4a3e088a58819c55328c1c55 Mon Sep 17 00:00:00 2001 From: scivision Date: Tue, 21 Feb 2023 21:44:35 -0500 Subject: [PATCH 2/2] correct type so visual studio works --- tinykaboom.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tinykaboom.cpp b/tinykaboom.cpp index ab7d904..94fc5c2 100644 --- a/tinykaboom.cpp +++ b/tinykaboom.cpp @@ -96,7 +96,7 @@ int main() { std::vector framebuffer(width*height); #pragma omp parallel for - for (size_t j = 0; j