Skip to content

Commit

Permalink
chore: restruct samples in sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jyxiong committed Nov 11, 2024
1 parent ddfc5b5 commit b40c238
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 41 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_SHADERS_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/shaders)

add_subdirectory(external)
add_subdirectory(sandbox)
Expand Down
10 changes: 1 addition & 9 deletions sandbox/00_hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS *.cpp *.h *.hpp)

add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE prism)
target_compile_definitions(${PROJECT_NAME} PRIVATE PROJECT_FOLDER="${CMAKE_CURRENT_SOURCE_DIR}")
add_sample()
10 changes: 1 addition & 9 deletions sandbox/01_offscreen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS *.cpp *.h *.hpp)

add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE prism)
target_compile_definitions(${PROJECT_NAME} PRIVATE PROJECT_FOLDER="${CMAKE_CURRENT_SOURCE_DIR}")
add_sample()
23 changes: 1 addition & 22 deletions sandbox/02_compute_pipeline/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS *.cpp *.h *.hpp)

add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE prism)
target_compile_definitions(${PROJECT_NAME} PRIVATE PROJECT_FOLDER="${CMAKE_CURRENT_SOURCE_DIR}")

include(glsl)

file(GLOB GLSL_SHADERS ${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.comp)
unset(SPV_SHADERS)
foreach(GLSL_SHADER ${GLSL_SHADERS})
get_filename_component(SHADER_NAME ${GLSL_SHADER} NAME_WE)
set(SPV_SHADER ${CMAKE_SHADERS_OUTPUT_DIRECTORY}/${SHADER_NAME}.spv)
compile_glsl(${GLSL_SHADER} ${SPV_SHADER} SPV_SHADERS)
endforeach()
add_custom_target(${PROJECT_NAME}_shaders DEPENDS ${SPV_SHADERS})

add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_shaders)
add_sample()
29 changes: 29 additions & 0 deletions sandbox/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
macro(add_sample)

get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS *.cpp *.h *.hpp)

add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE prism)
target_compile_definitions(${PROJECT_NAME} PRIVATE PROJECT_FOLDER="${CMAKE_CURRENT_SOURCE_DIR}")
set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)

file(GLOB GLSL_SHADERS ${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.comp)
unset(SPV_SHADERS)
foreach(GLSL_SHADER ${GLSL_SHADERS})
get_filename_component(SHADER_NAME ${GLSL_SHADER} NAME_WE)
set(SPV_SHADER ${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER_NAME}.spv)
compile_glsl(${GLSL_SHADER} ${SPV_SHADER} SPV_SHADERS)
endforeach()
add_custom_target(${PROJECT_NAME}_shaders DEPENDS ${SPV_SHADERS})

add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_shaders)

endmacro(add_sample)

include(glsl)

add_subdirectory(00_hello_world)
add_subdirectory(01_offscreen)
add_subdirectory(02_compute_pipeline)

0 comments on commit b40c238

Please sign in to comment.