Skip to content

Commit

Permalink
[build][refactoring] Converted Library to a shared library, and moved…
Browse files Browse the repository at this point in the history
… unnecessary files to tools directory (#24)
  • Loading branch information
abdelrahim-hentabli authored Apr 20, 2024
1 parent 48b02f5 commit b1d9332
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 19 deletions.
15 changes: 2 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
find_package(PNG REQUIRED)
file(GLOB RAY_TRACER_SOURCES *.cpp)

add_library(ray_tracer OBJECT camera.cpp hierarchy.cpp dump_png.cpp flat_shader.cpp parse.cpp phong_shader.cpp plane.cpp reflective_shader.cpp render_world.cpp sphere.cpp box.cpp mesh.cpp)
add_library(ray_tracer SHARED ${RAY_TRACER_SOURCES})

target_include_directories(ray_tracer
PRIVATE ${PNG_INCLUDE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/include
PRIVATE ${CMAKE_BINARY_DIR}/generated)

target_compile_options(ray_tracer
PUBLIC -ffast-math)

target_link_libraries(ray_tracer ${PNG_LIBRARY})

add_executable(original_ray_tracer main.cpp)

target_include_directories(original_ray_tracer
PRIVATE ${PNG_INCLUDE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/include)

target_link_libraries(original_ray_tracer ray_tracer)
4 changes: 3 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

add_subdirectory(third-party/googletest)
add_subdirectory(third-party/benchmark)
add_subdirectory(common)
add_subdirectory(demos)
add_subdirectory(test)
add_subdirectory(benchmark)
add_subdirectory(benchmark)
8 changes: 5 additions & 3 deletions tools/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ add_executable(benchmarks source/main.cpp)
target_include_directories(benchmarks
PRIVATE ${PROJECT_SOURCE_DIR}/include
PRIVATE ./include
PRIVATE ${CMAKE_BINARY_DIR}/generated)
PRIVATE ${CMAKE_BINARY_DIR}/generated
PRIVATE $<TARGET_PROPERTY:tool_common,INTERFACE_INCLUDE_DIRECTORIES>)

target_link_libraries(benchmarks
ray_tracer
benchmark::benchmark)
PRIVATE ray_tracer
PRIVATE tool_common
PRIVATE benchmark::benchmark)
17 changes: 17 additions & 0 deletions tools/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
find_package(PNG REQUIRED)

file(GLOB TOOL_COMMON_SOURCES *.cpp)

add_library(tool_common OBJECT ${TOOL_COMMON_SOURCES})

set_target_properties(tool_common PROPERTIES CXX_STANDARD 17)

target_include_directories(tool_common
PUBLIC .
PRIVATE ${PNG_INCLUDE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/include
PRIVATE ${CMAKE_BINARY_DIR}/generated
)

target_link_libraries(tool_common
PUBLIC ${PNG_LIBRARY})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tools/demos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(image)
10 changes: 10 additions & 0 deletions tools/demos/image/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_executable(image_demo main.cpp)

target_include_directories(image_demo
PRIVATE ${PROJECT_SOURCE_DIR}/include
PRIVATE $<TARGET_PROPERTY:tool_common,INTERFACE_INCLUDE_DIRECTORIES>
)

target_link_libraries(image_demo
PRIVATE ray_tracer
PRIVATE tool_common)
File renamed without changes.
6 changes: 4 additions & 2 deletions tools/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ target_include_directories(tests
PRIVATE ${PNG_INCLUDE_DIR}
PRIVATE ${PROJECT_SOURCE_DIR}/include
PRIVATE ./include
PRIVATE ${CMAKE_BINARY_DIR}/generated)
PRIVATE ${CMAKE_BINARY_DIR}/generated
PRIVATE $<TARGET_PROPERTY:tool_common,INTERFACE_INCLUDE_DIRECTORIES>)

target_link_libraries(tests
ray_tracer
tool_common
${PNG_LIBRARY}
GTest::gtest_main)
GTest::gtest_main)

0 comments on commit b1d9332

Please sign in to comment.