From de72ac55c9364cef14564ec468f5adb882d3ec99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Wed, 1 Jan 2020 15:45:39 +0100 Subject: [PATCH 1/3] Replace instutil wiht a cmake script --- CMakeLists.txt | 7 ++- include/CMakeLists.txt | 28 ++++++++---- include/prepare-headers.cmake | 18 ++++++++ util/CMakeLists.txt | 21 --------- util/faketarget.cpp | 4 ++ util/instutil.cpp | 86 ----------------------------------- 6 files changed, 43 insertions(+), 121 deletions(-) create mode 100644 include/prepare-headers.cmake delete mode 100644 util/CMakeLists.txt create mode 100644 util/faketarget.cpp delete mode 100644 util/instutil.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 58199ec..e6656f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required( VERSION 3.1 ) -project( Argumentum VERSION 0.2.0 ) +project( Argumentum VERSION 0.2.2 ) option( BUILD_STATIC_LIBS "Build static libraries" ON ) option( ARGUMENTUM_BUILD_EXAMPLES "Build examples" OFF ) @@ -17,13 +17,12 @@ set( CMAKE_DEBUG_POSTFIX d ) include( GNUInstallDirs ) # The name of the published static library target. -set( ARGUMENTUM_STATIC_NAME argumentum-s ) +set( ARGUMENTUM_STATIC_NAME argumentum ) -# The name of the internal static library target used for instutil, tests, examples. +# The name of the internal static library target used for tests, examples. set( ARGUMENTUM_INTERNAL_NAME argumentum-si ) add_subdirectory( src ) -add_subdirectory( util ) add_subdirectory( include ) include( cmake/InstallConfig.cmake ) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 28b5fc5..d0cb63d 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,18 +1,26 @@ +file( GLOB copied_headers "${CMAKE_SOURCE_DIR}/src/*.h" ) + add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fake_create_headers.cpp - DEPENDS instutil argumentum/argparse.h - COMMENT "Preparing library headers for publishing" + OUTPUT + ${CMAKE_CURRENT_BINARY_DIR}/fake_create_headers.cpp + ${CMAKE_CURRENT_BINARY_DIR}/argumentum/argparse.h + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/argumentum/argparse.h + ${copied_headers} - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/argumentum + COMMENT "Preparing library headers for publishing" - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/argumentum/inc + COMMAND ${CMAKE_COMMAND} + -E copy + "${CMAKE_SOURCE_DIR}/util/faketarget.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/fake_create_headers.cpp" - COMMAND instutil fake-target fake_create_headers.cpp - COMMAND instutil header - ${CMAKE_CURRENT_SOURCE_DIR}/argumentum/argparse.h - ${CMAKE_CURRENT_BINARY_DIR}/argumentum/argparse.h + COMMAND ${CMAKE_COMMAND} + -D TOP_SOURCE_DIR="${CMAKE_SOURCE_DIR}" + -D P_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" + -D P_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}" + -P "${CMAKE_CURRENT_SOURCE_DIR}/prepare-headers.cmake" ) add_executable( fake_create_headers diff --git a/include/prepare-headers.cmake b/include/prepare-headers.cmake new file mode 100644 index 0000000..0aa90b1 --- /dev/null +++ b/include/prepare-headers.cmake @@ -0,0 +1,18 @@ +# Run with cmake -P +# Parameters (-D): TOP_SOURCE_DIR, P_BINARY_DIR, P_SOURCE_DIR + +file( MAKE_DIRECTORY ${P_BINARY_DIR}/argumentum ) + +file( COPY ${TOP_SOURCE_DIR}/src/ + DESTINATION ${P_BINARY_DIR}/argumentum/inc/ + FILES_MATCHING PATTERN "*.h" + ) + +file( READ ${P_SOURCE_DIR}/argumentum/argparse.h + main_header ) + +string( REPLACE "../../src/" "inc/" + main_header "${main_header}" ) + +file( WRITE ${P_BINARY_DIR}/argumentum/argparse.h + "${main_header}" ) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt deleted file mode 100644 index 7ca8674..0000000 --- a/util/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ - -include_directories( ../include ) -set ( argumentum_util_lib ${ARGUMENTUM_INTERNAL_NAME} ) - -set(CMAKE_CXX_STANDARD 17) - -add_executable( instutil - instutil.cpp - ) - -if( ARGUMENTUM_PEDANTIC ) - target_compile_options( instutil PRIVATE - $<$:-Werror -Wall> - $<$:/WX /permissive- /Za> - ) -endif() - -target_link_libraries( instutil - ${argumentum_util_lib} - ) -add_dependencies( instutil ${argumentum_util_lib} ) diff --git a/util/faketarget.cpp b/util/faketarget.cpp new file mode 100644 index 0000000..0c2fe29 --- /dev/null +++ b/util/faketarget.cpp @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/util/instutil.cpp b/util/instutil.cpp deleted file mode 100644 index b347484..0000000 --- a/util/instutil.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// 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 argumentum; - -class MainHeaderCmd : public argumentum::CommandOptions -{ - std::string inputFilename; - std::string outputFilename; - -public: - using CommandOptions::CommandOptions; - void execute( const argumentum::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( argumentum::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." ); - } -}; - -class FakeTargetCmd : public argumentum::CommandOptions -{ - std::string outputFilename; - -public: - using CommandOptions::CommandOptions; - void execute( const argumentum::ParseResult& res ) override - { - auto fout = ofstream( outputFilename ); - fout << "int main() { return 0; }"; - } - -protected: - void add_arguments( argumentum::argument_parser& parser ) override - { - 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." ); - parser.add_command( "fake-target" ) - .help( "Create a cpp file with the function main() " - "that will serve as a fake target." ); - - 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 8c09cbb56e65c8c99376f3c804fdbf2c784da39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Wed, 1 Jan 2020 15:55:14 +0100 Subject: [PATCH 2/3] Update lgtm links in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8f410c7..4dc196a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![Build Status](https://travis-ci.com/mmahnic/cpp-argparse.svg?branch=master)](https://travis-ci.com/mmahnic/cpp-argparse) -[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/mmahnic/cpp-argparse.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/mmahnic/cpp-argparse/context:cpp) +[![Build Status](https://travis-ci.com/mmahnic/argumentum.svg?branch=master)](https://travis-ci.com/mmahnic/argumentum) +[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/mmahnic/argumentum.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/mmahnic/argumentum/context:cpp) # Argumentum / Argparse From b9a4d4682a095dd5589a1536a3f50a85d270fed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mahni=C4=8D?= Date: Wed, 1 Jan 2020 16:03:15 +0100 Subject: [PATCH 3/3] Change the static library name in building doc --- doc/building.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/building.md b/doc/building.md index b466c28..2c2a0c6 100644 --- a/doc/building.md +++ b/doc/building.md @@ -21,15 +21,13 @@ sudo make install ``` find_package( Argumentum CONFIG REQUIRED ) -set( Argumentum_LIBRARIES Argumentum::argumentum-s ) - set( CMAKE_CXX_STANDARD 17 ) add_executable( example main.cpp ) target_link_libraries( example - ${Argumentum_LIBRARIES} + Argumentum::argumentum ) ```