Commit 657b599b5202796b8cbbd6ecb174d14a2e669c59
Committed by
GitHub
1 parent
0da8fa94
Cmake cleanup (#21)
* Fixes for #8, vars hidden and findPython used * Adding compat with default python, better defaults
Showing
3 changed files
with
19 additions
and
10 deletions
CMakeLists.txt
| ... | ... | @@ -53,11 +53,18 @@ add_library(CLI11 INTERFACE) |
| 53 | 53 | target_include_directories(CLI11 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") |
| 54 | 54 | |
| 55 | 55 | # Single file test |
| 56 | -option(CLI_SINGLE_FILE "Generate a single header file (and test)" ${CUR_PROJ}) | |
| 56 | +find_package(PythonInterp) | |
| 57 | +if(CUR_PROJ AND PYTHONINTERP_FOUND) | |
| 58 | + set(CLI_SINGLE_FILE_DEFAULT ON) | |
| 59 | +else() | |
| 60 | + set(CLI_SINGLE_FILE_DEFAULT OFF) | |
| 61 | +endif() | |
| 62 | +option(CLI_SINGLE_FILE "Generate a single header file (and test)" ${CLI_SINGLE_FILE_DEFAULT}) | |
| 57 | 63 | if(CLI_SINGLE_FILE) |
| 64 | + find_package(PythonInterp REQUIRED) | |
| 58 | 65 | file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include") |
| 59 | 66 | add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" |
| 60 | - COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py" "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" | |
| 67 | + COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py" "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" | |
| 61 | 68 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp" ${CLI_headers} |
| 62 | 69 | ) |
| 63 | 70 | add_custom_target(generate_cli_single_file ALL | ... | ... |
cmake/AddGoogletest.cmake
scripts/MakeSingleHeader.py
| ... | ... | @@ -4,24 +4,24 @@ |
| 4 | 4 | |
| 5 | 5 | from __future__ import print_function, unicode_literals |
| 6 | 6 | |
| 7 | +import os | |
| 7 | 8 | import re |
| 8 | 9 | import argparse |
| 9 | -from pathlib import Path | |
| 10 | 10 | from subprocess import check_output |
| 11 | 11 | |
| 12 | 12 | includes_local = re.compile(r"""^#include "(.*)"$""", re.MULTILINE) |
| 13 | 13 | includes_system = re.compile(r"""^#include \<(.*)\>$""", re.MULTILINE) |
| 14 | 14 | |
| 15 | -DIR = Path(__file__).resolve().parent | |
| 16 | -BDIR = DIR.parent / 'include' | |
| 15 | +DIR = os.path.dirname(os.path.abspath(__file__)) # Path(__file__).resolve().parent | |
| 16 | +BDIR = os.path.join(os.path.dirname(DIR), 'include') # DIR.parent / 'include' | |
| 17 | 17 | |
| 18 | 18 | print("Git directory:", DIR) |
| 19 | 19 | |
| 20 | 20 | TAG = check_output(['git', 'describe', '--tags', '--always'], cwd=str(DIR)).decode("utf-8") |
| 21 | 21 | |
| 22 | 22 | def MakeHeader(out): |
| 23 | - main_header = BDIR / 'CLI/CLI.hpp' | |
| 24 | - with main_header.open() as f: | |
| 23 | + main_header = os.path.join(BDIR, 'CLI', 'CLI.hpp') | |
| 24 | + with open(main_header) as f: | |
| 25 | 25 | header = f.read() |
| 26 | 26 | |
| 27 | 27 | include_files = includes_local.findall(header) |
| ... | ... | @@ -29,7 +29,7 @@ def MakeHeader(out): |
| 29 | 29 | headers = set() |
| 30 | 30 | output = '' |
| 31 | 31 | for inc in include_files: |
| 32 | - with (BDIR / inc).open() as f: | |
| 32 | + with open(os.path.join(BDIR, inc)) as f: | |
| 33 | 33 | inner = f.read() |
| 34 | 34 | headers |= set(includes_system.findall(inner)) |
| 35 | 35 | output += '\n// From {inc}\n\n'.format(inc=inc) |
| ... | ... | @@ -50,7 +50,7 @@ def MakeHeader(out): |
| 50 | 50 | {header_list} |
| 51 | 51 | {output}'''.format(header_list=header_list, output=output, tag=TAG) |
| 52 | 52 | |
| 53 | - with Path(out).open('w') as f: | |
| 53 | + with open(out, 'w') as f: | |
| 54 | 54 | f.write(output) |
| 55 | 55 | |
| 56 | 56 | print("Created {out}".format(out=out)) |
| ... | ... | @@ -58,6 +58,6 @@ def MakeHeader(out): |
| 58 | 58 | |
| 59 | 59 | if __name__ == '__main__': |
| 60 | 60 | parser = argparse.ArgumentParser() |
| 61 | - parser.add_argument("output", nargs='?', default=BDIR / 'CLI11.hpp') | |
| 61 | + parser.add_argument("output", nargs='?', default=os.path.join(BDIR, 'CLI11.hpp')) | |
| 62 | 62 | args = parser.parse_args() |
| 63 | 63 | MakeHeader(args.output) | ... | ... |