Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake cleanup #21

Merged
merged 2 commits into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmake/AddGoogletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions scripts/MakeSingleHeader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@

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)

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)
Expand All @@ -50,14 +50,14 @@ 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))


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)