From 628f01b276d2354fcb7b12169b2262ceac108199 Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Tue, 1 Jun 2021 13:57:09 +0200 Subject: [PATCH] Use VCPKG in the Github Action (fix) --- .github/workflows/cmake.yml | 23 ++++++++++++----------- CMakeLists.txt | 4 +--- src/CMakeLists.txt | 12 +++++++++++- src/main.cpp | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index efe623d..62151d0 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -1,8 +1,13 @@ name: CMake +env: + VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite' + + on: push: - branches: [ main ] + branches: + - '*' workflow_dispatch: @@ -10,8 +15,6 @@ jobs: build: name: "${{ matrix.configurations.name }} | ${{ matrix.cmake-build-type }}" runs-on: ${{ matrix.configurations.os }} - env: - CONAN_SYSREQUIRES_MODE: enabled strategy: fail-fast: false matrix: @@ -37,20 +40,18 @@ jobs: if: matrix.configurations.os == 'ubuntu-20.04' || matrix.configurations.os == 'ubuntu-18.04' run: sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" - - name: Bootstrap VCPKG - if: matrix.configurations.os == 'ubuntu-20.04' || matrix.configurations.os == 'ubuntu-18.04' - run: $GITHUB_WORKSPACE/vcpkg/bootstrap-vcpkg.sh - - name: Bootstrap VCPKG - if: matrix.configurations.os == 'windows-2019' - run: $GITHUB_WORKSPACE\\bootstrap-vcpkg.bat + - name: Create Build Environment + # Some projects don't allow in-source building, so create a separate build directory + # We'll use this as our working directory for all subsequent commands + run: cmake -E make_directory ${{runner.workspace}}/build - name: Configure CMake - working-directory: $GITHUB_WORKSPACE + working-directory: ${{runner.workspace}}/build # Use a bash shell so we can use the same syntax for environment variable # access regardless of the host operating system shell: bash - run: cmake -B ${{runner.workspace}}/build -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} - name: Build working-directory: ${{runner.workspace}}/build diff --git a/CMakeLists.txt b/CMakeLists.txt index 0638206..5518997 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/ CACHE STRING "Vcpkg toolchain file") cmake_minimum_required(VERSION 3.17) +enable_language(CXX) project(modern_cpp_exercises ) set(CMAKE_CXX_STANDARD 20) @@ -10,6 +11,3 @@ set(CMAKE_CXX_STANDARD 20) add_subdirectory(lib) add_subdirectory(src) add_subdirectory(test) - -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/maze.png DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/sprites32.png DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b883ad8..15c6b9b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,22 @@ file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp") add_executable(pacman ${sources}) -target_link_libraries(pacman libpacman) +target_link_libraries(pacman PUBLIC libpacman) + +if(MSVC) + find_package(sdl2 CONFIG REQUIRED) + target_link_libraries(pacman PUBLIC SDL2::SDL2main) +endif() set_target_properties(pacman PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" ) +add_custom_command(TARGET pacman POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${PROJECT_SOURCE_DIR}/assets/maze.png + ${PROJECT_SOURCE_DIR}/assets/sprites32.png + $) #target_compile_options(pacman PRIVATE -fsanitize=address) # /MD will be used implicitly #target_link_directories(pacman PRIVATE "$ENV{ProgramFiles\(x86\)}/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/x64/lib/clang/10.0.0/lib/windows") diff --git a/src/main.cpp b/src/main.cpp index 7fe4ad6..fa0cd1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include "Game.hpp" -extern "C" int main([[maybe_unused]] int argc, [[maybe_unused]] char * argv[]) { +int main(int, char**) { Game game; game.run(); return 0;