diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index fa1b946..0cf8b26 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -8,5 +8,43 @@ # http://www.eclipse.org/org/documents/edl-v10.php. # # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause -add_subdirectory(manual) +include(FindPerl) +if(PERL_FOUND) + add_custom_command( + OUTPUT + options.md cyclonedds.rnc + COMMAND + ${PERL_EXECUTABLE} -w "${CMAKE_CURRENT_SOURCE_DIR}/makernc.pl" "${CMAKE_CURRENT_SOURCE_DIR}/../src/core/ddsi/src/q_config.c" options.md cyclonedds.rnc + COMMAND + ${PERL_EXECUTABLE} -w "${CMAKE_CURRENT_SOURCE_DIR}/compare.pl" options.md "${CMAKE_CURRENT_SOURCE_DIR}/manual/options.md" + COMMAND + ${PERL_EXECUTABLE} -w "${CMAKE_CURRENT_SOURCE_DIR}/compare.pl" cyclonedds.rnc "${CMAKE_CURRENT_SOURCE_DIR}/../etc/cyclonedds.rnc" + DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/makernc.pl" + "${CMAKE_CURRENT_SOURCE_DIR}/../src/core/ddsi/src/q_config.c") + add_custom_target(options_doc ALL DEPENDS "options.md" "cyclonedds.rnc") + find_package(Java COMPONENTS Runtime) + if(JAVA_FOUND AND EXISTS "${TRANG_PATH}" OR EXISTS "$ENV{TRANG}") + if(NOT EXISTS "${TRANG_PATH}" AND EXISTS "$ENV{TRANG}") + message(STATUS "Setting TRANG_PATH to $ENV{TRANG}") + set(TRANG_PATH "$ENV{TRANG}" CACHE FILEPATH "Location of 'trang' for converting XML schemas" FORCE) + endif() + add_custom_command( + OUTPUT + cyclonedds.xsd + COMMAND + ${Java_JAVA_EXECUTABLE} -jar "${TRANG_PATH}" -I rnc -O xsd cyclonedds.rnc cyclonedds.xsd + COMMAND + ${PERL_EXECUTABLE} -w "${CMAKE_CURRENT_SOURCE_DIR}/compare.pl" cyclonedds.xsd "${CMAKE_CURRENT_SOURCE_DIR}/../etc/cyclonedds.xsd" + DEPENDS + "cyclonedds.rnc") + add_custom_target(options_xsd ALL DEPENDS "cyclonedds.xsd") + else() + message(STATUS "Java or not trang not found: not converting/checking RNC to XSD") + endif() +else() + message(STATUS "perl not found: not generating/checking options documentation and RNC") +endif() + +add_subdirectory(manual) diff --git a/docs/compare.pl b/docs/compare.pl new file mode 100644 index 0000000..a8451a1 --- /dev/null +++ b/docs/compare.pl @@ -0,0 +1,8 @@ +open A, "< $ARGV[0]" or die "can't open $ARGV[0]"; +open B, "< $ARGV[1]" or die "can't open $ARGV[1]"; +while (defined ($a = ) && defined ($b = )) { + $a =~ s/[\r\n]+$//s; + $b =~ s/[\r\n]+$//s; + exit 1 unless $a eq $b; +} +exit 0; diff --git a/docs/makernc.pl b/docs/makernc.pl index 42033d1..07a67db 100644 --- a/docs/makernc.pl +++ b/docs/makernc.pl @@ -495,7 +495,7 @@ sub read_config { my @stk = (); # stack of conditional nesting, for each: copy/discard/ignore open FH, "<", $input or die "can't open $input\n"; while () { - chomp; + s/[\r\n]+$//s; # ignore parts guarded by #if/#ifdef/#if!/#ifndef if $incl says so if (/^\s*\#\s*if(n?def|\s*!)?\s*([A-Za-z_][A-Za-z_0-9]*)\s*(?:\/(?:\/.*|\*.*?\*\/)\s*)?$/) {