mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 20:23:55 +00:00
Adding tools to build with python 3.6 directly
This commit is contained in:
parent
9f0a6143d5
commit
ee5678562f
@ -1,6 +1,7 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
sudo: false
|
sudo: false
|
||||||
|
python:
|
||||||
|
- "3.6"
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- ${TRAVIS_BUILD_DIR}/deps/cmake
|
- ${TRAVIS_BUILD_DIR}/deps/cmake
|
||||||
|
@ -1,26 +1,51 @@
|
|||||||
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
||||||
|
|
||||||
project(CLI11 CXX)
|
project(CLI11 CXX)
|
||||||
|
|
||||||
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||||
|
|
||||||
# C++11 without GNU extensions
|
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||||
# Requires CMAKE 3.1+ for Mac
|
set(CUR_PROJ ON)
|
||||||
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
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
else()
|
||||||
|
set(CUR_PROJ OFF)
|
||||||
endif()
|
endif()
|
||||||
# be moderately paranoid with flags
|
|
||||||
|
# Be moderately paranoid with flags
|
||||||
|
# But only globally, don't inherit
|
||||||
add_compile_options(-pedantic -Wall -Wextra)
|
add_compile_options(-pedantic -Wall -Wextra)
|
||||||
|
|
||||||
include_directories(include)
|
add_library(CLI INTERFACE)
|
||||||
set(headers "${PROJECT_SOURCE_DIR}/include/CLI.hpp")
|
target_include_directories(CLI INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
|
|
||||||
enable_testing()
|
# Single file test
|
||||||
add_subdirectory(tests)
|
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()
|
||||||
|
@ -32,7 +32,7 @@ include_directories(${gtest_SOURCE_DIR}/include)
|
|||||||
|
|
||||||
# Target must already exist
|
# Target must already exist
|
||||||
macro(add_gtest TESTNAME)
|
macro(add_gtest TESTNAME)
|
||||||
target_link_libraries(${TESTNAME} gtest gtest_main)
|
target_link_libraries(${TESTNAME} PUBLIC gtest gtest_main)
|
||||||
add_test(${TESTNAME} ${TESTNAME})
|
add_test(${TESTNAME} ${TESTNAME})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
add_executable(try try.cpp ${headers})
|
add_executable(try try.cpp)
|
||||||
add_executable(try1 try1.cpp ${headers})
|
target_link_libraries(try PUBLIC CLI)
|
||||||
|
add_executable(try1 try1.cpp)
|
||||||
|
target_link_libraries(try1 PUBLIC CLI)
|
||||||
|
@ -2,35 +2,36 @@
|
|||||||
|
|
||||||
# Requires Python 3.6
|
# Requires Python 3.6
|
||||||
|
|
||||||
from plumbum import local, cli, FG
|
|
||||||
import re
|
import re
|
||||||
|
import argparse
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
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 = local.path(__file__).dirname
|
DIR = Path(__file__).resolve().parent
|
||||||
BDIR = DIR / '../include'
|
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'):
|
include_files = includes_local.findall(header)
|
||||||
main_header = BDIR / 'CLI/CLI.hpp'
|
|
||||||
header = main_header.read()
|
|
||||||
|
|
||||||
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()
|
header_list = '\n'.join(f'#include <{h}>' for h in headers)
|
||||||
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)
|
output = f'''\
|
||||||
|
|
||||||
output = f'''\
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Distributed under the LGPL version 3.0 license. See accompanying
|
// Distributed under the LGPL version 3.0 license. See accompanying
|
||||||
@ -42,12 +43,14 @@ class MakeHeader(cli.Application):
|
|||||||
{header_list}
|
{header_list}
|
||||||
{output}'''
|
{output}'''
|
||||||
|
|
||||||
with out.open('w') as f:
|
with Path(out).open('w') as f:
|
||||||
f.write(output)
|
f.write(output)
|
||||||
|
|
||||||
|
print(f"Created {out}")
|
||||||
|
|
||||||
print(f"Created {out}")
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
MakeHeader()
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("output", nargs='?', default=BDIR / 'CLI11.hpp')
|
||||||
|
args = parser.parse_args()
|
||||||
|
MakeHeader(args.output)
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
|
#ifdef CLI_SINGLE_FILE
|
||||||
|
#include "CLI11.hpp"
|
||||||
|
#else
|
||||||
#include "CLI/CLI.hpp"
|
#include "CLI/CLI.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
@ -1,7 +1,21 @@
|
|||||||
include(AddGoogletest)
|
include(AddGoogletest)
|
||||||
|
|
||||||
add_executable(CLITest CLITest.cpp ${headers})
|
add_executable(CLITest CLITest.cpp)
|
||||||
|
target_link_libraries(CLITest PUBLIC CLI)
|
||||||
add_gtest(CLITest)
|
add_gtest(CLITest)
|
||||||
|
|
||||||
add_executable(SmallTest SmallTest.cpp ${headers})
|
add_executable(SmallTest SmallTest.cpp)
|
||||||
|
target_link_libraries(SmallTest PUBLIC CLI)
|
||||||
add_gtest(SmallTest)
|
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()
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
|
#ifdef CLI_SINGLE_FILE
|
||||||
|
#include "CLI11.hpp"
|
||||||
|
#else
|
||||||
#include "CLI/CLI.hpp"
|
#include "CLI/CLI.hpp"
|
||||||
|
#endif
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user