Skip to content

Commit 86a716d

Browse files
committed
Define CLI options in JSON
1 parent d70cb22 commit 86a716d

File tree

10 files changed

+1238
-179
lines changed

10 files changed

+1238
-179
lines changed

application/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function(f3d_create_exec target_name)
3030
set_target_properties(${target_name} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=$<TARGET_FILE_DIR:VTK::CommonCore>") # Add VTK in MSVC PATH environment variable
3131
endif ()
3232

33+
add_dependencies(${target_name} generate_cli_opts_header)
3334
target_include_directories(${target_name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
3435

3536
if (F3D_USE_EXTERNAL_CXXOPTS)
@@ -182,6 +183,19 @@ f3d_embed_file(
182183
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/F3DConfig.h.in"
183184
"${CMAKE_CURRENT_BINARY_DIR}/F3DConfig.h")
184185

186+
add_custom_command(
187+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/F3DCLIOptions.h"
188+
COMMAND ${CMAKE_COMMAND} -D srcDir=${CMAKE_SOURCE_DIR} -D binaryDir=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_SOURCE_DIR}/cmake/f3dCLIOpts.cmake
189+
DEPENDS
190+
${CMAKE_SOURCE_DIR}/resources/cli-options.schema.json
191+
${CMAKE_SOURCE_DIR}/resources/cli-options.json
192+
VERBATIM
193+
)
194+
195+
add_custom_target(generate_cli_opts_header
196+
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/F3DCLIOptions.h"
197+
)
198+
185199
set(F3D_SOURCE_FILES
186200
${CMAKE_CURRENT_BINARY_DIR}/F3DIcon.cxx
187201
${CMAKE_CURRENT_SOURCE_DIR}/F3DColorMapTools.cxx
@@ -313,6 +327,12 @@ if(UNIX AND NOT APPLE AND NOT ANDROID)
313327
install(FILES "${F3D_SOURCE_DIR}/resources/logo-mono.svg"
314328
DESTINATION "share/icons/HighContrast/scalable/apps" COMPONENT assets
315329
RENAME "f3d.svg")
330+
install(FILES
331+
"${F3D_SOURCE_DIR}/resources/cli-options.json"
332+
"${F3D_SOURCE_DIR}/resources/cli-options.schema.json"
333+
DESTINATION "${f3d_resources_dir}"
334+
COMPONENT shellext
335+
)
316336
install(FILES "${F3D_SOURCE_DIR}/resources/completion.bash"
317337
DESTINATION "share/bash-completion/completions" COMPONENT shellext
318338
RENAME "f3d")

application/F3DCLIOptions.h.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef F3DCLIOptions_h
2+
#define F3DCLIOptions_h
3+
4+
#include <string_view>
5+
6+
namespace F3D
7+
{
8+
constexpr std::string_view CLI_OPTIONS_JSON = R"END(@CLI_OPTIONS_JSON@)END";
9+
}
10+
11+
#endif

application/F3DOptionsTools.cxx

Lines changed: 95 additions & 166 deletions
Large diffs are not rendered by default.

application/testing/tests.features.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ f3d_test(NAME TestExactMatch DATA suzanne.obj CONFIG ${CMAKE_BINARY_DIR}/exact.j
696696
# Test help display
697697
f3d_test(NAME TestHelp ARGS --help REGEXP "Usage:")
698698
f3d_test(NAME TestHelpPositional ARGS --help REGEXP "file1 file2 \.\.\.")
699+
f3d_test(NAME TestHelpVersionPresent ARGS --help REGEXP "--version")
699700

700701
# Test version display
701702
f3d_test(NAME TestVersion ARGS --version REGEXP "Version:")

cmake/f3dCLIOpts.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
file(READ ${srcDir}/resources/cli-options.json CLI_OPTIONS_JSON)
2+
3+
configure_file(${srcDir}/application/F3DCLIOptions.h.in
4+
${binaryDir}/F3DCLIOptions.h)

0 commit comments

Comments
 (0)