From 3d00ea84ca9f05a3c48fc7c071eb98abd1e1f080 Mon Sep 17 00:00:00 2001 From: Idhrendur Date: Mon, 23 Dec 2024 22:12:59 -0800 Subject: [PATCH] Create a cmake target for the commons library (#272) * Create a cmake target for the commons. * Fix a broken test. * Update workflows * More workflow updates * Add a windows cmake workflow * More workflow updates. * Double-dash * Check folder * Fix presets * No /w * Disable clang-tidy * Update name. * Try correcting directory. * Build both targets. * More path fixes. * Even more path fixes. * In both builds * Add gcov and lcov targets * Maybe don't change folders? * Don't initially build gcov and lcov * Use correct profile * Just get the commands from vic3tohoi4 * Fix syntax error * In both parts * Borrow more from converter * More tweaks * Peek at directories. * More folders * Add some echos * Moar folders * Focus more * Maybe these are the right dirs? * Woah, we're halfway there! * Maybe not the preceding folders? * Correct path to coverage report * Update exclusions. * Don't get coverage of tests. * Exclude nlohmann * Fix path * No need for gcov * Remove another few gcov references * One more workflow --- .github/workflows/linux_codeql-analysis.yml | 9 +- .github/workflows/linux_coverage.yml | 37 +-- .github/workflows/windows_cmake_build.yml | 79 +++++++ CMakeLists.txt | 235 +++++++++----------- CMakePresets.json | 147 ++++++++++++ GameVersion.cpp | 2 +- build_linux.sh | 4 +- build_linux_foreign.sh | 4 +- 8 files changed, 350 insertions(+), 167 deletions(-) create mode 100644 .github/workflows/windows_cmake_build.yml create mode 100644 CMakePresets.json diff --git a/.github/workflows/linux_codeql-analysis.yml b/.github/workflows/linux_codeql-analysis.yml index 828bf163..de1561a5 100644 --- a/.github/workflows/linux_codeql-analysis.yml +++ b/.github/workflows/linux_codeql-analysis.yml @@ -33,8 +33,8 @@ jobs: - name: Build solution run: | - chmod u+x build_linux.sh - ./build_linux.sh + cmake --preset x64-release-linux + cmake --build --preset build-x64-release-linux --target CommonItemsTests -- -j40 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 @@ -72,9 +72,8 @@ jobs: sudo apt-get install libgtest-dev sudo ln -s /usr/bin/gcc-11 /usr/local/bin/gcc sudo ln -s /usr/bin/g++-11 /usr/local/bin/g++ - # Run your build commands next - chmod u+x ./build_linux_foreign.sh - bash ./build_linux_foreign.sh + cmake --preset x64-release-linux + cmake --build --preset build-x64-release-linux --target commonLib CommonItemsTests -- -j40 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/linux_coverage.yml b/.github/workflows/linux_coverage.yml index aa73953d..df06e390 100644 --- a/.github/workflows/linux_coverage.yml +++ b/.github/workflows/linux_coverage.yml @@ -8,7 +8,7 @@ on: jobs: analyze_main: - name: Analyze Local + name: Coverage Check Local if: github.repository_owner == 'ParadoxGameConverters' runs-on: [self-hosted, linux] @@ -27,40 +27,34 @@ jobs: - name: Build solution run: | - cmake -H. -Bbuild && cmake --build ./build --target CommonItemsTests -- -j40 + cmake --preset x64-coverage-linux + cmake --build --preset build-x64-coverage-linux --target CommonItemsTests -- -j40 - name: Run tests run: | - cd build + cd build/x64-coverage-linux ./CommonItemsTests - - name: Run gcov - run: | - cd build - make gcov - - name: Run lcov - run: | - cd build - make lcov + run: cmake --build --preset build-x64-coverage-linux --target lcov - name: Coveralls uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: build/lcoverage/coverage.info + path-to-lcov: build/x64-coverage-linux/lcoverage/coverage.info - uses: actions/upload-artifact@v4 with: name: coverage-report - path: build/lcoverage/ + path: build/x64-coverage-linux/lcoverage/ - name: Cleanup uses: colpal/actions-clean@v1 if: always() analyze: - name: Analyze Foreign + name: Coverage Check Foreign if: github.repository_owner != 'ParadoxGameConverters' runs-on: ubuntu-latest @@ -81,23 +75,16 @@ jobs: sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install libcurl4-openssl-dev lcov - cmake -H. -Bbuild && cmake --build ./build --target CommonItemsTests -- -j3 + cmake --preset x64-coverage-linux + cmake --build --preset build-x64-coverage-linux --target commonLib CommonItemsTests -- -j40 - name: Run tests run: | - cd build + cd build/x64-coverage-linux ./CommonItemsTests - - name: Run gcov - run: | - cd build - make gcov - - name: Run lcov - run: | - cd build - pwd - make lcov + run: cmake --build --preset build-x64-coverage-linux --target lcov - name: Coveralls uses: coverallsapp/github-action@master diff --git a/.github/workflows/windows_cmake_build.yml b/.github/workflows/windows_cmake_build.yml new file mode 100644 index 00000000..b4285fc3 --- /dev/null +++ b/.github/workflows/windows_cmake_build.yml @@ -0,0 +1,79 @@ +name: Windows cmake build and test +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build_and_test: + name: Build and test local + if: github.repository_owner == 'ParadoxGameConverters' + runs-on: [self-hosted, windows] + + steps: + - name: work around permission issue + run: git config --global --add safe.directory /github/workspace + + - name: Add Ninja build to PATH + run: echo "c:\program files\ninja" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + - name: "Cloning repo" + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + + - name: Build with cmake + shell: cmd + run: | + call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" + cmake --preset x64-release-windows + cmake --build --preset build-x64-release-windows --target commonLib CommonItemsTests -- -j40 + + - name: "Run tests" + run: | + cd $Env:GITHUB_WORKSPACE\build\x64-release-windows + .\CommonItemsTests.exe + + - name: "Cleanup" + if: always() + run: | + Get-ChildItem -Path $Env:GITHUB_WORKSPACE -Recurse -Force | Remove-Item -force -recurse + + build_test: + name: Build and test foreign + if: github.repository_owner != 'ParadoxGameConverters' + runs-on: windows-2022 + + steps: + - name: "Cloning repo" + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + + - name: Install ninja + run: | + choco install ninja + + - name: Build with cmake + shell: cmd + run: | + call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" + cmake --preset x64-release-windows + cmake --build --preset build-x64-release-windows --target commonLib -- -j40 + + - name: "Run tests" + run: | + cd $Env:GITHUB_WORKSPACE\build\x64-release-windows + .\CommonItemsTests.exe + + - name: "Cleanup" + if: always() + run: | + Get-ChildItem -Path $Env:GITHUB_WORKSPACE -Recurse -Force | Remove-Item -force -recurse diff --git a/CMakeLists.txt b/CMakeLists.txt index 4db33027..8630246e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,28 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.25) project(CommonItemsTests) # Include directories include_directories(.) -include_directories(/usr/include) -link_directories(/usr/lib) +if (PLATFORM STREQUAL "Linux") + include_directories(/usr/include) + link_directories(/usr/lib) +endif (PLATFORM STREQUAL "Linux") # Set the compiler options -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -g -O0") -set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall -fprofile-arcs -ftest-coverage") -set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON) +set(CMAKE_CXX_STANDARD 23) +set (UNICODE_DEFAULT OFF) + +if (PLATFORM STREQUAL "Windows") + ADD_DEFINITIONS(-DUNICODE -D_UNICODE) +elseif (PLATFORM STREQUAL "Linux") + #set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,readability-*) + if (COVERAGE STREQUAL true) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") + set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON) + else (COVERAGE STREQUAL true) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall") + endif (COVERAGE STREQUAL true) +endif (PLATFORM STREQUAL "Windows") # Create OBJECT_DIR variable set(OBJECT_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir) @@ -23,48 +35,52 @@ add_subdirectory("external/googletest" "googletest") ################################################################################ # Source groups ################################################################################ -set(commonItems - "Color.cpp" - "Color.h" - "CommonFunctions.cpp" - "CommonFunctions.h" - "CommonRegexes.h" - "ConvenientParser.cpp" - "ConvenientParser.h" - "ConverterVersion.cpp" - "ConverterVersion.h" - "Date.cpp" - "Date.h" - "GameVersion.cpp" - "GameVersion.h" - "iconvlite.cpp" - "iconvlite.h" - "LinuxUtils.cpp" - "Log.cpp" - "Log.h" - "Localization/LocalizationBlock.cpp" - "Localization/LocalizationBlock.h" - "Localization/LocalizationDatabase.cpp" - "Localization/LocalizationDatabase.h" - "Localization/LocalizationLambdas.h" - "ModLoader/Mod.h" - "ModLoader/ModFilesystem.cpp" - "ModLoader/ModFilesystem.h" - "ModLoader/ModLoader.cpp" - "ModLoader/ModLoader.h" - "ModLoader/ModParser.cpp" - "ModLoader/ModParser.h" - "OSCommonLayer.cpp" - "OSCompatibilityLayer.h" - "Parser.cpp" - "Parser.h" - "ParserHelpers.cpp" - "ParserHelpers.h" - "StringUtils.cpp" - "StringUtils.h" - "external/zip/src/zip.c" +set(COMMON_SOURCES ${COMMON_SOURCES} "Color.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "Color.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "CommonFunctions.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "CommonFunctions.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "CommonRegexes.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "ConvenientParser.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "ConvenientParser.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "ConverterVersion.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "ConverterVersion.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "Date.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "Date.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "GameVersion.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "GameVersion.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "iconvlite.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "iconvlite.h") +if (PLATFORM STREQUAL "Windows") + set(COMMON_SOURCES ${COMMON_SOURCES} "WinUtils.cpp") +elseif (PLATFORM STREQUAL "Linux") + set(COMMON_SOURCES ${COMMON_SOURCES} "LinuxUtils.cpp") +endif (PLATFORM STREQUAL "Windows") +set(COMMON_SOURCES ${COMMON_SOURCES} "Log.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "Log.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationBlock.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationBlock.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationDatabase.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationDatabase.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "Localization/LocalizationLambdas.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/Mod.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModFilesystem.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModFilesystem.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModLoader.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModLoader.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModParser.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "ModLoader/ModParser.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "OSCommonLayer.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "OSCompatibilityLayer.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "Parser.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "Parser.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "ParserHelpers.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "ParserHelpers.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "StringUtils.cpp") +set(COMMON_SOURCES ${COMMON_SOURCES} "StringUtils.h") +set(COMMON_SOURCES ${COMMON_SOURCES} "external/zip/src/zip.c") +add_library(commonLib + ${COMMON_SOURCES} ) -source_group("commonItems" FILES ${commonItems}) set(tests "tests/test_main.cpp" @@ -89,17 +105,12 @@ set(tests ) source_group("tests" FILES ${tests}) -set(ALL_FILES - ${commonItems} - ${tests} -) - ################################################################################ # Target ################################################################################ -add_executable(${PROJECT_NAME} ${ALL_FILES}) - +add_executable(${PROJECT_NAME} ${tests}) +target_link_libraries(${PROJECT_NAME} commonLib) ################################################################################ # Test Files @@ -110,71 +121,43 @@ file(COPY "tests/TestFiles/" DESTINATION "./") ################################ # Coverage ################################ -add_custom_target(gcov - COMMAND mkdir -p gcoverage - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} -) -add_custom_command(TARGET gcov - COMMAND echo "=================== GCOV ====================" - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/Localization/LocalizationBlock.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir/Localization - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/Localization/LocalizationDatabase.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir/Localization - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/ModLoader/ModFilesystem.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir/ModLoader - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/ModLoader/ModLoader.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir/ModLoader - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/ModLoader/ModParser.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir/ModLoader - #COMMAND gcov -b ${CMAKE_SOURCE_DIR}/CardinalToOrdinal.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/Color.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/CommonFunctions.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/ConvenientParser.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/ConverterVersion.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/Date.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/GameVersion.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/iconvlite.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/LinuxUtils.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/Log.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/OSCommonLayer.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/Parser.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/ParserHelpers.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND gcov -b ${CMAKE_SOURCE_DIR}/StringUtils.cpp -o ${CMAKE_BINARY_DIR}/CMakeFiles/CommonItemsTests.dir - COMMAND echo "-- Coverage files have been output to ${CMAKE_BINARY_DIR}/gcoverage" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gcoverage -) - -add_custom_target(lcov - COMMAND mkdir -p lcoverage -) -add_custom_command(TARGET lcov - COMMAND rm -rf CMakeFiles/CommonItemsTests.dir/tests - COMMAND echo "=================== LCOV ====================" - COMMAND echo "-- Passing lcov tool under code coverage" - COMMAND lcov --c --d CMakeFiles --o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/11/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/11/bits/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/11/ext/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "/usr/include/x86_64-linux-gnu/c++/11/bits/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/12/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/12/bits/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/12/ext/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "commonItems/external/googletest/googlemock/include/gmock/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "commonItems/external/googletest/googlemock/include/gmock/internal/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "commonItems/external/googletest/googletest/include/gtest/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "commonItems/external/googletest/googletest/include/gtest/internal/*" -o lcoverage/coverage.info - COMMAND lcov --remove lcoverage/coverage.info "/usr/include/x86_64-linux-gnu/c++/12/bits/*" -o lcoverage/coverage.info - COMMAND echo "-- Generating HTML output files" - COMMAND genhtml lcoverage/coverage.info --output-directory lcoverage -) -add_dependencies(gcov ${PROJECT_NAME}) - -# Make sure to clean up the coverage folder -set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES gcoverage) - -# Create the gcov-clean target. This cleans the build as well as generated -# .gcda and .gcno files. -add_custom_target(init - COMMAND ${CMAKE_MAKE_PROGRAM} clean - COMMAND rm -f ${TEST_OUTPUT_DIRECTORY}/*.gcno - COMMAND rm -f ${TEST_OUTPUT_DIRECTORY}/*.gcda - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} -) +if (COVERAGE STREQUAL true) + add_custom_target(lcov + COMMAND mkdir -p lcoverage + ) + add_custom_command(TARGET lcov + COMMAND echo "=================== LCOV ====================" + COMMAND echo "-- Passing lcov tool under code coverage" + COMMAND lcov --c --d CMakeFiles/commonLib.dir --o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/11/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/11/bits/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/11/ext/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "/usr/include/x86_64-linux-gnu/c++/11/bits/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/12/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/12/bits/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "/usr/include/c++/12/ext/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "/usr/include/x86_64-linux-gnu/c++/12/bits/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "*/commonItems/external/googletest/googlemock/include/gmock/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "*/commonItems/external/googletest/googlemock/include/gmock/internal/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "*/commonItems/external/googletest/googletest/include/gtest/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "*/commonItems/external/googletest/googletest/include/gtest/internal/*" -o lcoverage/coverage.info + COMMAND lcov --remove lcoverage/coverage.info "*/commonItems/external/json/single_include/nlohmann/*" -o lcoverage/coverage.info + COMMAND echo "-- Generating HTML output files" + COMMAND genhtml lcoverage/coverage.info --output-directory lcoverage + ) + + # Make sure to clean up the coverage folder + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES gcoverage) + + # Create the clean target. This cleans the build as well as generated + # .gcda and .gcno files. + add_custom_target(init + COMMAND ${CMAKE_MAKE_PROGRAM} clean + COMMAND rm -f ${TEST_OUTPUT_DIRECTORY}/*.gcno + COMMAND rm -f ${TEST_OUTPUT_DIRECTORY}/*.gcda + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) +endif (COVERAGE STREQUAL true) ################################ # Unit Tests @@ -183,15 +166,3 @@ enable_testing() # Link test executable against gtest & gtest_main target_link_libraries(${PROJECT_NAME} gtest gtest_main gmock ) add_test( runUnitTests ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} ) - -################################ -# Clang-tidy -################################ - -find_program(CLANG_TIDY_EXE NAMES "clang-tidy") -set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}") -add_library(run_clang_tidy - ${ALL_FILES} -) -target_link_libraries(run_clang_tidy pthread) -set_target_properties(run_clang_tidy PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000..4e80ca19 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,147 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "windows-base", + "description": "Target Windows with the Visual Studio development environment.", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "installDir": "${sourceDir}/install/${presetName}", + "cacheVariables": { + "CMAKE_C_COMPILER": "cl.exe", + "CMAKE_CXX_COMPILER": "cl.exe" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "linux-base", + "description": "Target Linux with the gcc/g++ build environment.", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "installDir": "${sourceDir}/install/${presetName}", + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "x64-release-windows", + "displayName": "x64 Release Windows", + "description": "Target Windows (64-bit) with the Visual Studio development environment. (Release)", + "inherits": "windows-base", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", "PLATFORM": "Windows" } + }, + { + "name": "x64-debug-windows", + "displayName": "x64 Debug Windows", + "description": "Target Windows (64-bit) with the Visual Studio development environment. (Debug)", + "inherits": "windows-base", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "PLATFORM": "Windows" } + }, + { + "name": "x64-debug-linux", + "displayName": "x64 Debug Linux", + "description": "Target Linux with the gcc/g++ build environment. (Debug)", + "inherits": "linux-base", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "PLATFORM": "Linux" } + }, + { + "name": "x64-release-linux", + "displayName": "x64 Release Linux", + "description": "Target Linux with the gcc/g++ build environment. (Release)", + "inherits": "linux-base", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", "PLATFORM": "Linux" } + } + , + { + "name": "x64-coverage-linux", + "displayName": "x64 Release Linux", + "description": "Target Linux with the gcc/g++ build environment. (Code Coverage)", + "inherits": "linux-base", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { "CMAKE_BUILD_TYPE": "Coverage", "PLATFORM": "Linux", "COVERAGE": "true" } + } + ], + "buildPresets": [ + { + "name": "build-x64-release-windows", + "displayName": "x64 release", + "configurePreset": "x64-release-windows", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "build-x64-debug-windows", + "displayName": "x64 debug", + "configurePreset": "x64-debug-windows", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "build-x64-debug-linux", + "displayName": "x64 debug", + "configurePreset": "x64-debug-linux", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "build-x64-release-linux", + "displayName": "x64 release", + "configurePreset": "x64-release-linux", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "build-x64-coverage-linux", + "displayName": "x64 code coverage", + "configurePreset": "x64-coverage-linux", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + } + ] +} \ No newline at end of file diff --git a/GameVersion.cpp b/GameVersion.cpp index 09410480..02647473 100644 --- a/GameVersion.cpp +++ b/GameVersion.cpp @@ -541,7 +541,7 @@ std::optional GameVersion::extractVersionFromChangeLog(const std::s return std::nullopt; } line = line.substr(0, pos); - if (!std::isdigit(*line.begin())) + if (line.empty() || !std::isdigit(*line.begin())) { Log(LogLevel::Warning) << "Failure extracting version: " << filePath << " has broken version."; return std::nullopt; diff --git a/build_linux.sh b/build_linux.sh index b41e7203..31b1de53 100644 --- a/build_linux.sh +++ b/build_linux.sh @@ -4,5 +4,5 @@ export CC=/usr/bin/gcc-11 && export CXX=/usr/bin/g++-11 && -cmake -H. -Bbuild && -cmake --build build --target CommonItemsTests -- -j40 +cmake --preset x64-release-linux +cmake --build --preset build-x64-release-linux --target CommonItemsTests -- -j40 diff --git a/build_linux_foreign.sh b/build_linux_foreign.sh index c1e47ba5..cc44bb4e 100644 --- a/build_linux_foreign.sh +++ b/build_linux_foreign.sh @@ -4,5 +4,5 @@ export CC=/usr/bin/gcc-11 && export CXX=/usr/bin/g++-11 && -cmake -H. -Bbuild && -cmake --build build --target CommonItemsTests -- -j3 +cmake --preset x64-release-linux +cmake --build --preset build-x64-release-linux --target CommonItemsTests -- -j40 \ No newline at end of file