From 84c5228d4b630fcef0996e7a5d4adc96ffee095b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Sat, 7 Dec 2019 18:35:37 +0100 Subject: [PATCH 01/13] Make building examples and tests optional --- CMakeLists.txt | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca0246f..a27ed5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,19 +2,28 @@ cmake_minimum_required(VERSION 3.1) project(ArgParser) +option( CPPARGPARSE_BUILD_EXAMPLES "build examples" ON ) +option( CPPARGPARSE_BUILD_TESTS "build tests" ON ) + set(CMAKE_CXX_STANDARD 17) add_subdirectory(src) -add_subdirectory(example) +if( CPPARGPARSE_BUILD_EXAMPLES ) + add_subdirectory(example) +endif() + + +if( CPPARGPARSE_BUILD_TESTS ) + include(cmake/googletest/googletest.cmake) + fetch_googletest( + ${PROJECT_SOURCE_DIR}/cmake/googletest + ${PROJECT_BINARY_DIR}/googletest + ) -include(cmake/googletest/googletest.cmake) -fetch_googletest( - ${PROJECT_SOURCE_DIR}/cmake/googletest - ${PROJECT_BINARY_DIR}/googletest - ) + enable_testing() -enable_testing() -add_subdirectory(test) -add_subdirectory(test/staticlib) -add_subdirectory(test/headerlib) + add_subdirectory(test) + add_subdirectory(test/staticlib) + add_subdirectory(test/headerlib) +endif() From f1077868df339aba9b4f2ba99739c3ccfbe55b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Sun, 8 Dec 2019 17:09:10 +0100 Subject: [PATCH 02/13] Use static library in tests and examples --- example/CMakeLists.txt | 18 ++++++++++++++++++ include/cppargparse/argparse-h.h | 30 ++++++++++++++++++++++++++++++ include/cppargparse/argparse-s.h | 7 ------- include/cppargparse/argparse.h | 25 +------------------------ src/CMakeLists.txt | 5 +++++ test/action_t.cpp | 2 +- test/argparser_t.cpp | 2 +- test/argumentstream_t.cpp | 2 +- test/command_t.cpp | 2 +- test/commandhelp_t.cpp | 2 +- test/convert_t.cpp | 2 +- test/filesystemarguments_t.cpp | 2 +- test/group_t.cpp | 2 +- test/headerlib/basic_command_t.cpp | 2 +- test/help_t.cpp | 2 +- test/helpwriter_t.cpp | 2 +- test/negativenumber_t.cpp | 2 +- test/number_t.cpp | 2 +- test/optionfactory_t.cpp | 2 +- test/staticlib/basic_command_t.cpp | 2 +- test/testutil.h | 2 +- test/value_t.cpp | 2 +- 22 files changed, 71 insertions(+), 48 deletions(-) create mode 100644 include/cppargparse/argparse-h.h delete mode 100644 include/cppargparse/argparse-s.h diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 8d4de43..bb49825 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -9,24 +9,42 @@ set(PARSER_SOURCES add_executable( basic basic.cpp ) +target_link_libraries( basic + ${CMAKE_BINARY_DIR}/src/libargparse-s.a + ) add_executable( basic_action basic_action.cpp ) +target_link_libraries( basic_action + ${CMAKE_BINARY_DIR}/src/libargparse-s.a + ) add_executable( basic_struct basic_struct.cpp ) +target_link_libraries( basic_struct + ${CMAKE_BINARY_DIR}/src/libargparse-s.a + ) add_executable( basic_command basic_command.cpp ) +target_link_libraries( basic_command + ${CMAKE_BINARY_DIR}/src/libargparse-s.a + ) add_executable( example1 example1.cpp ) +target_link_libraries( example1 + ${CMAKE_BINARY_DIR}/src/libargparse-s.a + ) add_executable( example2 example2.cpp ) +target_link_libraries( example2 + ${CMAKE_BINARY_DIR}/src/libargparse-s.a + ) diff --git a/include/cppargparse/argparse-h.h b/include/cppargparse/argparse-h.h new file mode 100644 index 0000000..420d577 --- /dev/null +++ b/include/cppargparse/argparse-h.h @@ -0,0 +1,30 @@ +// Copyright (c) 2019 Marko Mahnič +// License: MPL2. See LICENSE in the root of the project. + +#pragma once + +#include "../../src/argparser.h" + +#define CPPARGPARSE_INLINE inline + +#include "../../src/argdescriber_impl.h" +#include "../../src/argparser_impl.h" +#include "../../src/argumentstream_impl.h" +#include "../../src/command_impl.h" +#include "../../src/commandconfig_impl.h" +#include "../../src/convert_impl.h" +#include "../../src/environment_impl.h" +#include "../../src/group_impl.h" +#include "../../src/groupconfig_impl.h" +#include "../../src/helpformatter_impl.h" +#include "../../src/option_impl.h" +#include "../../src/optionconfig_impl.h" +#include "../../src/optionsorter_impl.h" +#include "../../src/parser_impl.h" +#include "../../src/parserconfig_impl.h" +#include "../../src/parserdefinition_impl.h" +#include "../../src/parseresult_impl.h" +#include "../../src/value_impl.h" +#include "../../src/writer_impl.h" + +#undef CPPARGPARSE_INLINE diff --git a/include/cppargparse/argparse-s.h b/include/cppargparse/argparse-s.h deleted file mode 100644 index ac68973..0000000 --- a/include/cppargparse/argparse-s.h +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) 2019 Marko Mahnič -// License: MPL2. See LICENSE in the root of the project. - -#pragma once - -#include "../../src/argparser.h" -#include "../../src/exceptions.h" diff --git a/include/cppargparse/argparse.h b/include/cppargparse/argparse.h index 420d577..ac68973 100644 --- a/include/cppargparse/argparse.h +++ b/include/cppargparse/argparse.h @@ -4,27 +4,4 @@ #pragma once #include "../../src/argparser.h" - -#define CPPARGPARSE_INLINE inline - -#include "../../src/argdescriber_impl.h" -#include "../../src/argparser_impl.h" -#include "../../src/argumentstream_impl.h" -#include "../../src/command_impl.h" -#include "../../src/commandconfig_impl.h" -#include "../../src/convert_impl.h" -#include "../../src/environment_impl.h" -#include "../../src/group_impl.h" -#include "../../src/groupconfig_impl.h" -#include "../../src/helpformatter_impl.h" -#include "../../src/option_impl.h" -#include "../../src/optionconfig_impl.h" -#include "../../src/optionsorter_impl.h" -#include "../../src/parser_impl.h" -#include "../../src/parserconfig_impl.h" -#include "../../src/parserdefinition_impl.h" -#include "../../src/parseresult_impl.h" -#include "../../src/value_impl.h" -#include "../../src/writer_impl.h" - -#undef CPPARGPARSE_INLINE +#include "../../src/exceptions.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 18803e6..2596b3c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,3 +2,8 @@ add_library(argparse-s STATIC argparser.cpp ) + +install( TARGETS argparse-s + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + ) diff --git a/test/action_t.cpp b/test/action_t.cpp index a987fc3..c6cfe2e 100644 --- a/test/action_t.cpp +++ b/test/action_t.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2018, 2019 Marko Mahnič // License: MPL2. See LICENSE in the root of the project. -#include +#include #include diff --git a/test/argparser_t.cpp b/test/argparser_t.cpp index 847a95a..eb10bfc 100644 --- a/test/argparser_t.cpp +++ b/test/argparser_t.cpp @@ -4,7 +4,7 @@ #include "testutil.h" #include "vectors.h" -#include +#include #include #include diff --git a/test/argumentstream_t.cpp b/test/argumentstream_t.cpp index c6a2b12..9d1ed0d 100644 --- a/test/argumentstream_t.cpp +++ b/test/argumentstream_t.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2018, 2019 Marko Mahnič // License: MPL2. See LICENSE in the root of the project. -#include +#include #include diff --git a/test/command_t.cpp b/test/command_t.cpp index 4ee09d0..97734b0 100644 --- a/test/command_t.cpp +++ b/test/command_t.cpp @@ -3,7 +3,7 @@ #include "testutil.h" -#include +#include #include #include diff --git a/test/commandhelp_t.cpp b/test/commandhelp_t.cpp index 7394cf5..849c547 100644 --- a/test/commandhelp_t.cpp +++ b/test/commandhelp_t.cpp @@ -3,7 +3,7 @@ #include "testutil.h" -#include +#include #include #include diff --git a/test/convert_t.cpp b/test/convert_t.cpp index 54a483b..81c815f 100644 --- a/test/convert_t.cpp +++ b/test/convert_t.cpp @@ -3,7 +3,7 @@ #include "vectors.h" -#include +#include #include #include diff --git a/test/filesystemarguments_t.cpp b/test/filesystemarguments_t.cpp index a6c6529..6c9b7c2 100644 --- a/test/filesystemarguments_t.cpp +++ b/test/filesystemarguments_t.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2019 Marko Mahnič // License: MPL2. See LICENSE in the root of the project. -#include +#include #include #include diff --git a/test/group_t.cpp b/test/group_t.cpp index d79d122..a7b96b4 100644 --- a/test/group_t.cpp +++ b/test/group_t.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2019 Marko Mahnič // License: MPL2. See LICENSE in the root of the project. -#include +#include #include #include diff --git a/test/headerlib/basic_command_t.cpp b/test/headerlib/basic_command_t.cpp index 95c3988..e8cadde 100644 --- a/test/headerlib/basic_command_t.cpp +++ b/test/headerlib/basic_command_t.cpp @@ -1,7 +1,7 @@ #include "../testutil.h" #include -#include +#include #include #include #include diff --git a/test/help_t.cpp b/test/help_t.cpp index 044e449..cc8e703 100644 --- a/test/help_t.cpp +++ b/test/help_t.cpp @@ -3,7 +3,7 @@ #include "testutil.h" -#include +#include #include #include diff --git a/test/helpwriter_t.cpp b/test/helpwriter_t.cpp index ceeee66..480395c 100644 --- a/test/helpwriter_t.cpp +++ b/test/helpwriter_t.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2018, 2019 Marko Mahnič // License: MPL2. See LICENSE in the root of the project. -#include +#include #include diff --git a/test/negativenumber_t.cpp b/test/negativenumber_t.cpp index 17c3307..93d5322 100644 --- a/test/negativenumber_t.cpp +++ b/test/negativenumber_t.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2018, 2019 Marko Mahnič // License: MPL2. See LICENSE in the root of the project. -#include +#include #include #include diff --git a/test/number_t.cpp b/test/number_t.cpp index bbf45ec..7555f5e 100644 --- a/test/number_t.cpp +++ b/test/number_t.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2018, 2019 Marko Mahnič // License: MPL2. See LICENSE in the root of the project. -#include +#include #include #include diff --git a/test/optionfactory_t.cpp b/test/optionfactory_t.cpp index 753e7ca..f717225 100644 --- a/test/optionfactory_t.cpp +++ b/test/optionfactory_t.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2018, 2019 Marko Mahnič // License: MPL2. See LICENSE in the root of the project. -#include +#include #include diff --git a/test/staticlib/basic_command_t.cpp b/test/staticlib/basic_command_t.cpp index 4edbd8c..95c3988 100644 --- a/test/staticlib/basic_command_t.cpp +++ b/test/staticlib/basic_command_t.cpp @@ -1,7 +1,7 @@ #include "../testutil.h" #include -#include +#include #include #include #include diff --git a/test/testutil.h b/test/testutil.h index b9df35c..f3857f9 100644 --- a/test/testutil.h +++ b/test/testutil.h @@ -3,7 +3,7 @@ #pragma once -#include +#include #include #include diff --git a/test/value_t.cpp b/test/value_t.cpp index d9206be..6d7fa5e 100644 --- a/test/value_t.cpp +++ b/test/value_t.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2018, 2019 Marko Mahnič // License: MPL2. See LICENSE in the root of the project. -#include +#include #include From 185a295535ff15864fa666c3f2ad1b5b60205212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Sun, 8 Dec 2019 19:38:28 +0100 Subject: [PATCH 03/13] Add cmake and compile options, add installation script --- CMakeLists.txt | 32 +++++++++++++++++++++++++++++--- cmake/CppArgparseConfig.cmake.in | 4 ++++ src/CMakeLists.txt | 14 ++++++++------ 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 cmake/CppArgparseConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a27ed5f..9850184 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,11 @@ cmake_minimum_required(VERSION 3.1) -project(ArgParser) +project(CppArgparse VERSION 0.1.0) -option( CPPARGPARSE_BUILD_EXAMPLES "build examples" ON ) -option( CPPARGPARSE_BUILD_TESTS "build tests" ON ) +option( CPPARGPARSE_BUILD_EXAMPLES "build examples" ON ) +option( CPPARGPARSE_BUILD_TESTS "build tests" ON ) +option( CPPARGPARSE_INSTALL "enable library installation" ON ) +option( CPPARGPARSE_PEDANTIC "treat warnings as errors" OFF ) set(CMAKE_CXX_STANDARD 17) @@ -27,3 +29,27 @@ if( CPPARGPARSE_BUILD_TESTS ) add_subdirectory(test/staticlib) add_subdirectory(test/headerlib) endif() + +if (CPPARGPARSE_INSTALL) + include(CMakePackageConfigHelpers) + + set(INCLUDE_INSTALL_DIR include/ ) + set(LIB_INSTALL_DIR lib/ ) + + install( TARGETS ${CPPARGPARSE_STATIC_NAME} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + ) + install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + + configure_package_config_file(cmake/CppArgparseConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/CppArgparseConfig.cmake + INSTALL_DESTINATION ${LIB_INSTALL_DIR}/CppArgparse/cmake + PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR ) + + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/CppArgparseConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion + ) +endif() diff --git a/cmake/CppArgparseConfig.cmake.in b/cmake/CppArgparseConfig.cmake.in new file mode 100644 index 0000000..4d83794 --- /dev/null +++ b/cmake/CppArgparseConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +set_and_check(CPPARGPARSE_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(CPPARGPARSE_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2596b3c..fc2c3bf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,9 +1,11 @@ -add_library(argparse-s STATIC +set(CPPARGPARSE_STATIC_NAME argparse-s) +add_library(${CPPARGPARSE_STATIC_NAME} STATIC argparser.cpp ) - -install( TARGETS argparse-s - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - ) +if( CPPARGPARSE_PEDANTIC ) + target_compile_options(${CPPARGPARSE_STATIC_NAME} PRIVATE + $<$:-Werror -Wall> + $<$:/WX /permissive- /Za> + ) +endif() From 1bae568665d33db3e60b3c86609f3d6eb914472b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Sun, 8 Dec 2019 19:48:15 +0100 Subject: [PATCH 04/13] Remove googletest build files from the project --- CMakeLists.txt | 7 ----- cmake/googletest/README.md | 30 -------------------- cmake/googletest/googletest-download.cmake | 20 -------------- cmake/googletest/googletest.cmake | 32 ---------------------- 4 files changed, 89 deletions(-) delete mode 100644 cmake/googletest/README.md delete mode 100644 cmake/googletest/googletest-download.cmake delete mode 100644 cmake/googletest/googletest.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9850184..f541e5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,14 +17,7 @@ endif() if( CPPARGPARSE_BUILD_TESTS ) - include(cmake/googletest/googletest.cmake) - fetch_googletest( - ${PROJECT_SOURCE_DIR}/cmake/googletest - ${PROJECT_BINARY_DIR}/googletest - ) - enable_testing() - add_subdirectory(test) add_subdirectory(test/staticlib) add_subdirectory(test/headerlib) diff --git a/cmake/googletest/README.md b/cmake/googletest/README.md deleted file mode 100644 index db79da2..0000000 --- a/cmake/googletest/README.md +++ /dev/null @@ -1,30 +0,0 @@ -The cmake files in this directory are copied from https://github.com/bast/gtest-demo -Where they are published under the following license (2018-12-17): - -Copyright (c) 2015-2018, Radovan Bast -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of gtest-demo nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cmake/googletest/googletest-download.cmake b/cmake/googletest/googletest-download.cmake deleted file mode 100644 index 4926683..0000000 --- a/cmake/googletest/googletest-download.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# code copied from https://crascit.com/2015/07/25/cmake-gtest/ -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) - -project(googletest-download NONE) - -include(ExternalProject) - -ExternalProject_Add( - googletest - SOURCE_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-src" - BINARY_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-build" - GIT_REPOSITORY - https://github.com/google/googletest.git - GIT_TAG - release-1.8.0 - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" - ) diff --git a/cmake/googletest/googletest.cmake b/cmake/googletest/googletest.cmake deleted file mode 100644 index 5ca7090..0000000 --- a/cmake/googletest/googletest.cmake +++ /dev/null @@ -1,32 +0,0 @@ -# the following code to fetch googletest -# is inspired by and adapted after https://crascit.com/2015/07/25/cmake-gtest/ -# download and unpack googletest at configure time - -macro(fetch_googletest _download_module_path _download_root) - set(GOOGLETEST_DOWNLOAD_ROOT ${_download_root}) - configure_file( - ${_download_module_path}/googletest-download.cmake - ${_download_root}/CMakeLists.txt - @ONLY - ) - unset(GOOGLETEST_DOWNLOAD_ROOT) - - execute_process( - COMMAND - "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" . - WORKING_DIRECTORY - ${_download_root} - ) - execute_process( - COMMAND - "${CMAKE_COMMAND}" --build . - WORKING_DIRECTORY - ${_download_root} - ) - - # adds the targers: gtest, gtest_main, gmock, gmock_main - add_subdirectory( - ${_download_root}/googletest-src - ${_download_root}/googletest-build - ) -endmacro() From a11270d653e9c1ded533796b0c7c81439de97425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Sun, 8 Dec 2019 20:03:07 +0100 Subject: [PATCH 05/13] Before cmake 3.13 install must be in the same directory as target --- CMakeLists.txt | 10 +++------- src/CMakeLists.txt | 8 +++++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f541e5b..977455b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,10 @@ option( CPPARGPARSE_INSTALL "enable library installation" ON ) option( CPPARGPARSE_PEDANTIC "treat warnings as errors" OFF ) set(CMAKE_CXX_STANDARD 17) +set(INCLUDE_INSTALL_DIR include/ ) +set(LIB_INSTALL_DIR lib/ ) +set(CPPARGPARSE_STATIC_NAME argparse-s) add_subdirectory(src) if( CPPARGPARSE_BUILD_EXAMPLES ) @@ -26,13 +29,6 @@ endif() if (CPPARGPARSE_INSTALL) include(CMakePackageConfigHelpers) - set(INCLUDE_INSTALL_DIR include/ ) - set(LIB_INSTALL_DIR lib/ ) - - install( TARGETS ${CPPARGPARSE_STATIC_NAME} - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - ) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) configure_package_config_file(cmake/CppArgparseConfig.cmake.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fc2c3bf..26e3b98 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,4 @@ -set(CPPARGPARSE_STATIC_NAME argparse-s) add_library(${CPPARGPARSE_STATIC_NAME} STATIC argparser.cpp ) @@ -9,3 +8,10 @@ if( CPPARGPARSE_PEDANTIC ) $<$:/WX /permissive- /Za> ) endif() + +if (CPPARGPARSE_INSTALL) + install( TARGETS ${CPPARGPARSE_STATIC_NAME} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + ) +endif() From b2ab3ec9c81191297d7eaa29072e2ddbc7a2acde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Mon, 9 Dec 2019 20:43:57 +0100 Subject: [PATCH 06/13] Add a custom command for generating published headers --- CMakeLists.txt | 4 ++-- include/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 include/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 977455b..b71be84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,9 +27,9 @@ if( CPPARGPARSE_BUILD_TESTS ) endif() if (CPPARGPARSE_INSTALL) - include(CMakePackageConfigHelpers) + add_subdirectory(include) - install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + include(CMakePackageConfigHelpers) configure_package_config_file(cmake/CppArgparseConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CppArgparseConfig.cmake diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..6b912e0 --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,30 @@ + +add_custom_command( + OUTPUT fake_create_headers.cpp + DEPENDS cppargparse/argparse.h + COMMENT "Preparing library headers for publishing" + + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/cppargparse/inc + + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/cppargparse/inc + + COMMAND ${CMAKE_COMMAND} -E remove + ${CMAKE_CURRENT_BINARY_DIR}/cppargparse/inc/*.cpp + ${CMAKE_CURRENT_BINARY_DIR}/cppargparse/inc/*.txt + ${CMAKE_CURRENT_BINARY_DIR}/cppargparse/inc/*_impl.h + + COMMAND sed -e "s#\.\./\.\./src#inc#g" + ${CMAKE_CURRENT_SOURCE_DIR}/cppargparse/argparse.h + > ${CMAKE_CURRENT_BINARY_DIR}/cppargparse/argparse.h + + COMMAND ${CMAKE_COMMAND} -E echo 'int main(){ return 0\; }' > fake_create_headers.cpp + ) + +add_executable(fake_create_headers + ${CMAKE_CURRENT_BINARY_DIR}/fake_create_headers.cpp + ) + +install(DIRECTORY ${CMAKE_BINARY_DIR}/include/cppargparse + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + From 1861edb41f46acedd4cb5e4f625d26a4a9fec7b6 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Dec 2019 08:40:28 +0100 Subject: [PATCH 07/13] Ignore more build directories --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9129724..205cef5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/ +build-*/ *.swp *.*~ From a79920d542474d900924be2c06488deced662885 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Dec 2019 08:41:20 +0100 Subject: [PATCH 08/13] Add a utility for preparing headers for installtion --- CMakeLists.txt | 1 + util/CMakeLists.txt | 19 ++++++++++++++ util/instutil.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 util/CMakeLists.txt create mode 100644 util/instutil.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b71be84..3c22b98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ set(LIB_INSTALL_DIR lib/ ) set(CPPARGPARSE_STATIC_NAME argparse-s) add_subdirectory(src) +add_subdirectory(util) if( CPPARGPARSE_BUILD_EXAMPLES ) add_subdirectory(example) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt new file mode 100644 index 0000000..20b7ce8 --- /dev/null +++ b/util/CMakeLists.txt @@ -0,0 +1,19 @@ + +include_directories( ../include ) + +set(CMAKE_CXX_STANDARD 17) + +add_executable(instutil + instutil.cpp + ) + +if( CPPARGPARSE_PEDANTIC ) + target_compile_options(${CPPARGPARSE_STATIC_NAME} PRIVATE + $<$:-Werror -Wall> + $<$:/WX /permissive- /Za> + ) +endif() + +target_link_libraries( instutil + argparse-s + ) diff --git a/util/instutil.cpp b/util/instutil.cpp new file mode 100644 index 0000000..f5b5578 --- /dev/null +++ b/util/instutil.cpp @@ -0,0 +1,62 @@ +// Copyright (c) 2018, 2019 Marko Mahnič +// License: MPL2. See LICENSE in the root of the project. + +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace argparse; + +class MainHeaderCmd : public argparse::CommandOptions +{ + std::string inputFilename; + std::string outputFilename; + +public: + using CommandOptions::CommandOptions; + void execute( const argparse::ParseResult& res ) override + { + auto fin = ifstream( inputFilename ); + auto fout = ofstream( outputFilename ); + + auto rxSrcPath = std::regex( "\\.\\./\\.\\./src/" ); + auto instPath = "inc/"; + + std::string line; + while ( std::getline( fin, line ) ) + fout << regex_replace( line, rxSrcPath, instPath ) << "\n"; + } + +protected: + void add_arguments( argparse::argument_parser& parser ) override + { + parser.add_argument( inputFilename, "input" ) + .nargs( 1 ) + .help( "The path of the source file." ); + + parser.add_argument( outputFilename, "output" ) + .nargs( 1 ) + .help( "The path of the destination file." ); + } +}; + +int main( int argc, char** argv ) +{ + auto parser = argument_parser{}; + parser.config().program( argv[0] ).description( "cpp-argparse installation utility" ); + parser.add_command( "header" ).help( "Transform the main header." ); + + auto res = parser.parse_args( argc, argv, 1 ); + if ( !res ) + return 1; + + for ( auto& pcmd : res.commands ) + if ( pcmd ) + pcmd->execute( res ); + + return 0; +} From f85171d1d0165d2e95b4ae18f0d14c8af7b2a720 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Dec 2019 08:42:04 +0100 Subject: [PATCH 09/13] Improve build files Fixed compilation on WSL --- CMakeLists.txt | 10 +++++++++- example/CMakeLists.txt | 7 +++++++ include/CMakeLists.txt | 6 +++--- test/CMakeLists.txt | 13 ++++++++++--- test/headerlib/CMakeLists.txt | 6 +++++- test/staticlib/CMakeLists.txt | 8 +++++++- 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c22b98..66adbda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ option( CPPARGPARSE_PEDANTIC "treat warnings as errors" OFF ) set(CMAKE_CXX_STANDARD 17) set(INCLUDE_INSTALL_DIR include/ ) set(LIB_INSTALL_DIR lib/ ) +set(CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/CppArgparse) set(CPPARGPARSE_STATIC_NAME argparse-s) add_subdirectory(src) @@ -19,7 +20,6 @@ if( CPPARGPARSE_BUILD_EXAMPLES ) add_subdirectory(example) endif() - if( CPPARGPARSE_BUILD_TESTS ) enable_testing() add_subdirectory(test) @@ -28,6 +28,7 @@ if( CPPARGPARSE_BUILD_TESTS ) endif() if (CPPARGPARSE_INSTALL) + include(GNUInstallDirs) add_subdirectory(include) include(CMakePackageConfigHelpers) @@ -42,4 +43,11 @@ if (CPPARGPARSE_INSTALL) VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion ) + + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/CppArgparseConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/CppArgparseConfigVersion.cmake + DESTINATION ${CONFIG_INSTALL_DIR} + ) + endif() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index bb49825..1600310 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories( ../include ) +set ( CPPARGPARSE_EXAMPLE_LIB ${CPPARGPARSE_STATIC_NAME} ) # The library is currently header-only. set(PARSER_SOURCES @@ -12,6 +13,7 @@ add_executable( basic target_link_libraries( basic ${CMAKE_BINARY_DIR}/src/libargparse-s.a ) +add_dependencies( basic ${CPPARGPARSE_EXAMPLE_LIB} ) add_executable( basic_action basic_action.cpp @@ -19,6 +21,7 @@ add_executable( basic_action target_link_libraries( basic_action ${CMAKE_BINARY_DIR}/src/libargparse-s.a ) +add_dependencies( basic_action ${CPPARGPARSE_EXAMPLE_LIB} ) add_executable( basic_struct basic_struct.cpp @@ -26,6 +29,7 @@ add_executable( basic_struct target_link_libraries( basic_struct ${CMAKE_BINARY_DIR}/src/libargparse-s.a ) +add_dependencies( basic_struct ${CPPARGPARSE_EXAMPLE_LIB} ) add_executable( basic_command basic_command.cpp @@ -33,6 +37,7 @@ add_executable( basic_command target_link_libraries( basic_command ${CMAKE_BINARY_DIR}/src/libargparse-s.a ) +add_dependencies( basic_command ${CPPARGPARSE_EXAMPLE_LIB} ) add_executable( example1 example1.cpp @@ -40,6 +45,7 @@ add_executable( example1 target_link_libraries( example1 ${CMAKE_BINARY_DIR}/src/libargparse-s.a ) +add_dependencies( example1 ${CPPARGPARSE_EXAMPLE_LIB} ) add_executable( example2 example2.cpp @@ -47,4 +53,5 @@ add_executable( example2 target_link_libraries( example2 ${CMAKE_BINARY_DIR}/src/libargparse-s.a ) +add_dependencies( example2 ${CPPARGPARSE_EXAMPLE_LIB} ) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 6b912e0..10f28b9 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,10 +1,10 @@ add_custom_command( - OUTPUT fake_create_headers.cpp - DEPENDS cppargparse/argparse.h + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fake_create_headers.cpp + DEPENDS instutil cppargparse/argparse.h COMMENT "Preparing library headers for publishing" - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/cppargparse/inc + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/cppargparse COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/cppargparse/inc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5eeccf4..93073ac 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,9 @@ include_directories( ../include ) +set ( CPPARGPARSE_TEST_LIB ${CPPARGPARSE_STATIC_NAME} ) + +find_package( GTest REQUIRED ) +find_package( Threads REQUIRED ) # The library is currently header-only. set(PARSER_SOURCES @@ -16,7 +20,6 @@ add_executable( runUnitTests group_t.cpp command_t.cpp action_t.cpp - helpwriter_t.cpp help_t.cpp commandhelp_t.cpp filesystemarguments_t.cpp @@ -27,9 +30,11 @@ add_executable( runUnitTests ) target_link_libraries( runUnitTests - gtest_main + ${GTEST_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_BINARY_DIR}/src/libargparse-s.a ) +add_dependencies( runUnitTests ${CPPARGPARSE_TEST_LIB} ) add_executable( utilityTests runtest.cpp @@ -38,8 +43,10 @@ add_executable( utilityTests ) target_link_libraries( utilityTests - gtest_main + ${GTEST_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ) +add_dependencies( utilityTests ${CPPARGPARSE_TEST_LIB} ) add_test( NAME diff --git a/test/headerlib/CMakeLists.txt b/test/headerlib/CMakeLists.txt index 6e2c97b..77c8e4e 100644 --- a/test/headerlib/CMakeLists.txt +++ b/test/headerlib/CMakeLists.txt @@ -1,6 +1,9 @@ include_directories( ../../include ) +find_package( GTest REQUIRED ) +find_package( Threads REQUIRED ) + add_executable( headerLibraryTest runtest.cpp ../testutil.cpp @@ -8,7 +11,8 @@ add_executable( headerLibraryTest ) target_link_libraries( headerLibraryTest - gtest_main + ${GTEST_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ) add_test( diff --git a/test/staticlib/CMakeLists.txt b/test/staticlib/CMakeLists.txt index d0351a8..18baba7 100644 --- a/test/staticlib/CMakeLists.txt +++ b/test/staticlib/CMakeLists.txt @@ -1,5 +1,9 @@ include_directories( ../../include ) +set ( CPPARGPARSE_TEST_LIB ${CPPARGPARSE_STATIC_NAME} ) + +find_package( GTest REQUIRED ) +find_package( Threads REQUIRED ) add_executable( staticLibraryTest runtest.cpp @@ -8,9 +12,11 @@ add_executable( staticLibraryTest ) target_link_libraries( staticLibraryTest - gtest_main + ${GTEST_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_BINARY_DIR}/src/libargparse-s.a ) +add_dependencies( staticLibraryTest ${CPPARGPARSE_TEST_LIB} ) add_test( NAME From 910a1ef80a33d87d16ca33a22a3d28ac5a4fd16b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Fri, 13 Dec 2019 11:09:50 +0100 Subject: [PATCH 10/13] Build libgtest and publish the libraries --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 74c5c27..5ed8288 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,12 @@ sudo: false language: - cpp +install: + - mkdir /tmp/build-gtest && cd /tmp/build-gtest + - cmake /usr/src/libgtest + - make + - sudo cp libgtest* /usr/lib/ + script: - cmake -H. -Bbuild -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER - cd build From 5129015642dbf200ff43a81df0d0a7145200ad97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Fri, 13 Dec 2019 11:16:23 +0100 Subject: [PATCH 11/13] Reorder stages in travis --- .travis.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5ed8288..97a3f53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,18 +3,6 @@ sudo: false language: - cpp -install: - - mkdir /tmp/build-gtest && cd /tmp/build-gtest - - cmake /usr/src/libgtest - - make - - sudo cp libgtest* /usr/lib/ - -script: - - cmake -H. -Bbuild -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER - - cd build - - cmake --build . - - ctest - matrix: include: - os: linux @@ -49,6 +37,18 @@ matrix: - C_COMPILER=gcc-8 - CXX_COMPILER=g++-8 +install: + - mkdir /tmp/build-gtest && cd /tmp/build-gtest + - cmake /usr/src/libgtest + - make + - sudo cp libgtest* /usr/lib/ + +script: + - cmake -H. -Bbuild -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER + - cd build + - cmake --build . + - ctest + notifications: email: false From 92321e1c57ba7a860162a36cadde5d40bb679e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Fri, 13 Dec 2019 11:18:56 +0100 Subject: [PATCH 12/13] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 97a3f53..e153d07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ matrix: install: - mkdir /tmp/build-gtest && cd /tmp/build-gtest - - cmake /usr/src/libgtest + - cmake /usr/src/gtest - make - sudo cp libgtest* /usr/lib/ From 1a7e7036cc71a342da63ea5e806f6dbc81d4498d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Fri, 13 Dec 2019 11:21:41 +0100 Subject: [PATCH 13/13] Restore cwd after building gtest in travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e153d07..1ed4146 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,7 @@ install: - cmake /usr/src/gtest - make - sudo cp libgtest* /usr/lib/ + - cd - script: - cmake -H. -Bbuild -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER