aboutsummaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-05-21 14:32:35 -0700
committerAnders Broman <a.broman58@gmail.com>2018-05-22 07:34:57 +0000
commiteed49613872b0f2ab52c52048b74bf50c6e2e212 (patch)
tree94dd3e3afdbe8c1770c4391063bd3ed224ddd9d5 /cmake
parent50197b30236f1b5b3e7ee8a90c57a3dbcbd835e5 (diff)
CMake: Search for asciidoctor-pdf separate from asciidoctor.
Search for asciidoctorj and asciidoctor-pdf and set ASCIIDOCTOR_PDF_EXECUTABLE if either are found. Only enable the PDF targets if we find ASCIIDOCTOR_PDF_EXECUTABLE. Remove env.cmake since it's no longer needed. Change-Id: Iee82b30eaa67d1ad3fd3a296d9997b0643a0cb4e Reviewed-on: https://code.wireshark.org/review/27696 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/env.cmake76
-rw-r--r--cmake/modules/FindAsciidoctor.cmake71
2 files changed, 46 insertions, 101 deletions
diff --git a/cmake/env.cmake b/cmake/env.cmake
deleted file mode 100644
index 677c94c4f9..0000000000
--- a/cmake/env.cmake
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# Set environment variables and execute a program.
-# Attempts to emulate "cmake -E env" which is only available since CMake 3.1.
-#
-# Copyright 2018 Peter Wu <peter@lekensteyn.nl>
-# SPDX-License-Identifier: MIT
-#
-# Usage:
-#
-# cmake -P env.cmake [NAME=VALUE]... [COMMAND [ARG]...]
-#
-# Limitations due to CMake:
-#
-# - The command and arguments cannot be keywords for the "execute_process"
-# command ("COMMAND", "ENCODING", "TIMEOUT", "WORKING_DIRECTORY", etc.).
-# - Empty arguments are ignored, arguments with a trailing backslash ("\") will
-# have the slash replaced by a forward slash ("/").
-# - If a program fails, a message will be printed and exit code 1 is returned.
-
-# Choose between two evils for the command line limitations:
-# (1) Hard-coded number of maximum arguments and repetitive lines.
-# (2) Limitations on the arguments (due to use of lists).
-# (3) A combination of both.
-# For simplicity, (2) is chosen here.
-set(command)
-
-math(EXPR argsCount "${CMAKE_ARGC} - 1")
-set(skip_args ${argsCount})
-set(maybe_env TRUE)
-
-foreach(argNumber RANGE ${argsCount})
- set(arg "${CMAKE_ARGV${argNumber}}")
-
- if(skip_args EQUAL 0)
- # Escape ";" (list separator) to avoid splitting arguments.
- string(REPLACE ";" "\\;" argForList "${arg}")
-
- # Prevent a trailing backslash from escaping the next list separator.
- # Hopefully it is just a path separator, otherwise there will be problems.
- if(argForList MATCHES "(.*)\\\\$")
- message(WARNING "Trailing backslash is converted to forward slash in: ${arg}")
- set(argForList "${CMAKE_MATCH_1}/")
- endif()
-
- if(argForList STREQUAL "")
- message(WARNING "Empty arguments are currently not supported and ignored")
- endif()
-
- if(maybe_env)
- # Try to parse NAME=VALUE
- if(arg MATCHES "^([^=]+)=(.*)$")
- set("ENV{${CMAKE_MATCH_1}}" "${CMAKE_MATCH_2}")
- else()
- set(maybe_env FALSE)
- list(APPEND command "${argForList}")
- endif()
- else()
- # Definitely no more env vars.
- list(APPEND command "${argForList}")
- endif()
- else()
- # Skip arguments until "-P env.cmake" is found.
- if(arg STREQUAL "-P")
- # just skip "env.cmake" from now on
- set(skip_args 1)
- else()
- math(EXPR skip_args "${skip_args} - 1")
- endif()
- endif()
-endforeach()
-
-execute_process(COMMAND ${command} RESULT_VARIABLE exitCode)
-
-if(NOT exitCode EQUAL 0)
- message(FATAL_ERROR "Process exited with ${exitCode}")
-endif()
diff --git a/cmake/modules/FindAsciidoctor.cmake b/cmake/modules/FindAsciidoctor.cmake
index f6328876d3..cdbb351311 100644
--- a/cmake/modules/FindAsciidoctor.cmake
+++ b/cmake/modules/FindAsciidoctor.cmake
@@ -19,6 +19,18 @@ FIND_PROGRAM(ASCIIDOCTOR_EXECUTABLE
DOC "Path to Asciidoctor or AsciidoctorJ"
)
+FIND_PROGRAM(ASCIIDOCTOR_PDF_EXECUTABLE
+ NAMES
+ asciidoctorj
+ asciidoctor-pdf
+ PATHS
+ /bin
+ /usr/bin
+ /usr/local/bin
+ ${CHOCOLATEY_BIN_PATH}
+ DOC "Path to Asciidoctor or AsciidoctorJ"
+)
+
if(ASCIIDOCTOR_EXECUTABLE)
# The AsciidctorJ wrapper script sets -Xmx256m. This isn't enough
# for the User's Guide.
@@ -42,14 +54,8 @@ if(ASCIIDOCTOR_EXECUTABLE)
--require ${CMAKE_CURRENT_SOURCE_DIR}/asciidoctor-macros/ws_salink-inline-macro.rb
)
- if(CMAKE_VERSION VERSION_LESS 3.1)
- set(_env_command ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/env.cmake)
- else()
- set(_env_command ${CMAKE_COMMAND} -E env)
- endif()
-
- set(_asciidoctor_common_command ${_env_command}
- TZ=UTC ASCIIDOCTORJ_OPTS="${_asciidoctorj_opts}"
+ set(_asciidoctor_common_command
+ ${CMAKE_COMMAND} -E env TZ=UTC ASCIIDOCTORJ_OPTS="${_asciidoctorj_opts}"
${ASCIIDOCTOR_EXECUTABLE}
${_asciidoctor_common_args}
)
@@ -118,26 +124,41 @@ if(ASCIIDOCTOR_EXECUTABLE)
# news: release-notes.txt
# ${CMAKE_COMMAND} -E copy_if_different release-notes.txt ../NEWS
- MACRO( ASCIIDOCTOR2PDF _asciidocsource )
- GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
- set( _output_pdf ${_source_base_name}.pdf )
+ if(ASCIIDOCTOR_PDF_EXECUTABLE)
- ADD_CUSTOM_COMMAND(
+ set(_asciidoctor_pdf_common_command
+ ${CMAKE_COMMAND} -E env TZ=UTC ASCIIDOCTORJ_OPTS="${_asciidoctorj_opts}"
+ ${ASCIIDOCTOR_PDF_EXECUTABLE}
+ --require asciidoctor-pdf
+ --backend pdf
+ ${_asciidoctor_common_args}
+ )
+
+ MACRO( ASCIIDOCTOR2PDF _asciidocsource )
+ GET_FILENAME_COMPONENT( _source_base_name ${_asciidocsource} NAME_WE )
+ set( _output_pdf ${_source_base_name}.pdf )
+
+ ADD_CUSTOM_COMMAND(
OUTPUT
- ${_output_pdf}
- COMMAND ${_asciidoctor_common_command}
- --backend pdf
- ${_asciidoctor_common_args}
- --out-file ${_output_pdf}
- ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
+ ${_output_pdf}
+ COMMAND ${_asciidoctor_pdf_common_command}
+ --out-file ${_output_pdf}
+ ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
DEPENDS
- ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
- ${ARGN}
- )
- add_custom_target(generate_${_output_pdf} DEPENDS ${_output_pdf})
- set_asciidoctor_target_properties(generate_${_output_pdf})
- unset(_output_pdf)
- ENDMACRO()
+ ${CMAKE_CURRENT_SOURCE_DIR}/${_asciidocsource}
+ ${ARGN}
+ )
+ add_custom_target(generate_${_output_pdf} DEPENDS ${_output_pdf})
+ set_asciidoctor_target_properties(generate_${_output_pdf})
+ unset(_output_pdf)
+ ENDMACRO()
+
+ else(ASCIIDOCTOR_PDF_EXECUTABLE)
+
+ MACRO( ASCIIDOCTOR2PDF _asciidocsource )
+ ENDMACRO()
+
+ endif(ASCIIDOCTOR_PDF_EXECUTABLE)
endif(ASCIIDOCTOR_EXECUTABLE)