diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml new file mode 100644 index 0000000..ec03b9f --- /dev/null +++ b/.github/workflows/cmake.yml @@ -0,0 +1,37 @@ +name: CMake + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - 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 ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DWITH_TESTS=ON -DWITH_EXAMPLE=ON + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Test + working-directory: ${{github.workspace}}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest -C ${{env.BUILD_TYPE}} + diff --git a/.gitignore b/.gitignore index 6d7eb1c..b8ca4a6 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,9 @@ docopt-config-version.cmake # Files configured by CMake run_tests + +# cmake build directory +build/ + +# VS Code directory +.vscode/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 28da614..bf733f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.1) project(docopt.cpp VERSION 0.6.2) include(GNUInstallDirs) +enable_testing() #============================================================================ # Settable options @@ -73,6 +74,7 @@ endif() # Tests #============================================================================ if(WITH_TESTS) + find_program(PYTHON python) set(TESTPROG "${CMAKE_CURRENT_BINARY_DIR}/run_testcase") set(TESTCASES "${PROJECT_SOURCE_DIR}/testcases.docopt") add_executable(run_testcase run_testcase.cpp) @@ -82,7 +84,9 @@ if(WITH_TESTS) "${CMAKE_CURRENT_BINARY_DIR}/run_tests" ESCAPE_QUOTES ) - add_test("Testcases docopt" ${TESTPROG}) + add_test(NAME Testcases_docopt + COMMAND ${PYTHON} "${CMAKE_CURRENT_BINARY_DIR}/run_tests" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) endif() #============================================================================