mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-02 13:43:52 +00:00
Cmake cleanup (#21)
* Fixes for #8, vars hidden and findPython used * Adding compat with default python, better defaults
This commit is contained in:
parent
0da8fa9411
commit
657b599b52
@ -53,11 +53,18 @@ 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 REQUIRED)
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user