Skip to content

Commit

Permalink
Merge branch 'improve_build'
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahnic committed Dec 18, 2019
2 parents 440bc29 + 1a7e703 commit 23c69f6
Show file tree
Hide file tree
Showing 35 changed files with 282 additions and 153 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
build-*/

*.swp
*.*~
Expand Down
19 changes: 13 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ sudo: false
language:
- cpp

script:
- cmake -H. -Bbuild -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER
- cd build
- cmake --build .
- ctest

matrix:
include:
- os: linux
Expand Down Expand Up @@ -43,6 +37,19 @@ matrix:
- C_COMPILER=gcc-8
- CXX_COMPILER=g++-8

install:
- mkdir /tmp/build-gtest && cd /tmp/build-gtest
- 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
- cd build
- cmake --build .
- ctest

notifications:
email: false

55 changes: 44 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
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_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(CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/CppArgparse)

set(CPPARGPARSE_STATIC_NAME argparse-s)
add_subdirectory(src)
add_subdirectory(example)
add_subdirectory(util)

if( CPPARGPARSE_BUILD_EXAMPLES )
add_subdirectory(example)
endif()

if( CPPARGPARSE_BUILD_TESTS )
enable_testing()
add_subdirectory(test)
add_subdirectory(test/staticlib)
add_subdirectory(test/headerlib)
endif()

if (CPPARGPARSE_INSTALL)
include(GNUInstallDirs)
add_subdirectory(include)

include(CMakePackageConfigHelpers)

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
)

include(cmake/googletest/googletest.cmake)
fetch_googletest(
${PROJECT_SOURCE_DIR}/cmake/googletest
${PROJECT_BINARY_DIR}/googletest
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/CppArgparseConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/CppArgparseConfigVersion.cmake
DESTINATION ${CONFIG_INSTALL_DIR}
)

enable_testing()
add_subdirectory(test)
add_subdirectory(test/staticlib)
add_subdirectory(test/headerlib)
endif()
4 changes: 4 additions & 0 deletions cmake/CppArgparseConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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@")
30 changes: 0 additions & 30 deletions cmake/googletest/README.md

This file was deleted.

20 changes: 0 additions & 20 deletions cmake/googletest/googletest-download.cmake

This file was deleted.

32 changes: 0 additions & 32 deletions cmake/googletest/googletest.cmake

This file was deleted.

25 changes: 25 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

include_directories( ../include )
set ( CPPARGPARSE_EXAMPLE_LIB ${CPPARGPARSE_STATIC_NAME} )

# The library is currently header-only.
set(PARSER_SOURCES
Expand All @@ -9,24 +10,48 @@ set(PARSER_SOURCES
add_executable( basic
basic.cpp
)
target_link_libraries( basic
${CMAKE_BINARY_DIR}/src/libargparse-s.a
)
add_dependencies( basic ${CPPARGPARSE_EXAMPLE_LIB} )

add_executable( basic_action
basic_action.cpp
)
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
)
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
)
target_link_libraries( basic_command
${CMAKE_BINARY_DIR}/src/libargparse-s.a
)
add_dependencies( basic_command ${CPPARGPARSE_EXAMPLE_LIB} )

add_executable( example1
example1.cpp
)
target_link_libraries( example1
${CMAKE_BINARY_DIR}/src/libargparse-s.a
)
add_dependencies( example1 ${CPPARGPARSE_EXAMPLE_LIB} )

add_executable( example2
example2.cpp
)
target_link_libraries( example2
${CMAKE_BINARY_DIR}/src/libargparse-s.a
)
add_dependencies( example2 ${CPPARGPARSE_EXAMPLE_LIB} )

30 changes: 30 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

add_custom_command(
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

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})

30 changes: 30 additions & 0 deletions include/cppargparse/argparse-h.h
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions include/cppargparse/argparse-s.h

This file was deleted.

25 changes: 1 addition & 24 deletions include/cppargparse/argparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 14 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@

add_library(argparse-s STATIC
add_library(${CPPARGPARSE_STATIC_NAME} STATIC
argparser.cpp
)
if( CPPARGPARSE_PEDANTIC )
target_compile_options(${CPPARGPARSE_STATIC_NAME} PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Werror -Wall>
$<$<CXX_COMPILER_ID:MSVC>:/WX /permissive- /Za>
)
endif()

if (CPPARGPARSE_INSTALL)
install( TARGETS ${CPPARGPARSE_STATIC_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
endif()
Loading

0 comments on commit 23c69f6

Please sign in to comment.