mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-03 22:13:51 +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")
|
target_include_directories(CLI11 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
|
|
||||||
# Single file test
|
# 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)
|
if(CLI_SINGLE_FILE)
|
||||||
|
find_package(PythonInterp REQUIRED)
|
||||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include")
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include")
|
||||||
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp"
|
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}
|
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp" ${CLI_headers}
|
||||||
)
|
)
|
||||||
add_custom_target(generate_cli_single_file ALL
|
add_custom_target(generate_cli_single_file ALL
|
||||||
|
@ -46,6 +46,8 @@ gtest_build_tests
|
|||||||
gtest_disable_pthreads
|
gtest_disable_pthreads
|
||||||
gtest_force_shared_crt
|
gtest_force_shared_crt
|
||||||
gtest_hide_internal_symbols
|
gtest_hide_internal_symbols
|
||||||
|
BUILD_GMOCK
|
||||||
|
BUILD_GTEST
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(gtest gtest_main gmock gmock_main
|
set_target_properties(gtest gtest_main gmock gmock_main
|
||||||
|
@ -4,24 +4,24 @@
|
|||||||
|
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
|
||||||
from subprocess import check_output
|
from subprocess import check_output
|
||||||
|
|
||||||
includes_local = re.compile(r"""^#include "(.*)"$""", re.MULTILINE)
|
includes_local = re.compile(r"""^#include "(.*)"$""", re.MULTILINE)
|
||||||
includes_system = re.compile(r"""^#include \<(.*)\>$""", re.MULTILINE)
|
includes_system = re.compile(r"""^#include \<(.*)\>$""", re.MULTILINE)
|
||||||
|
|
||||||
DIR = Path(__file__).resolve().parent
|
DIR = os.path.dirname(os.path.abspath(__file__)) # Path(__file__).resolve().parent
|
||||||
BDIR = DIR.parent / 'include'
|
BDIR = os.path.join(os.path.dirname(DIR), 'include') # DIR.parent / 'include'
|
||||||
|
|
||||||
print("Git directory:", DIR)
|
print("Git directory:", DIR)
|
||||||
|
|
||||||
TAG = check_output(['git', 'describe', '--tags', '--always'], cwd=str(DIR)).decode("utf-8")
|
TAG = check_output(['git', 'describe', '--tags', '--always'], cwd=str(DIR)).decode("utf-8")
|
||||||
|
|
||||||
def MakeHeader(out):
|
def MakeHeader(out):
|
||||||
main_header = BDIR / 'CLI/CLI.hpp'
|
main_header = os.path.join(BDIR, 'CLI', 'CLI.hpp')
|
||||||
with main_header.open() as f:
|
with open(main_header) as f:
|
||||||
header = f.read()
|
header = f.read()
|
||||||
|
|
||||||
include_files = includes_local.findall(header)
|
include_files = includes_local.findall(header)
|
||||||
@ -29,7 +29,7 @@ def MakeHeader(out):
|
|||||||
headers = set()
|
headers = set()
|
||||||
output = ''
|
output = ''
|
||||||
for inc in include_files:
|
for inc in include_files:
|
||||||
with (BDIR / inc).open() as f:
|
with open(os.path.join(BDIR, inc)) as f:
|
||||||
inner = f.read()
|
inner = f.read()
|
||||||
headers |= set(includes_system.findall(inner))
|
headers |= set(includes_system.findall(inner))
|
||||||
output += '\n// From {inc}\n\n'.format(inc=inc)
|
output += '\n// From {inc}\n\n'.format(inc=inc)
|
||||||
@ -50,7 +50,7 @@ def MakeHeader(out):
|
|||||||
{header_list}
|
{header_list}
|
||||||
{output}'''.format(header_list=header_list, output=output, tag=TAG)
|
{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)
|
f.write(output)
|
||||||
|
|
||||||
print("Created {out}".format(out=out))
|
print("Created {out}".format(out=out))
|
||||||
@ -58,6 +58,6 @@ def MakeHeader(out):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
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()
|
args = parser.parse_args()
|
||||||
MakeHeader(args.output)
|
MakeHeader(args.output)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user