mirror of
https://github.com/PixarAnimationStudios/OpenSubdiv
synced 2024-12-23 00:10:07 +00:00
Improve stringification of shaders & kernels in build.
- added a _stringify function to top CMakeLists - switched all stringification tasks to use the macro - all suffixes are now .gen.h instead of .inc (to help cmake track dependencies)
This commit is contained in:
parent
5c4e8286e5
commit
8918173fda
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,9 +1,4 @@
|
||||
|
||||
# ignore stringified kernels
|
||||
*.inc
|
||||
*.inc.rule
|
||||
*.gen.h
|
||||
|
||||
# ignore build files
|
||||
/build*
|
||||
/inst*
|
||||
|
@ -495,6 +495,38 @@ macro(_add_doxy_headers headers)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Kernel Stringification
|
||||
# We want to use preprocessor include directives to include GLSL and OpenCL
|
||||
# kernel source files in cpp files, but since the sources contain newline
|
||||
# characters we would need raw string literals from C++11 to do this directly.
|
||||
# To avoid depending on C++11 we instead use a small tool called "line_quote"
|
||||
# to generate source files that are suitable for direct inclusion.
|
||||
function(_stringify src_files varname)
|
||||
|
||||
set(inc_files "")
|
||||
|
||||
foreach(src_file ${src_files})
|
||||
|
||||
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${src_file})
|
||||
|
||||
if(NOT ${extension} STREQUAL "cu")
|
||||
|
||||
string(REGEX REPLACE "(.*)[.].*" "\\1.gen.h" inc_file ${src_file})
|
||||
list(APPEND inc_files ${inc_file})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${inc_file}
|
||||
COMMAND
|
||||
stringify ${CMAKE_CURRENT_SOURCE_DIR}/${src_file} ${CMAKE_CURRENT_BINARY_DIR}/${inc_file}
|
||||
DEPENDS
|
||||
stringify ${CMAKE_CURRENT_SOURCE_DIR}/${src_file}
|
||||
)
|
||||
|
||||
endif()
|
||||
endforeach()
|
||||
set(${varname} ${inc_files} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Macro wrapper for adding a non-cuda dependent executable
|
||||
macro(_add_executable target)
|
||||
|
@ -45,27 +45,9 @@ set(SOURCE_FILES
|
||||
dxPtexViewer.cpp
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Shader Stringification
|
||||
# We want to use preprocessor include directives to include GLSL and OpenCL
|
||||
# shader source files in cpp files, but since the sources contain newline
|
||||
# characters we would need raw string literals from C++11 to do this directly.
|
||||
# To avoid depending on C++11 we instead use a small tool called "line_quote"
|
||||
# to generate source files that are suitable for direct inclusion.
|
||||
foreach(shader_file ${SHADER_FILES})
|
||||
_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${shader_file})
|
||||
|
||||
string(REGEX REPLACE "(.*)[.].*" "\\1.inc" inc_file ${shader_file})
|
||||
list(APPEND INC_FILES ${inc_file})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
)
|
||||
endforeach()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
_add_possibly_cuda_executable(dxPtexViewer WIN32
|
||||
${SOURCE_FILES}
|
||||
|
@ -83,7 +83,7 @@ OpenSubdiv::OsdD3D11MeshInterface *g_mesh;
|
||||
#include "../../regression/common/shape_utils.h"
|
||||
|
||||
static const char *g_shaderSource =
|
||||
#include "shader.inc"
|
||||
#include "shader.gen.h"
|
||||
;
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -43,27 +43,9 @@ set(SOURCE_FILES
|
||||
dxViewer.cpp
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Shader Stringification
|
||||
# We want to use preprocessor include directives to include GLSL and OpenCL
|
||||
# shader source files in cpp files, but since the sources contain newline
|
||||
# characters we would need raw string literals from C++11 to do this directly.
|
||||
# To avoid depending on C++11 we instead use a small tool called "line_quote"
|
||||
# to generate source files that are suitable for direct inclusion.
|
||||
foreach(shader_file ${SHADER_FILES})
|
||||
_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${shader_file})
|
||||
|
||||
string(REGEX REPLACE "(.*)[.].*" "\\1.inc" inc_file ${shader_file})
|
||||
list(APPEND INC_FILES ${inc_file})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
)
|
||||
endforeach()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
_add_possibly_cuda_executable(dxViewer WIN32
|
||||
${SOURCE_FILES}
|
||||
|
@ -79,7 +79,7 @@ OpenSubdiv::OsdD3D11MeshInterface *g_mesh;
|
||||
#include "../common/d3d11_hud.h"
|
||||
|
||||
static const char *shaderSource =
|
||||
#include "shader.inc"
|
||||
#include "shader.gen.h"
|
||||
;
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -46,27 +46,9 @@ if ( GLEW_FOUND )
|
||||
list(APPEND PLATFORM_LIBRARIES ${GLEW_LIBRARY})
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Shader Stringification
|
||||
# We want to use preprocessor include directives to include GLSL and OpenCL
|
||||
# shader source files in cpp files, but since the sources contain newline
|
||||
# characters we would need raw string literals from C++11 to do this directly.
|
||||
# To avoid depending on C++11 we instead use a small tool called "line_quote"
|
||||
# to generate source files that are suitable for direct inclusion.
|
||||
foreach(shader_file ${SHADER_FILES})
|
||||
_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${shader_file})
|
||||
|
||||
string(REGEX REPLACE "(.*)[.].*" "\\1.inc" inc_file ${shader_file})
|
||||
list(APPEND INC_FILES ${inc_file})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
)
|
||||
endforeach()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
_add_glfw_executable(glBatchViewer
|
||||
viewer.cpp
|
||||
|
@ -28,9 +28,9 @@
|
||||
|
||||
static const char *shaderSource =
|
||||
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
||||
#include "shader.inc"
|
||||
#include "shader.gen.h"
|
||||
#else
|
||||
#include "shader_gl3.inc"
|
||||
#include "shader_gl3.gen.h"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
@ -46,27 +46,9 @@ if ( GLEW_FOUND )
|
||||
list(APPEND PLATFORM_LIBRARIES ${GLEW_LIBRARY})
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Shader Stringification
|
||||
# We want to use preprocessor include directives to include GLSL and OpenCL
|
||||
# shader source files in cpp files, but since the sources contain newline
|
||||
# characters we would need raw string literals from C++11 to do this directly.
|
||||
# To avoid depending on C++11 we instead use a small tool called "line_quote"
|
||||
# to generate source files that are suitable for direct inclusion.
|
||||
foreach(shader_file ${SHADER_FILES})
|
||||
_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${shader_file})
|
||||
|
||||
string(REGEX REPLACE "(.*)[.].*" "\\1.inc" inc_file ${shader_file})
|
||||
list(APPEND INC_FILES ${inc_file})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
)
|
||||
endforeach()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
_add_glfw_executable(glViewer
|
||||
viewer.cpp
|
||||
|
@ -122,9 +122,9 @@ OpenSubdiv::OsdGLMeshInterface *g_mesh;
|
||||
|
||||
static const char *shaderSource =
|
||||
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
||||
#include "shader.inc"
|
||||
#include "shader.gen.h"
|
||||
#else
|
||||
#include "shader_gl3.inc"
|
||||
#include "shader_gl3.gen.h"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
@ -43,27 +43,9 @@ include_directories(
|
||||
${GLFW_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Shader Stringification
|
||||
# We want to use preprocessor include directives to include GLSL and OpenCL
|
||||
# shader source files in cpp files, but since the sources contain newline
|
||||
# characters we would need raw string literals from C++11 to do this directly.
|
||||
# To avoid depending on C++11 we instead use a small tool called "line_quote"
|
||||
# to generate source files that are suitable for direct inclusion.
|
||||
foreach(shader_file ${SHADER_FILES})
|
||||
_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${shader_file})
|
||||
|
||||
string(REGEX REPLACE "(.*)[.].*" "\\1.inc" inc_file ${shader_file})
|
||||
list(APPEND INC_FILES ${inc_file})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
)
|
||||
endforeach()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
_add_glfw_executable(paintTest
|
||||
main.cpp
|
||||
|
@ -65,10 +65,10 @@ OpenSubdiv::OsdGLMeshInterface *g_mesh;
|
||||
#include "../common/gl_hud.h"
|
||||
|
||||
static const char *shaderSource =
|
||||
#include "shader.inc"
|
||||
#include "shader.gen.h"
|
||||
;
|
||||
static const char *paintShaderSource =
|
||||
#include "paintShader.inc"
|
||||
#include "paintShader.gen.h"
|
||||
;
|
||||
|
||||
#include <cfloat>
|
||||
|
@ -55,26 +55,10 @@ if ( GLEW_FOUND )
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Shader Stringification
|
||||
# We want to use preprocessor include directives to include GLSL and OpenCL
|
||||
# shader source files in cpp files, but since the sources contain newline
|
||||
# characters we would need raw string literals from C++11 to do this directly.
|
||||
# To avoid depending on C++11 we instead use a small tool called "line_quote"
|
||||
# to generate source files that are suitable for direct inclusion.
|
||||
foreach(shader_file ${SHADER_FILES})
|
||||
|
||||
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${shader_file})
|
||||
_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
string(REGEX REPLACE "(.*)[.].*" "\\1.inc" inc_file ${shader_file})
|
||||
list(APPEND INC_FILES ${inc_file})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
)
|
||||
endforeach()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
_add_glfw_executable(ptexViewer
|
||||
|
@ -131,16 +131,16 @@ OpenSubdiv::OsdGLMeshInterface *g_mesh;
|
||||
|
||||
static const char *g_defaultShaderSource =
|
||||
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
||||
#include "shader.inc"
|
||||
#include "shader.gen.h"
|
||||
#else
|
||||
#include "shader_gl3.inc"
|
||||
#include "shader_gl3.gen.h"
|
||||
#endif
|
||||
;
|
||||
static const char *g_skyShaderSource =
|
||||
#include "skyshader.inc"
|
||||
#include "skyshader.gen.h"
|
||||
;
|
||||
static const char *g_imageShaderSource =
|
||||
#include "imageshader.inc"
|
||||
#include "imageshader.gen.h"
|
||||
;
|
||||
static std::string g_shaderSource;
|
||||
static const char *g_shaderFilename = NULL;
|
||||
|
@ -46,26 +46,10 @@ if ( GLEW_FOUND )
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Shader Stringification
|
||||
# We want to use preprocessor include directives to include GLSL and OpenCL
|
||||
# shader source files in cpp files, but since the sources contain newline
|
||||
# characters we would need raw string literals from C++11 to do this directly.
|
||||
# To avoid depending on C++11 we instead use a small tool called "line_quote"
|
||||
# to generate source files that are suitable for direct inclusion.
|
||||
foreach(shader_file ${SHADER_FILES})
|
||||
|
||||
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${shader_file})
|
||||
_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
string(REGEX REPLACE "(.*)[.].*" "\\1.inc" inc_file ${shader_file})
|
||||
list(APPEND INC_FILES ${inc_file})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
)
|
||||
endforeach()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
_add_glfw_executable(simpleCpu
|
||||
main.cpp
|
||||
|
@ -84,7 +84,7 @@ GLuint g_quadFillProgram = 0;
|
||||
// see [shader.glsl](shader.html).
|
||||
//
|
||||
static const char *shaderSource =
|
||||
#include "shader.inc"
|
||||
#include "shader.gen.h"
|
||||
;
|
||||
|
||||
GLfloat g_modelView[16], g_proj[16], g_mvp[16];
|
||||
|
@ -46,26 +46,10 @@ if ( GLEW_FOUND )
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Shader Stringification
|
||||
# We want to use preprocessor include directives to include GLSL and OpenCL
|
||||
# shader source files in cpp files, but since the sources contain newline
|
||||
# characters we would need raw string literals from C++11 to do this directly.
|
||||
# To avoid depending on C++11 we instead use a small tool called "line_quote"
|
||||
# to generate source files that are suitable for direct inclusion.
|
||||
foreach(shader_file ${SHADER_FILES})
|
||||
|
||||
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${shader_file})
|
||||
_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
string(REGEX REPLACE "(.*)[.].*" "\\1.inc" inc_file ${shader_file})
|
||||
list(APPEND INC_FILES ${inc_file})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${shader_file}
|
||||
)
|
||||
endforeach()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
_add_glfw_executable(uvViewer
|
||||
viewer.cpp
|
||||
|
@ -66,9 +66,9 @@ OpenSubdiv::OsdGLMeshInterface *g_mesh = NULL;
|
||||
|
||||
static const char *shaderSource =
|
||||
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
||||
#include "shader.inc"
|
||||
#include "shader.gen.h"
|
||||
#else
|
||||
#include "shader_gl3.inc"
|
||||
#include "shader_gl3.gen.h"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
@ -434,30 +434,10 @@ endif()
|
||||
list(APPEND DOXY_HEADER_FILES ${CUDA_PUBLIC_HEADERS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Kernel Stringification
|
||||
# We want to use preprocessor include directives to include GLSL and OpenCL
|
||||
# kernel source files in cpp files, but since the sources contain newline
|
||||
# characters we would need raw string literals from C++11 to do this directly.
|
||||
# To avoid depending on C++11 we instead use a small tool called "line_quote"
|
||||
# to generate source files that are suitable for direct inclusion.
|
||||
foreach(kernel_file ${KERNEL_FILES})
|
||||
|
||||
string(REGEX REPLACE ".*[.](.*)" "\\1" extension ${kernel_file})
|
||||
_stringify("${KERNEL_FILES}" INC_FILES)
|
||||
|
||||
if(NOT ${extension} STREQUAL "cu")
|
||||
|
||||
string(REGEX REPLACE "(.*)[.].*" "\\1.gen.h" inc_file ${kernel_file})
|
||||
list(APPEND INC_FILES ${inc_file})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
COMMAND stringify ${CMAKE_CURRENT_SOURCE_DIR}/${kernel_file}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${inc_file}
|
||||
DEPENDS stringify ${CMAKE_CURRENT_SOURCE_DIR}/${kernel_file}
|
||||
)
|
||||
|
||||
endif()
|
||||
endforeach()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
source_group("Kernels" FILES ${KERNEL_FILES})
|
||||
|
Loading…
Reference in New Issue
Block a user