From f04dbda0bb2819429db33402fdc70d8aaa46508b Mon Sep 17 00:00:00 2001 From: Dmitrii Ivanov Date: Thu, 26 Jan 2023 23:10:36 +0300 Subject: [PATCH] =?UTF-8?q?*=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D1=91?= =?UTF-8?q?=D0=BD=20GitHub=20Action=20*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80?= =?UTF-8?q?=D0=B6=D0=BA=D0=B0=20vcpkg=20*=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=81=D1=83=D0=B1=D0=BC=D0=BE=D0=B4=D1=83=D0=BB?= =?UTF-8?q?=D0=B8=20*=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20cmake-=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cmake.yml | 38 +++++++++++------- .gitmodules | 6 --- CMakeLists.txt | 74 +++++++++++++++++++++++++++++------- SolitaireTest/CMakeLists.txt | 70 +++++++++++++++------------------- cmake/copy_res.cmake | 15 ++++++++ cmake/vcpkg.cmake | 7 ++++ glog | 1 - googletest | 1 - src/CMakeLists.txt | 4 -- 9 files changed, 137 insertions(+), 79 deletions(-) create mode 100644 cmake/copy_res.cmake create mode 100644 cmake/vcpkg.cmake delete mode 160000 glog delete mode 160000 googletest delete mode 100644 src/CMakeLists.txt diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 9f2f851..76e1807 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -11,33 +11,45 @@ env: 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: ${{ matrix.os }} strategy: fail-fast: false matrix: - os: [ ubuntu-latest, windows-latest ] + config: + # - os: ubuntu-latest + # vcpkg_triplet: x64-linux-release + - os: ubuntu-latest + vcpkg_triplet: x64-linux + # - os: windows-latest + # vcpkg_triplet: x64-windows-release + - os: windows-latest + vcpkg_triplet: x64-windows + + runs-on: ${{ matrix.config.os }} steps: - uses: actions/checkout@v2 with: + ref: ${{ github.ref }} submodules: recursive + - name: Install libs + run: sudo apt install -y libflac-dev libfreetype6-dev libgl1-mesa-dev libopenal-dev libudev-dev libvorbis-dev libx11-dev libxcursor-dev libxi-dev libxrandr-dev + if: ${{ matrix.config.os == 'ubuntu-latest' }} + + - name: vcpkg + uses: johnwason/vcpkg-action@v4 + with: + pkgs: sfml gtest glog + triplet: ${{ matrix.config.vcpkg_triplet }} + cache-key: ${{ matrix.config.os }} + token: ${{ github.token }} + - 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}} + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=${{ matrix.config.vcpkg_triplet }} - 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/.gitmodules b/.gitmodules index 2a80f1f..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "glog"] - path = glog - url = https://github.com/google/glog.git -[submodule "googletest"] - path = googletest - url = https://github.com/google/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c72df1..4b49210 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,23 +1,69 @@ cmake_minimum_required(VERSION 3.10.2) +################################################################################ +# vcpkg +################################################################################ +include (${CMAKE_SOURCE_DIR}/cmake/vcpkg.cmake) + +################################################################################ +# Project +################################################################################ project(SolitaireGame VERSION 0.1.0) -set(BUILD_SHARED_LIBS OFF) -option(BUILD_TESTING OFF) -option(WITH_GFLAGS OFF) -add_compile_options(-DHAVE_SNPRINTF) -set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) -if (MSVC) - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") -endif() +set(CMAKE_CXX_STANDARD 11) + +################################################################################ +# External libraries +################################################################################ +find_package(glog CONFIG REQUIRED) +find_package(GTest CONFIG REQUIRED) +find_package(SFML COMPONENTS system window graphics CONFIG REQUIRED) + +################################################################################ +# Sources +################################################################################ +set(coregame_dir src/CoreGame/) +set(engine_dir src/Engine/) +set(utils_dir src/Utils/) + +file(GLOB_RECURSE common_sources ${engine_dir}*.cpp ${utils_dir}*.cpp ${coregame_dir}*.cpp) +file(GLOB_RECURSE common_headers ${engine_dir}*.h ${utils_dir}*.h ${coregame_dir}*.h) +file(GLOB_RECURSE src_sources src/*.cpp) +file(GLOB_RECURSE src_headers src/*.h) + +set(sources ${src_sources} ${src_headers} ${common_sources} ${common_headers}) + +################################################################################ +# Executable +################################################################################ +add_executable(${PROJECT_NAME} ${sources}) + +target_link_libraries(${PROJECT_NAME} PRIVATE + glog::glog + GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main + sfml-system sfml-graphics sfml-window +) -add_subdirectory(glog) -include_directories(glog) +################################################################################ +# Resources +################################################################################ +include (${CMAKE_SOURCE_DIR}/cmake/copy_res.cmake) +################################################################################ +# - Blueprints +################################################################################ -enable_testing() -add_subdirectory(googletest) +set(BLUEPRINTS_DIR Blueprints) +# file(GLOB blueprints ${BLUEPRINTS_DIR}/*.*) +CopyResources(${BLUEPRINTS_DIR}/*.* $) -add_subdirectory(src) +################################################################################ +# - Fonts +################################################################################ +set(FONT_DIR Font) +# file(GLOB fonts ${FONT_DIR}/*.*) +CopyResources(${FONT_DIR}/*.* $) +################################################################################ +# SubProjects +################################################################################ add_subdirectory(SolitaireTest) diff --git a/SolitaireTest/CMakeLists.txt b/SolitaireTest/CMakeLists.txt index 99e7543..eb5463f 100644 --- a/SolitaireTest/CMakeLists.txt +++ b/SolitaireTest/CMakeLists.txt @@ -1,42 +1,27 @@ cmake_minimum_required(VERSION 3.10.2) +################################################################################ +# Project +################################################################################ project(SolitaireTest) -if (MSVC) - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") -endif() +set(CMAKE_CXX_STANDARD 11) -find_library(GTEST_LIB gtestd ${CMAKE_BINARY_DIR}/lib/Debug) +################################################################################ +# External libraries +################################################################################ +find_package(glog CONFIG REQUIRED) +find_package(GTest CONFIG REQUIRED) +find_package(SFML COMPONENTS system window graphics CONFIG REQUIRED) -if(GTEST_LIB) - message("Gtest library found") -else() - message("Gtest library not found") - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -endif() +################################################################################ +# Sources +################################################################################ +set(engine_dir_test ../src/Engine/) +set(utils_dir_test ../src/Utils/) -message("CMAKE_BINARY_DIR = " ${CMAKE_BINARY_DIR}) -include_directories("${CMAKE_BINARY_DIR}/googletest") - -if (CMAKE_VERSION VERSION_LESS 2.8.11) - - include_directories("${gtest_SOURCE_DIR}/include" - "${gmock_SOURCE_DIR}/include") - - message(gtest_SOURCE_DIR ${gtest_SOURCE_DIR}) - message(gmock_SOURCE_DIR ${gmock_SOURCE_DIR}) - -endif() - -set(field_dir_test ../src/Field/) -set(common_dir_test ../src/Common/) -set(game_dir_test ../src/Game/) - -file(GLOB_RECURSE common_sources_test ${field_dir_test}*.cpp ${common_dir_test}*.cpp - ${game_dir_test}*.cpp ) -file(GLOB_RECURSE common_headers_test ${field_dir_test}*.h ${common_dir_test}*.h - ${game_dir_test}*.h) +file(GLOB_RECURSE common_sources_test ${engine_dir_test}*.cpp ${utils_dir_test}*.cpp) +file(GLOB_RECURSE common_headers_test ${engine_dir_test}*.h ${utils_dir_test}*.h) file(GLOB_RECURSE TEST_SRC_SOURCE ${PROJECT_SOURCE_DIR}/*.cpp) file(GLOB_RECURSE TEST_SRC_HEADERS ${PROJECT_SOURCE_DIR}/*.h) @@ -48,13 +33,18 @@ set(sources_test ${common_headers_test} ) -find_library(GLOG_LIB glogd ${CMAKE_BINARY_DIR}/glog/Debug) -if(GLOG_LIB) - message ("GLOG_TEST FOUND!!!") -else() - message ("GLOG_TEST NOT FOUND!!!") -endif() - +################################################################################ +# Executable +################################################################################ add_executable(testmain ${sources_test}) -target_link_libraries(testmain gtest gmock_main gtest_main glog) +target_link_libraries(testmain PRIVATE + glog::glog + GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main + sfml-system sfml-graphics sfml-window +) + +################################################################################ +# Tests +################################################################################ +enable_testing() add_test(NAME testmain COMMAND testmain) \ No newline at end of file diff --git a/cmake/copy_res.cmake b/cmake/copy_res.cmake new file mode 100644 index 0000000..7a268e8 --- /dev/null +++ b/cmake/copy_res.cmake @@ -0,0 +1,15 @@ +################################################################################ +# CopyResources +################################################################################ +function(CopyResources src_dir dest_dir) + file(GLOB files ${src_dir}) + + foreach(item IN LISTS files) + get_filename_component(dest_filename ${item} NAME) + + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${item} + ${dest_dir}/${dest_filename} + ) + endforeach() +endfunction() \ No newline at end of file diff --git a/cmake/vcpkg.cmake b/cmake/vcpkg.cmake new file mode 100644 index 0000000..e00b1cd --- /dev/null +++ b/cmake/vcpkg.cmake @@ -0,0 +1,7 @@ +################################################################################ +# vcpkg +################################################################################ +if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + CACHE STRING "") +endif() \ No newline at end of file diff --git a/glog b/glog deleted file mode 160000 index 6e46c12..0000000 --- a/glog +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6e46c125e3718ce64570883e2ca558b3c853a125 diff --git a/googletest b/googletest deleted file mode 160000 index 4ec4cd2..0000000 --- a/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4ec4cd23f486bf70efcc5d2caa40f24368f752e3 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index cd535c3..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -message(${PROJECT_NAME}) -message("Runner") - -add_subdirectory(Runner) \ No newline at end of file