summaryrefslogtreecommitdiffstats
path: root/CMake
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-18 07:05:45 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-18 07:06:07 -0400
commita246e9b4c7d280a69bfc525c03246ddfd75f54fd (patch)
tree459c35dee3c1f56848c679ba4623071cc0c863c1 /CMake
parentMerge pull request #65 from taiyu-len/focus_v2 (diff)
downloadsway-a246e9b4c7d280a69bfc525c03246ddfd75f54fd.tar.gz
sway-a246e9b4c7d280a69bfc525c03246ddfd75f54fd.tar.zst
sway-a246e9b4c7d280a69bfc525c03246ddfd75f54fd.zip
Find a2x through CMake
Fixes #63
Diffstat (limited to 'CMake')
-rw-r--r--CMake/FindA2X.cmake75
1 files changed, 75 insertions, 0 deletions
diff --git a/CMake/FindA2X.cmake b/CMake/FindA2X.cmake
new file mode 100644
index 00000000..b38f5086
--- /dev/null
+++ b/CMake/FindA2X.cmake
@@ -0,0 +1,75 @@
1#
2# (c)2015 KiCad Developers
3# (c)2015 Brian Sidebotham <brian.sidebotham@gmail.com>
4#
5# CMake module to find a2x (part of the asciidoc toolchain).
6#
7# Variables generated:
8#
9# A2X_FOUND true when A2X_COMMAND is valid
10# A2X_COMMAND The command to run a2x (may be a list including an interpreter)
11# A2X_VERSION The a2x version that has been found
12#
13
14# Have a go at finding a a2x executable
15find_program( A2X_PROGRAM a2x )
16
17# Found something, attempt to try and use it...
18if( A2X_PROGRAM )
19 execute_process(
20 COMMAND ${A2X_PROGRAM} --version
21 OUTPUT_VARIABLE _OUT
22 ERROR_VARIABLE _ERR
23 RESULT_VARIABLE _RES
24 OUTPUT_STRIP_TRAILING_WHITESPACE )
25
26 # If it worked, set the A2X_COMMAND
27 if( _RES MATCHES 0 )
28 set( A2X_COMMAND "${A2X_PROGRAM}" )
29 endif()
30endif()
31
32# If nothing could be found, test to see if we can just find the script file,
33# that we'll then run with the python interpreter
34if( NOT A2X_COMMAND )
35 find_file( A2X_SCRIPT a2x.py )
36
37 if( A2X_SCRIPT )
38 # Find the python interpreter quietly
39 if( NOT PYTHONINTERP_FOUND )
40 find_package( PYTHONINTERP QUIET )
41 endif()
42
43 if( NOT PYTHONINTERP_FOUND )
44 # Python's not available so can't find a2x...
45 set( A2X_COMMAND "" )
46 else()
47 # Build the python based command
48 set( A2X_COMMAND "${PYTHON_EXECUTABLE}" "${A2X_SCRIPT}" )
49
50 execute_process(
51 COMMAND ${A2X_COMMAND} --version
52 OUTPUT_VARIABLE _OUT
53 ERROR_VARIABLE _ERR
54 RESULT_VARIABLE _RES
55 OUTPUT_STRIP_TRAILING_WHITESPACE )
56
57 # If it still can't be run, then give up
58 if( NOT _RES MATCHES 0 )
59 set( A2X_COMMAND "" )
60 endif()
61 endif()
62 endif()
63endif()
64
65# If we've found a command that works, check the version
66if( A2X_COMMAND )
67 string(REGEX REPLACE ".*a2x[^0-9.]*\([0-9.]+\).*" "\\1" A2X_VERSION "${_OUT}")
68endif()
69
70# Generate the *_FOUND as necessary, etc.
71include( FindPackageHandleStandardArgs )
72find_package_handle_standard_args(
73 A2X
74 REQUIRED_VARS A2X_COMMAND
75 VERSION_VAR A2X_VERSION )