Build and install the library from the sources:
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release
cd build
cmake --build .
sudo make install
Use the static library in a project:
# CMakeLists.txt
cmake_minimum_required( VERSION 3.1 )
project( Example VERSION 0.0.1 )
find_package( Argumentum CONFIG REQUIRED )
set( CMAKE_CXX_STANDARD 17 )
add_executable( example
main.cpp
)
target_link_libraries( example
PRIVATE
Argumentum::argumentum
)
// main.cpp:
#include <argumentum/argparse.h>
using namespace argumentum;
Differences compared to the use of the installed static library:
- Define
-DARGUMENTUM_INSTALL_HEADERONLY=ON
when callingcmake
. - The static library doesn't have to be built when using
cmake
:-DARGUMENTUM_BUILD_STATIC_LIBS=OFF
. - Link to the target
Argumentum::headers
. - Use the header
<argumentum/argparse-h.h>
.
Build and install the library from the sources:
cmake -H. -Bbuild -DARGUMENTUM_INSTALL_HEADERONLY=ON -DARGUMENTUM_BUILD_STATIC_LIBS=OFF
cd build
cmake --build .
sudo make install
Use the header-only library in a project:
# CMakeLists.txt:
cmake_minimum_required( VERSION 3.1 )
project( Example VERSION 0.0.1 )
find_package( Argumentum CONFIG REQUIRED )
set( CMAKE_CXX_STANDARD 17 )
add_executable( example
main.cpp
)
target_link_libraries( example
PRIVATE
Argumentum::headers
)
// main.cpp:
#include <argumentum/argparse-h.h>
using namespace argumentum;
In vcpkg
directory:
./vcpkg install argumentum
Use in your CMake project:
cmake -H. -Bbuild -DCMAKE_TOOLCHAIN_FILE=path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
Download the library with git clone
git clone https://github.com/mmahnic/argumentum.git external/argumentum
or with git submodule
inside your project's git repository
git submodule add https://github.com/mmahnic/argumentum.git external/argumentum
Add the library to a project as a subdirectory:
# CMakeLists.txt:
cmake_minimum_required( VERSION 3.1 )
project( Example VERSION 0.0.1 )
add_subdirectory( external/argumentum )
set( CMAKE_CXX_STANDARD 17 )
add_executable( example main.cpp )
target_link_libraries( example
PRIVATE
Argumentum::argumentum
)
// main.cpp:
#include <argumentum/argparse.h>
using namespace argumentum;
To build the project, building of the static library must be enabled:
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release -DARGUMENTUM_BUILD_STATIC_LIBS=ON
cmake --build build
Differences compared to the use of the cloned static library:
- Link to the target
Argumentum::headers
. - Use the header
<argumentum/argparse-h.h>
. - The static library doesn't have to be built when using
cmake
:-DARGUMENTUM_BUILD_STATIC_LIBS=OFF
.
# CMakeLists.txt:
cmake_minimum_required( VERSION 3.1 )
project( Example VERSION 0.0.1 )
add_subdirectory( external/argumentum )
set( CMAKE_CXX_STANDARD 17 )
add_executable( example main.cpp )
target_link_libraries( example
PRIVATE
Argumentum::headers
)
// main.cpp:
#include <argumentum/argparse-h.h>
using namespace argumentum;
Build with cmake
:
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release
cmake --build build
Or compile from the command line if not using CMake:
g++ -Wall -Werror -std=c++17 -o example -I $(pwd)/external/argumentum/include main.cpp
The library can also be used with FetchContent
without cloning the library in advance.
cmake_minimum_required( VERSION 3.11 )
project( Example VERSION 0.0.1 )
set( CMAKE_CXX_STANDARD 17 )
include(FetchContent)
FetchContent_Declare(Argumentum
GIT_REPOSITORY https://github.com/mmahnic/argumentum.git
GIT_TAG master
)
FetchContent_MakeAvailable(Argumentum)
add_executable( example main.cpp )
target_link_libraries( example
PRIVATE
Argumentum::argumentum
# With header-only: Argumentum::headers
)
// main.cpp:
#include <argumentum/argparse.h>
// With header-only: #include <argumentum/argparse-h.h>
using namespace argumentum;
To use the static version of the library, building of the static version must be enabled with
-DARGUMENTUM_BUILD_STATIC_LIBS=ON
:
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release -DARGUMENTUM_BUILD_STATIC_LIBS=ON
cmake --build build