Skip to content

Commit f42bb04

Browse files
committed
Build test and example on CI too
Use includes with namespace docopt
1 parent ea9009a commit f42bb04

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

.github/workflows/cmake-multi-platform.yml

+26-24
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,33 @@ jobs:
4545
c_compiler: cl
4646

4747
steps:
48-
- uses: actions/checkout@v3
48+
- uses: actions/checkout@v3
4949

50-
- name: Set reusable strings
51-
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
52-
id: strings
53-
shell: bash
54-
run: |
55-
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
50+
- name: Set reusable strings
51+
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
52+
id: strings
53+
shell: bash
54+
run: |
55+
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
5656
57-
- name: Configure CMake
58-
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
59-
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
60-
run: >
61-
cmake -B ${{ steps.strings.outputs.build-output-dir }}
62-
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
63-
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
64-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
65-
-S ${{ github.workspace }}
57+
- name: Configure CMake
58+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
59+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
60+
run: >
61+
cmake -B ${{ steps.strings.outputs.build-output-dir }}
62+
-D CMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
63+
-D CMAKE_C_COMPILER=${{ matrix.c_compiler }}
64+
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }}
65+
-D WITH_TESTS=YES
66+
-D WITH_EXAMPLE=YES
67+
-S ${{ github.workspace }}
6668
67-
- name: Build
68-
# 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).
69-
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
69+
- name: Build
70+
# 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).
71+
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
7072

71-
- name: Test
72-
working-directory: ${{ steps.strings.outputs.build-output-dir }}
73-
# 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).
74-
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
75-
run: ctest --build-config ${{ matrix.build_type }}
73+
- name: Test
74+
working-directory: ${{ steps.strings.outputs.build-output-dir }}
75+
# 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).
76+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
77+
run: ctest --build-config ${{ matrix.build_type }}

CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ set_target_properties(docopt PROPERTIES
4141
SOVERSION ${PROJECT_VERSION_MAJOR}
4242
)
4343

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

4646
if(MSVC AND BUILD_SHARED_LIBS)
4747
# DOCOPT_DLL: Must be specified when building *and* when using the DLL.
@@ -74,6 +74,8 @@ endif()
7474
# Tests
7575
#============================================================================
7676
if(WITH_TESTS)
77+
enable_testing()
78+
7779
set(TESTPROG "${CMAKE_CURRENT_BINARY_DIR}/run_testcase")
7880
set(TESTCASES "${PROJECT_SOURCE_DIR}/testcases.docopt")
7981
add_executable(run_testcase run_testcase.cpp)
@@ -98,7 +100,7 @@ install(TARGETS docopt EXPORT ${export_name}
98100
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
99101

100102
# Development package
101-
install(FILES ${docopt_HEADERS} DESTINATION include/docopt)
103+
install(FILES ${docopt_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/docopt)
102104

103105
# CMake Package
104106
include(CMakePackageConfigHelpers)

examples/naval_fate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "docopt.h"
1+
#include "docopt/docopt.h"
22

33
#include <iostream>
44

run_testcase.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
// Copyright (c) 2013 Jared Grubb. All rights reserved.
77
//
88

9-
#include "docopt.h"
9+
#include "docopt/docopt.h"
1010

1111
#include <iostream>
1212

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

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

3939
return 0;
40-
}
40+
}

0 commit comments

Comments
 (0)