From 241365336e772d646011bb0a1c7b43f9355f6f71 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Mon, 5 Jun 2017 10:36:48 -0400 Subject: [PATCH 1/2] Fixes for #8, vars hidden and findPython used --- CMakeLists.txt | 3 ++- cmake/AddGoogletest.cmake | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38955915a..f5a7ed14e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,9 +55,10 @@ target_include_directories(CLI11 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include" # Single file test option(CLI_SINGLE_FILE "Generate a single header file (and test)" ${CUR_PROJ}) if(CLI_SINGLE_FILE) + find_package(PythonInterp) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include") add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" - COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py" "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" + COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py" "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp" ${CLI_headers} ) add_custom_target(generate_cli_single_file ALL diff --git a/cmake/AddGoogletest.cmake b/cmake/AddGoogletest.cmake index e18ce48a4..5e026cca8 100644 --- a/cmake/AddGoogletest.cmake +++ b/cmake/AddGoogletest.cmake @@ -46,6 +46,8 @@ gtest_build_tests gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols +BUILD_GMOCK +BUILD_GTEST ) set_target_properties(gtest gtest_main gmock gmock_main From b4e44aaecc98535ebb6e9bea5b4c36f083d0c99f Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Mon, 5 Jun 2017 10:47:27 -0400 Subject: [PATCH 2/2] Adding compat with default python, better defaults --- CMakeLists.txt | 10 ++++++++-- scripts/MakeSingleHeader.py | 16 ++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5a7ed14e..f8b8e0b2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,9 +53,15 @@ add_library(CLI11 INTERFACE) target_include_directories(CLI11 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") # Single file test -option(CLI_SINGLE_FILE "Generate a single header file (and test)" ${CUR_PROJ}) +find_package(PythonInterp) +if(CUR_PROJ AND PYTHONINTERP_FOUND) + set(CLI_SINGLE_FILE_DEFAULT ON) +else() + set(CLI_SINGLE_FILE_DEFAULT OFF) +endif() +option(CLI_SINGLE_FILE "Generate a single header file (and test)" ${CLI_SINGLE_FILE_DEFAULT}) if(CLI_SINGLE_FILE) - find_package(PythonInterp) + find_package(PythonInterp REQUIRED) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include") add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py" "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" diff --git a/scripts/MakeSingleHeader.py b/scripts/MakeSingleHeader.py index 157609293..23c2de3f4 100755 --- a/scripts/MakeSingleHeader.py +++ b/scripts/MakeSingleHeader.py @@ -4,24 +4,24 @@ from __future__ import print_function, unicode_literals +import os import re import argparse -from pathlib import Path from subprocess import check_output includes_local = re.compile(r"""^#include "(.*)"$""", re.MULTILINE) includes_system = re.compile(r"""^#include \<(.*)\>$""", re.MULTILINE) -DIR = Path(__file__).resolve().parent -BDIR = DIR.parent / 'include' +DIR = os.path.dirname(os.path.abspath(__file__)) # Path(__file__).resolve().parent +BDIR = os.path.join(os.path.dirname(DIR), 'include') # DIR.parent / 'include' print("Git directory:", DIR) TAG = check_output(['git', 'describe', '--tags', '--always'], cwd=str(DIR)).decode("utf-8") def MakeHeader(out): - main_header = BDIR / 'CLI/CLI.hpp' - with main_header.open() as f: + main_header = os.path.join(BDIR, 'CLI', 'CLI.hpp') + with open(main_header) as f: header = f.read() include_files = includes_local.findall(header) @@ -29,7 +29,7 @@ def MakeHeader(out): headers = set() output = '' for inc in include_files: - with (BDIR / inc).open() as f: + with open(os.path.join(BDIR, inc)) as f: inner = f.read() headers |= set(includes_system.findall(inner)) output += '\n// From {inc}\n\n'.format(inc=inc) @@ -50,7 +50,7 @@ def MakeHeader(out): {header_list} {output}'''.format(header_list=header_list, output=output, tag=TAG) - with Path(out).open('w') as f: + with open(out, 'w') as f: f.write(output) print("Created {out}".format(out=out)) @@ -58,6 +58,6 @@ def MakeHeader(out): if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument("output", nargs='?', default=BDIR / 'CLI11.hpp') + parser.add_argument("output", nargs='?', default=os.path.join(BDIR, 'CLI11.hpp')) args = parser.parse_args() MakeHeader(args.output)