Skip to content

Commit

Permalink
Build test and example on CI too
Browse files Browse the repository at this point in the history
Use includes with namespace docopt
  • Loading branch information
ClausKlein committed Nov 26, 2023
1 parent ea9009a commit f42bb04
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
50 changes: 26 additions & 24 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,33 @@ jobs:
c_compiler: cl

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-D CMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-D CMAKE_C_COMPILER=${{ matrix.c_compiler }}
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }}
-D WITH_TESTS=YES
-D WITH_EXAMPLE=YES
-S ${{ github.workspace }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ set_target_properties(docopt PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
)

target_include_directories(docopt PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/docopt> $<INSTALL_INTERFACE:include/docopt>)
target_include_directories(docopt PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

if(MSVC AND BUILD_SHARED_LIBS)
# DOCOPT_DLL: Must be specified when building *and* when using the DLL.
Expand Down Expand Up @@ -74,6 +74,8 @@ endif()
# Tests
#============================================================================
if(WITH_TESTS)
enable_testing()

set(TESTPROG "${CMAKE_CURRENT_BINARY_DIR}/run_testcase")
set(TESTCASES "${PROJECT_SOURCE_DIR}/testcases.docopt")
add_executable(run_testcase run_testcase.cpp)
Expand All @@ -98,7 +100,7 @@ install(TARGETS docopt EXPORT ${export_name}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

# Development package
install(FILES ${docopt_HEADERS} DESTINATION include/docopt)
install(FILES ${docopt_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/docopt)

# CMake Package
include(CMakePackageConfigHelpers)
Expand Down
2 changes: 1 addition & 1 deletion examples/naval_fate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "docopt.h"
#include "docopt/docopt.h"

#include <iostream>

Expand Down
6 changes: 3 additions & 3 deletions run_testcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
// Copyright (c) 2013 Jared Grubb. All rights reserved.
//

#include "docopt.h"
#include "docopt/docopt.h"

#include <iostream>

int main(int argc, const char** argv)
{
if (argc < 2) {
std::cerr << "Usage: docopt_tests USAGE [arg]..." << std::endl;
exit(-5);
exit(0);
}

std::string usage = argv[1];
Expand All @@ -37,4 +37,4 @@ int main(int argc, const char** argv)
std::cout << " }" << std::endl;

return 0;
}
}

0 comments on commit f42bb04

Please sign in to comment.