Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bvarillon committed Sep 7, 2023
2 parents e2ea0fe + c96b4bb commit 0206d38
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 14 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ build/
bin/*
!bin/conf.json
.vscode/
<<<<<<< HEAD

Testing/
neovim.json
neovim.json
=======
.cache/
>>>>>>> c96b4bbb92e93d988d3d74323262b9b94318b163
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
cmake_minimum_required(VERSION 3.1.0)
cmake_minimum_required(VERSION 3.5)
project(RayTracing VERSION 0.0.1)


add_subdirectory(third_party/stb_image_write)
add_subdirectory(third_party/nlohmann)
add_subdirectory(third_party/cxxopts)

configure_file(include/Version.hpp.in Version.hpp)
#configure_file(include/Version.hpp.in Version.hpp)

ADD_CUSTOM_COMMAND(
OUTPUT version.h
_version.h
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/version.cmake)

include_directories(include "${PROJECT_BINARY_DIR}")
add_executable(RayTracing src/main.cpp
Expand All @@ -18,7 +24,8 @@ add_executable(RayTracing src/main.cpp
src/Color.cpp
src/Material.cpp
src/Renderer.cpp
src/Arguments.cpp)
src/Arguments.cpp
${CMAKE_CURRENT_BINARY_DIR}/version.h)
if(UNIX)
target_link_libraries(RayTracing pthread)
endif(UNIX)
Expand Down
1 change: 0 additions & 1 deletion include/Version.hpp.in

This file was deleted.

8 changes: 5 additions & 3 deletions src/Arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <iostream>
#include <fstream>

#include "Version.hpp"
//#include "Version.hpp"
#include "version.h"

#include "nlohmann/json.hpp"
#include "cxxopts.hpp"
Expand All @@ -26,7 +27,8 @@ Arguments pars_args(int argc, char* argv[])

if (result.count("version"))
{
std::cout << "RayTracing - v" << VERSION << std::endl;
//std::cout << "RayTracing - v" << VERSION << std::endl;
std::cout << "RayTracing - " << GIT_DESCRIBE << std::endl;
exit(EXIT_SUCCESS);
}
if (result.count("help"))
Expand Down Expand Up @@ -64,4 +66,4 @@ Arguments pars_args(int argc, char* argv[])
std::cout << "samples : " << params.samples << " - depth" << params.max_depth << " - size " << params.size << std::endl;
}
return params;
}
}
6 changes: 4 additions & 2 deletions src/Renderer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Renderer.hpp"

#include <climits>

#include "Color.hpp"
#include "Point3.hpp"
#include "Ray.hpp"
Expand Down Expand Up @@ -77,7 +79,7 @@ Color* Renderer::run(int img_height, int img_width, int samples, int max_depth,
while (k < img_height)
{
log << "\rWorking:" << (int) (float(k)/img_height*100) << std::flush;
std::this_thread::sleep_for(500ms);
// std::this_thread::sleep_for(500ms);
}
log << "\rWorking:" << (int) (float(k)/img_height*100) << std::flush;

Expand All @@ -89,4 +91,4 @@ Color* Renderer::run(int img_height, int img_width, int samples, int max_depth,
log << std::endl << " Effective max depth : " << effective_depth << std::endl;

return img;
}
}
4 changes: 2 additions & 2 deletions third_party/nlohmann/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.1.0)
cmake_minimum_required(VERSION 3.5)
project(Nlohmann VERSION 0.1.0)

add_library(Nlohmann INTERFACE)
target_include_directories(StbImageWrite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(StbImageWrite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
4 changes: 2 additions & 2 deletions third_party/stb_image_write/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.1.0)
cmake_minimum_required(VERSION 3.5)
project(StbImageWrite VERSION 0.1.0)

set(SRC stb_image_write.cpp)
set(HDR stb_image_write.hpp)

add_library(StbImageWrite ${SRC})
target_include_directories(StbImageWrite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(StbImageWrite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
44 changes: 44 additions & 0 deletions version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
find_package(Git REQUIRED)

execute_process(COMMAND ${GIT_EXECUTABLE} log --pretty=format:'%h' -n1
OUTPUT_VARIABLE GIT_REV
ERROR_QUIET)

execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --always
OUTPUT_VARIABLE GIT_DESCRIBE
ERROR_QUIET)

execute_process(
COMMAND bash -c "${GIT_EXECUTABLE} diff --quiet --exit-code || echo +"
OUTPUT_VARIABLE GIT_DIFF)
execute_process(
COMMAND git describe --exact-match --tags
OUTPUT_VARIABLE GIT_TAG ERROR_QUIET)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE GIT_BRANCH)

string(STRIP "${GIT_REV}" GIT_REV)
string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV)
string(STRIP "${GIT_DESCRIBE}" GIT_DESCRIBE)
string(STRIP "${GIT_DIFF}" GIT_DIFF)
string(STRIP "${GIT_TAG}" GIT_TAG)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)

set(VERSION "#define GIT_REV \"${GIT_REV}${GIT_DIFF}\"
#define GIT_DESCRIBE \"${GIT_DESCRIBE}${GIT_DIFF}\"
#define GIT_TAG \"${GIT_TAG}\"
#define GIT_BRANCH \"${GIT_BRANCH}\"")

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.h)
file(READ version.h VERSION_)
message("${CMAKE_CURRENT_SOURCE_DIR}/version.h exist")
else()
set(VERSION_ "")
message("${CMAKE_CURRENT_SOURCE_DIR}/version.h doesn't exist")
endif()

if (NOT "${VERSION}" STREQUAL "${VERSION_}")
file(WRITE version.h "${VERSION}")
message("new version detected")
endif()

0 comments on commit 0206d38

Please sign in to comment.