Skip to content

Commit

Permalink
Merge topic 'deprecate-vtk-encode-string'
Browse files Browse the repository at this point in the history
5215867 Utilities/EncodeString: deprecate for the vtkEncodeString module
420c9a2 vtkEncodeString: replace the executable with a CMake script
4fc25a6 vtkEncodeString: add a module to write a C string for content

Acked-by: Kitware Robot <[email protected]>
Acked-by: Brad King <[email protected]>
Merge-request: !3605
  • Loading branch information
mathstuf authored and kwrobot committed Nov 27, 2017
2 parents c89be39 + 5215867 commit 7961011
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 146 deletions.
158 changes: 158 additions & 0 deletions CMake/vtkEncodeString.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#[==[.md
# vtkEncodeString
This module contains the `vtk_encode_string` function which may be used to turn
a file into a C string. This is primarily used within a program so that the
content does not need to be retrieved from the filesystem at runtime, but can
still be developed as a standalone file.
#]==]

set(_vtkEncodeString_script_file "${CMAKE_CURRENT_LIST_FILE}")

include(CMakeParseArguments)

#[==[.md
# `vtk_encode_string`
Adds a rule to turn a file into a C string. Note that any Unicode characters
will not be replaced with escaping, so it is recommended to avoid their usage
in the input.
```
vtk_encode_string
INPUT <input>
[NAME <name>]
[EXPORT_SYMBOL <symbol>]
[EXPORT_HEADER <header>
[HEADER_OUTPUT <variable>]
[SOURCE_OUTPUT <variable>])
```
The only required variable is `INPUT`, however, it is likely that at least one
of `HEADER_OUTPUT` or `SOURCE_OUTPUT` will be required to add them to a
library.
* `INPUT`: (Required) The path to the file to be embedded. If a relative path
is given, it will be interpreted as being relative to
`CMAKE_CURRENT_SOURCE_DIR`.
* `NAME`: This is the base name of the files that will be generated as well
as the variable name for the C string. It defaults to the basename of the
input without extensions.
* `EXPORT_SYMBOL`: The symbol to use for exporting the variable. By default,
it will not be exported. If set, `EXPORT_HEADER` must also be set.
* `EXPORT_HEADER`: The header to include for providing the given export
symbol. If set, `EXPORT_SYMBOL` should also be set.
* `HEADER_OUTPUT`: The variable to store the generated header path.
* `SOURCE_OUTPUT`: The variable to store the generated source path.
#]==]
function (vtk_encode_string)
cmake_parse_arguments(_vtk_encode_string
""
"INPUT;NAME;EXPORT_SYMBOL;EXPORT_HEADER;HEADER_OUTPUT;SOURCE_OUTPUT"
""
${ARGN})

if (_vtk_encode_string_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unrecognized arguments to vtk_encode_string: "
"${_vtk_encode_string_UNPARSED_ARGUMENTS}")
endif ()

if (NOT DEFINED _vtk_encode_string_INPUT)
message(FATAL_ERROR
"Missing `INPUT` for vtk_encode_string.")
endif ()

if (NOT DEFINED _vtk_encode_string_NAME)
get_filename_component(_vtk_encode_string_NAME
"${_vtk_encode_string_INPUT}" NAME_WE)
endif ()

if (DEFINED _vtk_encode_string_EXPORT_SYMBOL AND
NOT DEFINED _vtk_encode_string_EXPORT_HEADER)
message(FATAL_ERROR
"Missing `EXPORT_HEADER` when using `EXPORT_SYMBOL`.")
endif ()

if (DEFINED _vtk_encode_string_EXPORT_HEADER AND
NOT DEFINED _vtk_encode_string_EXPORT_SYMBOL)
message(WARNING
"Missing `EXPORT_SYMBOL` when using `EXPORT_HEADER`.")
endif ()

set(_vtk_encode_string_header
"${CMAKE_CURRENT_BINARY_DIR}/${_vtk_encode_string_NAME}.h")
set(_vtk_encode_string_source
"${CMAKE_CURRENT_BINARY_DIR}/${_vtk_encode_string_NAME}.cxx")

if (IS_ABSOLUTE "${_vtk_encode_string_INPUT}")
set(_vtk_encode_string_input
"${_vtk_encode_string_INPUT}")
else ()
set(_vtk_encode_string_input
"${CMAKE_CURRENT_SOURCE_DIR}/${_vtk_encode_string_INPUT}")
endif ()

add_custom_command(
OUTPUT ${_vtk_encode_string_header}
${_vtk_encode_string_source}
DEPENDS "${_vtkEncodeString_script_file}"
"${_vtk_encode_string_input}"
COMMAND "${CMAKE_COMMAND}"
"-Dsource_dir=${CMAKE_CURRENT_SOURCE_DIR}"
"-Dbinary_dir=${CMAKE_CURRENT_BINARY_DIR}"
"-Dsource_file=${_vtk_encode_string_input}"
"-Doutput_name=${_vtk_encode_string_NAME}"
"-Dexport_symbol=${_vtk_encode_string_EXPORT_SYMBOL}"
"-Dexport_header=${_vtk_encode_string_EXPORT_HEADER}"
"-D_vtk_encode_string_run=ON"
-P "${_vtkEncodeString_script_file}")

if (DEFINED _vtk_encode_string_SOURCE_OUTPUT)
set("${_vtk_encode_string_SOURCE_OUTPUT}"
"${_vtk_encode_string_source}"
PARENT_SCOPE)
endif ()

if (DEFINED _vtk_encode_string_HEADER_OUTPUT)
set("${_vtk_encode_string_HEADER_OUTPUT}"
"${_vtk_encode_string_header}"
PARENT_SCOPE)
endif ()
endfunction ()

if (_vtk_encode_string_run)
set(output_header "${binary_dir}/${output_name}.h")
set(output_source "${binary_dir}/${output_name}.cxx")

file(WRITE "${output_header}" "")
file(WRITE "${output_source}" "")

file(APPEND "${output_header}"
"#ifndef ${output_name}_h\n#define ${output_name}_h\n\n")
if (export_symbol)
file(APPEND "${output_header}"
"#include \"${export_header}\"\n\n${export_symbol} ")
endif ()
file(APPEND "${output_header}"
"extern const char *${output_name};\n\n#endif\n")

if (IS_ABSOLUTE "${source_file}")
set(source_file_full "${source_file}")
else ()
set(source_file_full "${source_dir}/${source_file}")
endif ()
file(READ "${source_file_full}" original_content)

# Escape literal backslashes.
string(REPLACE "\\" "\\\\" escaped_content "${original_content}")
# Escape literal double quotes.
string(REPLACE "\"" "\\\"" escaped_content "${escaped_content}")
# Turn newlines into newlines in the C string.
string(REPLACE "\n" "\\n\"\n\"" escaped_content "${escaped_content}")

file(APPEND "${output_source}"
"#include \"${output_name}.h\"\n\nconst char *${output_name} =\n")
file(APPEND "${output_source}"
"\"${escaped_content}\";\n")
endif ()
1 change: 1 addition & 0 deletions CMake/vtkModuleTop.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ if (NOT VTK_INSTALL_NO_DEVELOPMENT)
CMake/vtkTclTkMacros.cmake
CMake/vtk-forward.c.in
CMake/vtkGroups.cmake
CMake/vtkEncodeString.cmake
CMake/vtkForwardingExecutable.cmake
CMake/vtkJavaWrapping.cmake
CMake/vtkModuleAPI.cmake
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ endif()
option(VTK_ENABLE_KITS "Build VTK using kits instead of modules." OFF)
mark_as_advanced(VTK_ENABLE_KITS)

include(vtkEncodeString)

#----------------------------------------------------------------------
# Load the module DAG, assess all modules etc.
include(vtkModuleTop)
Expand Down
24 changes: 10 additions & 14 deletions Rendering/LIC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,16 @@ set(shader_files

unset(shader_h_files)
foreach(file ${shader_files})
get_filename_component(file_we ${file} NAME_WE)
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${file})
set(res ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.cxx)
set(resh ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.h)
list(APPEND shader_h_files ${resh})
add_custom_command(
OUTPUT ${res} ${resh}
DEPENDS ${src} vtkEncodeString
COMMAND vtkEncodeString
ARGS ${res} ${src} ${file_we}
--build-header VTKRENDERINGLIC_EXPORT vtkRenderingLICModule.h
)
list(APPEND Module_SRCS ${res})
set_source_files_properties(${file_we}
vtk_encode_string(
INPUT "${file}"
EXPORT_SYMBOL "VTKRENDERINGLIC_EXPORT"
EXPORT_HEADER "vtkRenderingLICModule.h"
HEADER_OUTPUT header
SOURCE_OUTPUT source)
list(APPEND Module_SRCS ${source})
set_source_files_properties(
${header}
${source}
PROPERTIES
WRAP_EXCLUDE 1
WRAP_EXCLUDE_PYTHON 1
Expand Down
24 changes: 10 additions & 14 deletions Rendering/LICOpenGL2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,16 @@ set(shader_files
)
unset(shader_h_files)
foreach(file ${shader_files})
get_filename_component(file_we ${file} NAME_WE)
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${file})
set(res ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.cxx)
set(resh ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.h)
list(APPEND shader_h_files ${resh})
add_custom_command(
OUTPUT ${res} ${resh}
DEPENDS ${src} vtkEncodeString
COMMAND vtkEncodeString
ARGS ${res} ${src} ${file_we}
--build-header VTKRENDERINGLICOPENGL2_EXPORT vtkRenderingLICOpenGL2Module.h
)
list(APPEND Module_SRCS ${res})
set_source_files_properties(${file_we}
vtk_encode_string(
INPUT "${file}"
EXPORT_SYMBOL "VTKRENDERINGLICOPENGL2_EXPORT"
EXPORT_HEADER "vtkRenderingLICOpenGL2Module.h"
HEADER_OUTPUT header
SOURCE_OUTPUT source)
list(APPEND Module_SRCS ${source})
set_source_files_properties(
${header}
${source}
PROPERTIES
WRAP_EXCLUDE 1
WRAP_EXCLUDE_PYTHON 1
Expand Down
23 changes: 10 additions & 13 deletions Rendering/OpenGL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,16 @@ set(shader_files

unset(shader_h_files)
foreach(file ${shader_files})
get_filename_component(file_we ${file} NAME_WE)
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${file})
set(res ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.cxx)
set(resh ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.h)
list(APPEND shader_h_files ${resh})
add_custom_command(
OUTPUT ${res} ${resh}
DEPENDS ${src} vtkEncodeString
COMMAND vtkEncodeString
ARGS ${res} ${src} ${file_we} --build-header VTKRENDERINGOPENGL_EXPORT vtkRenderingOpenGLModule.h
)
list(APPEND Module_SRCS ${res})
set_source_files_properties(${file_we}
vtk_encode_string(
INPUT "${file}"
EXPORT_SYMBOL "VTKRENDERINGOPENGL_EXPORT"
EXPORT_HEADER "vtkRenderingOpenGLModule.h"
HEADER_OUTPUT header
SOURCE_OUTPUT source)
list(APPEND Module_SRCS ${source})
set_source_files_properties(
${header}
${source}
PROPERTIES
WRAP_EXCLUDE 1
WRAP_EXCLUDE_PYTHON 1
Expand Down
3 changes: 1 addition & 2 deletions Rendering/OpenGL/module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ vtk_module(vtkRenderingOpenGL
IMPLEMENTATION_REQUIRED_BY_BACKEND
COMPILE_DEPENDS
vtkParseOGLExt
vtkUtilitiesEncodeString
TEST_DEPENDS
vtkInteractionStyle
vtkTestingRendering
Expand Down Expand Up @@ -37,4 +36,4 @@ vtk_module(vtkRenderingOpenGL
vtkImagingCore
vtkImagingHybrid
vtksys
)
)
24 changes: 10 additions & 14 deletions Rendering/OpenGL2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,16 @@ set(shader_files
)
unset(shader_h_files)
foreach(file ${shader_files})
get_filename_component(file_we ${file} NAME_WE)
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${file})
set(res ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.cxx)
set(resh ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.h)
list(APPEND shader_h_files ${resh})
add_custom_command(
OUTPUT ${res} ${resh}
DEPENDS ${src} vtkEncodeString
COMMAND vtkEncodeString
ARGS ${res} ${src} ${file_we}
--build-header VTKRENDERINGOPENGL2_EXPORT vtkRenderingOpenGL2Module.h
)
list(APPEND Module_SRCS ${res})
set_source_files_properties(${file_we}
vtk_encode_string(
INPUT "${file}"
EXPORT_SYMBOL "VTKRENDERINGOPENGL2_EXPORT"
EXPORT_HEADER "vtkRenderingOpenGL2Module.h"
HEADER_OUTPUT header
SOURCE_OUTPUT source)
list(APPEND Module_SRCS ${source})
set_source_files_properties(
${header}
${source}
PROPERTIES
WRAP_EXCLUDE 1
WRAP_EXCLUDE_PYTHON 1
Expand Down
2 changes: 0 additions & 2 deletions Rendering/OpenGL2/module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ vtk_module(vtkRenderingOpenGL2
BACKEND
OpenGL2
IMPLEMENTATION_REQUIRED_BY_BACKEND
COMPILE_DEPENDS
vtkUtilitiesEncodeString
TEST_DEPENDS
vtkIOLegacy
vtkRenderingImage
Expand Down
24 changes: 10 additions & 14 deletions Rendering/Parallel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,16 @@ set(shader_files vtkCompositeZPassShader_fs.glsl vtkCompositeZPassFS.glsl)

unset(shader_h_files)
foreach(file ${shader_files})
get_filename_component(file_we ${file} NAME_WE)
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${file})
set(res ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.cxx)
set(resh ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.h)
list(APPEND shader_h_files ${resh})
add_custom_command(
OUTPUT ${res} ${resh}
DEPENDS ${src} vtkEncodeString
COMMAND vtkEncodeString
ARGS ${res} ${src} ${file_we}
--build-header VTKRENDERINGPARALLEL_EXPORT vtkRenderingParallelModule.h
)
list(APPEND Module_SRCS ${res})
set_source_files_properties(${file_we}
vtk_encode_string(
INPUT "${file}"
EXPORT_SYMBOL "VTKRENDERINGPARALLEL_EXPORT"
EXPORT_HEADER "vtkRenderingParallelModule.h"
HEADER_OUTPUT header
SOURCE_OUTPUT source)
list(APPEND Module_SRCS ${source})
set_source_files_properties(
${header}
${source}
PROPERTIES
WRAP_EXCLUDE 1
WRAP_EXCLUDE_PYTHON 1
Expand Down
26 changes: 10 additions & 16 deletions Rendering/ParallelLIC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,16 @@ endif()

unset(shader_h_files)
foreach(file ${shader_files})
get_filename_component(file_we ${file} NAME_WE)
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${file})
set(res ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.cxx)
set(resh ${CMAKE_CURRENT_BINARY_DIR}/${file_we}.h)
list(APPEND shader_h_files ${resh})
add_custom_command(
OUTPUT ${res} ${resh}
DEPENDS ${src} vtkEncodeString
COMMAND vtkEncodeString
ARGS ${res} ${src} ${file_we}
--build-header
VTKRENDERINGPARALLELLIC_EXPORT
vtkRenderingParallelLICModule.h
)
list(APPEND Module_SRCS ${res})
set_source_files_properties(${file_we}
vtk_encode_string(
INPUT "${file}"
EXPORT_SYMBOL "VTKRENDERINGPARALLELLIC_EXPORT"
EXPORT_HEADER "vtkRenderingParallelLICModule.h"
HEADER_OUTPUT header
SOURCE_OUTPUT source)
list(APPEND Module_SRCS ${source})
set_source_files_properties(
${header}
${source}
PROPERTIES
WRAP_EXCLUDE 1
WRAP_EXCLUDE_PYTHON 1
Expand Down
Loading

0 comments on commit 7961011

Please sign in to comment.