1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 12:13:52 +00:00

Adding tools to build with python 3.6 directly

This commit is contained in:
Henry Fredrick Schreiner 2017-02-06 11:51:06 -05:00
parent 9f0a6143d5
commit ee5678562f
8 changed files with 98 additions and 45 deletions

View File

@ -1,6 +1,7 @@
language: cpp
sudo: false
python:
- "3.6"
cache:
directories:
- ${TRAVIS_BUILD_DIR}/deps/cmake

View File

@ -1,26 +1,51 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(CLI11 CXX)
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# C++11 without GNU extensions
# Requires CMAKE 3.1+ for Mac
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 3.1)
add_compile_options(-std=c++11)
else()
cmake_policy(VERSION 3.1) # Needed for Mac
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(CUR_PROJ ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
else()
set(CUR_PROJ OFF)
endif()
# be moderately paranoid with flags
# Be moderately paranoid with flags
# But only globally, don't inherit
add_compile_options(-pedantic -Wall -Wextra)
include_directories(include)
set(headers "${PROJECT_SOURCE_DIR}/include/CLI.hpp")
add_library(CLI INTERFACE)
target_include_directories(CLI INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
enable_testing()
add_subdirectory(tests)
# Single file test
option(CLI_SINGLE_FILE "Generate a single header file (and test)" ${CUR_PROJ})
if(CLI_SINGLE_FILE)
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"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp"
IMPLICIT_DEPENDS CXX "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp"
)
add_custom_target(generate_cli_single_file
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp")
add_subdirectory(examples)
add_library(CLI_SINGLE INTERFACE)
target_link_libraries(CLI_SINGLE INTERFACE CLI)
add_dependencies(CLI_SINGLE generate_cli_single_file)
target_compile_definitions(CLI_SINGLE INTERFACE -DCLI_SINGLE_FILE)
target_include_directories(CLI_SINGLE INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/")
endif()
option(CLI_TESTING "Build the tests and add them" ${CUR_PROJ})
if(CLI_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
option(CLI_EXAMPLES "Build the examples" ${CUR_PROJ})
if(CLI_EXAMPLES)
add_subdirectory(examples)
endif()

View File

@ -32,7 +32,7 @@ include_directories(${gtest_SOURCE_DIR}/include)
# Target must already exist
macro(add_gtest TESTNAME)
target_link_libraries(${TESTNAME} gtest gtest_main)
target_link_libraries(${TESTNAME} PUBLIC gtest gtest_main)
add_test(${TESTNAME} ${TESTNAME})
endmacro()

View File

@ -1,2 +1,4 @@
add_executable(try try.cpp ${headers})
add_executable(try1 try1.cpp ${headers})
add_executable(try try.cpp)
target_link_libraries(try PUBLIC CLI)
add_executable(try1 try1.cpp)
target_link_libraries(try1 PUBLIC CLI)

View File

@ -2,35 +2,36 @@
# Requires Python 3.6
from plumbum import local, cli, FG
import re
import argparse
from pathlib import Path
includes_local = re.compile(r"""^#include "(.*)"$""", re.MULTILINE)
includes_system = re.compile(r"""^#include \<(.*)\>$""", re.MULTILINE)
DIR = local.path(__file__).dirname
BDIR = DIR / '../include'
DIR = Path(__file__).resolve().parent
BDIR = DIR.parent / 'include'
class MakeHeader(cli.Application):
def MakeHeader(out):
main_header = BDIR / 'CLI/CLI.hpp'
with main_header.open() as f:
header = f.read()
def main(self, out : cli.NonexistentPath = BDIR / 'CLI11.hpp'):
main_header = BDIR / 'CLI/CLI.hpp'
header = main_header.read()
include_files = includes_local.findall(header)
include_files = includes_local.findall(header)
headers = set()
output = ''
with open('output.hpp', 'w') as f:
for inc in include_files:
with (BDIR / inc).open() as f:
inner = f.read()
headers |= set(includes_system.findall(inner))
output += f'\n// From {inc}\n\n'
output += inner[inner.find('namespace'):]
headers = set()
output = ''
with open('output.hpp', 'w') as f:
for inc in include_files:
inner = (BDIR / inc).read()
headers |= set(includes_system.findall(inner))
output += f'\n// From {inc}\n\n'
output += inner[inner.find('namespace'):]
header_list = '\n'.join(f'#include <{h}>' for h in headers)
header_list = '\n'.join(f'#include <{h}>' for h in headers)
output = f'''\
output = f'''\
#pragma once
// Distributed under the LGPL version 3.0 license. See accompanying
@ -42,12 +43,14 @@ class MakeHeader(cli.Application):
{header_list}
{output}'''
with out.open('w') as f:
f.write(output)
with Path(out).open('w') as f:
f.write(output)
print(f"Created {out}")
print(f"Created {out}")
if __name__ == '__main__':
MakeHeader()
parser = argparse.ArgumentParser()
parser.add_argument("output", nargs='?', default=BDIR / 'CLI11.hpp')
args = parser.parse_args()
MakeHeader(args.output)

View File

@ -1,5 +1,9 @@
#ifdef CLI_SINGLE_FILE
#include "CLI11.hpp"
#else
#include "CLI/CLI.hpp"
#endif
#include "gtest/gtest.h"
#include <fstream>

View File

@ -1,7 +1,21 @@
include(AddGoogletest)
add_executable(CLITest CLITest.cpp ${headers})
add_executable(CLITest CLITest.cpp)
target_link_libraries(CLITest PUBLIC CLI)
add_gtest(CLITest)
add_executable(SmallTest SmallTest.cpp ${headers})
add_executable(SmallTest SmallTest.cpp)
target_link_libraries(SmallTest PUBLIC CLI)
add_gtest(SmallTest)
if(CLI_SINGLE_FILE)
add_executable(CLISingleTest CLITest.cpp)
target_link_libraries(CLISingleTest PUBLIC CLI_SINGLE)
add_gtest(CLISingleTest)
add_executable(SmallSingleTest SmallTest.cpp)
target_link_libraries(SmallSingleTest PUBLIC CLI_SINGLE)
add_gtest(SmallSingleTest)
endif()

View File

@ -1,4 +1,8 @@
#ifdef CLI_SINGLE_FILE
#include "CLI11.hpp"
#else
#include "CLI/CLI.hpp"
#endif
#include "gtest/gtest.h"
#include <cstdio>
#include <fstream>