mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-02 13:43:52 +00:00
[precompiled] Initial proof-of-concept with App.cpp
- Add C11_COMPILE cmake option that creates a static lib instead of header-only - Add C11_INLINE macro that depends on C11_COMPILE - Split App.hpp into App.hpp and impl/App_inl.hpp - Add App.cpp that compiles App_inl.hpp into an object file - CMake modifications to handle impl headers differently for sinlge-header, headers-only, and compiled versions
This commit is contained in:
parent
c57000e582
commit
b56ae237e5
@ -62,6 +62,8 @@ namespace {namespace} {{
|
|||||||
|
|
||||||
{app_hpp}
|
{app_hpp}
|
||||||
|
|
||||||
|
{app_inl_hpp}
|
||||||
|
|
||||||
{config_hpp}
|
{config_hpp}
|
||||||
|
|
||||||
{formatter_hpp}
|
{formatter_hpp}
|
||||||
|
@ -77,6 +77,7 @@ endif()
|
|||||||
|
|
||||||
option(CLI11_WARNINGS_AS_ERRORS "Turn all warnings into errors (for CI)")
|
option(CLI11_WARNINGS_AS_ERRORS "Turn all warnings into errors (for CI)")
|
||||||
option(CLI11_SINGLE_FILE "Generate a single header file")
|
option(CLI11_SINGLE_FILE "Generate a single header file")
|
||||||
|
option(CLI11_PRECOMPILED "Generate a precompiled static library instead of a header-only")
|
||||||
cmake_dependent_option(CLI11_SANITIZERS "Download the sanitizers CMake config" OFF
|
cmake_dependent_option(CLI11_SANITIZERS "Download the sanitizers CMake config" OFF
|
||||||
"NOT CMAKE_VERSION VERSION_LESS 3.11" OFF)
|
"NOT CMAKE_VERSION VERSION_LESS 3.11" OFF)
|
||||||
|
|
||||||
@ -105,6 +106,11 @@ cmake_dependent_option(
|
|||||||
CLI11_CUDA_TESTS "Build the tests with NVCC to check for warnings there - requires CMake 3.9+"
|
CLI11_CUDA_TESTS "Build the tests with NVCC to check for warnings there - requires CMake 3.9+"
|
||||||
OFF "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF)
|
OFF "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF)
|
||||||
|
|
||||||
|
if(CLI11_PRECOMPILED AND CLI11_SINGLE_FILE)
|
||||||
|
# Sanity check
|
||||||
|
message(FATAL_ERROR "CLI11_PRECOMPILE and CLI11_SINGLE_FILE are mutually exclusive")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT DEFINED CMAKE_CXX_STANDARD)
|
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT DEFINED CMAKE_CXX_STANDARD)
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
endif()
|
endif()
|
||||||
@ -160,12 +166,34 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.13)
|
|||||||
target_link_options(CLI11_warnings INTERFACE $<$<BOOL:${CLI11_FORCE_LIBCXX}>:-stdlib=libc++>)
|
target_link_options(CLI11_warnings INTERFACE $<$<BOOL:${CLI11_FORCE_LIBCXX}>:-stdlib=libc++>)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# To see in IDE, headers must be listed for target
|
||||||
|
set(MAYBE_CONFIGURE_DEPENDS "")
|
||||||
|
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT CMAKE_VERSION VERSION_LESS 3.12)
|
||||||
|
list(INSERT MAYBE_CONFIGURE_DEPENDS 0 CONFIGURE_DEPENDS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
file(GLOB CLI11_headers ${MAYBE_CONFIGURE_DEPENDS} "${PROJECT_SOURCE_DIR}/include/CLI/*.hpp")
|
||||||
|
file(GLOB CLI11_impl_headers ${MAYBE_CONFIGURE_DEPENDS}
|
||||||
|
"${PROJECT_SOURCE_DIR}/include/CLI/impl/*.hpp")
|
||||||
|
|
||||||
|
if(CLI11_PRECOMPILED)
|
||||||
|
# Create static lib
|
||||||
|
file(GLOB CLI11_precompile_sources "${PROJECT_SOURCE_DIR}/src/*.cpp")
|
||||||
|
add_library(CLI11 STATIC ${CLI11_headers} ${CLI11_impl_headers} ${CLI11_precompile_sources})
|
||||||
|
target_compile_definitions(CLI11 PUBLIC -DCLI11_COMPILE)
|
||||||
|
|
||||||
|
set(PUBLIC_OR_INTERFACE PUBLIC)
|
||||||
|
else()
|
||||||
|
add_library(CLI11 INTERFACE)
|
||||||
|
set(PUBLIC_OR_INTERFACE INTERFACE)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Allow IDE's to group targets into folders
|
# Allow IDE's to group targets into folders
|
||||||
add_library(CLI11 INTERFACE)
|
|
||||||
add_library(CLI11::CLI11 ALIAS CLI11) # for add_subdirectory calls
|
add_library(CLI11::CLI11 ALIAS CLI11) # for add_subdirectory calls
|
||||||
|
|
||||||
# Duplicated because CMake adds the current source dir if you don't.
|
# Duplicated because CMake adds the current source dir if you don't.
|
||||||
target_include_directories(CLI11 INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
target_include_directories(
|
||||||
|
CLI11 ${PUBLIC_OR_INTERFACE} $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
$<INSTALL_INTERFACE:include>)
|
$<INSTALL_INTERFACE:include>)
|
||||||
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.8)
|
if(CMAKE_VERSION VERSION_LESS 3.8)
|
||||||
@ -184,14 +212,6 @@ else()
|
|||||||
target_compile_features(CLI11 INTERFACE cxx_std_11)
|
target_compile_features(CLI11 INTERFACE cxx_std_11)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# To see in IDE, headers must be listed for target
|
|
||||||
set(header-patterns "${PROJECT_SOURCE_DIR}/include/CLI/*")
|
|
||||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT CMAKE_VERSION VERSION_LESS 3.12)
|
|
||||||
list(INSERT header-patterns 0 CONFIGURE_DEPENDS)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
file(GLOB CLI11_headers ${header-patterns})
|
|
||||||
|
|
||||||
# Allow tests to be run on CUDA
|
# Allow tests to be run on CUDA
|
||||||
if(CLI11_CUDA_TESTS)
|
if(CLI11_CUDA_TESTS)
|
||||||
enable_language(CUDA)
|
enable_language(CUDA)
|
||||||
@ -202,7 +222,10 @@ endif()
|
|||||||
|
|
||||||
# This folder should be installed
|
# This folder should be installed
|
||||||
if(CLI11_INSTALL)
|
if(CLI11_INSTALL)
|
||||||
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
install(FILES ${CLI11_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/CLI")
|
||||||
|
if(NOT CLI11_COMPILE)
|
||||||
|
install(FILES ${CLI11_impl_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/CLI/impl")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Make an export target
|
# Make an export target
|
||||||
install(TARGETS CLI11 EXPORT CLI11Targets)
|
install(TARGETS CLI11 EXPORT CLI11Targets)
|
||||||
@ -257,9 +280,10 @@ if(CLI11_SINGLE_FILE)
|
|||||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp"
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp"
|
||||||
COMMAND
|
COMMAND
|
||||||
Python::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py"
|
Python::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py"
|
||||||
${CLI11_headers} --main "${CMAKE_CURRENT_SOURCE_DIR}/CLI11.hpp.in" --output
|
${CLI11_headers} ${CLI11_impl_headers} --main "${CMAKE_CURRENT_SOURCE_DIR}/CLI11.hpp.in"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" --version "${CLI11_VERSION}"
|
--output "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp" --version "${CLI11_VERSION}"
|
||||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp" ${CLI11_headers})
|
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp" ${CLI11_headers}
|
||||||
|
${CLI11_impl_headers})
|
||||||
add_custom_target(CLI11-generate-single-file ALL
|
add_custom_target(CLI11-generate-single-file ALL
|
||||||
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp")
|
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp")
|
||||||
set_property(TARGET CLI11-generate-single-file PROPERTY FOLDER "Scripts")
|
set_property(TARGET CLI11-generate-single-file PROPERTY FOLDER "Scripts")
|
||||||
|
2052
include/CLI/App.hpp
2052
include/CLI/App.hpp
File diff suppressed because it is too large
Load Diff
@ -65,4 +65,11 @@
|
|||||||
#define CLI11_USE_STATIC_RTTI 1
|
#define CLI11_USE_STATIC_RTTI 1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** Inline macro **/
|
||||||
|
#ifdef CLI11_COMPILE
|
||||||
|
#define CLI11_INLINE
|
||||||
|
#else
|
||||||
|
#define CLI11_INLINE inline
|
||||||
|
#endif
|
||||||
// [CLI11:macros_hpp:end]
|
// [CLI11:macros_hpp:end]
|
||||||
|
2072
include/CLI/impl/App_inl.hpp
Normal file
2072
include/CLI/impl/App_inl.hpp
Normal file
File diff suppressed because it is too large
Load Diff
10
src/App.cpp
Normal file
10
src/App.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (c) 2017-2022, University of Cincinnati, developed by Henry Schreiner
|
||||||
|
// under NSF AWARD 1414736 and by the respective contributors.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
#include <CLI/impl/App_inl.hpp>
|
||||||
|
|
||||||
|
#include <CLI/Config.hpp>
|
||||||
|
#include <CLI/Formatter.hpp>
|
Loading…
x
Reference in New Issue
Block a user