diff --git a/CMakeLists.txt b/CMakeLists.txt index dbb18f1d..372e8553 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ include(CPack) option(BUILD_SHARED_LIBS "build shared libs with C inteface" ON) option(BUILD_EXAMPLES "build examples" ON) include(CTest) +option(ENABLE_CODE_COVERAGE "compile Debug with code coverage" OFF) option(BUILD_SNAPSHOT "build snapshot test" OFF) include(CMakeDependentOption) CMAKE_DEPENDENT_OPTION(TEST_DUMP_SNAPSHOT "build test to dump the expected output instead of verifing it" OFF diff --git a/README.md b/README.md index a88bd0ef..4764c6e1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # SDL2 VGA Terminal [![Codacy Badge](https://api.codacy.com/project/badge/Grade/83e178fb7d9343b78be651f2797fe3f8)](https://app.codacy.com/manual/Raffaello/sdl2-vga-terminal?utm_source=github.com&utm_medium=referral&utm_content=Raffaello/sdl2-vga-terminal&utm_campaign=Badge_Grade_Settings) +[![codecov](https://codecov.io/gh/Raffaello/sdl2-vga-terminal/branch/master/graph/badge.svg)](https://codecov.io/gh/Raffaello/sdl2-vga-terminal) | Monolithic CI | Note | |:-------------:|-----:| diff --git a/appveyor.yml b/appveyor.yml index ac65772f..2c5e09a5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,6 +19,7 @@ configuration: environment: VCPKG_SCRIPT: scripts/buildsystems/vcpkg.cmake + ENABLE_CODE_COVERAGE: OFF matrix: allow_failures: @@ -46,17 +47,29 @@ for: environment: WS: /Users/appveyor/projects TRIPLET: $PLATFORM-osx +# ENABLE_CODE_COVERAGE: ON cache: #- $WS/vcpkg - $WS/vcpkg/installed init: - sh: if [ $PLATFORM = "x86" ]; then exit 1; fi - - sh: brew install p7zip + - sh: brew install p7zip #lcov - sh: cd $WS && git clone https://github.com/Microsoft/vcpkg.git - sh: cd $APPVEYOR_BUILD_FOLDER + # /Library/Developer/CommandLineTools/usr/bin/llvm-cov + #- sh: sudo find / -name llvm-cov 2> /dev/null + #- sh: llvm-cov --help test_script: - sh: ctest -V - + #- sh: find . -name *.gcda + #- sh: echo '#!/bin/bash' > g.sh + #- sh: echo 'exec /Library/Developer/CommandLineTools/usr/bin/llvm-cov gcov "$@"' >> g.sh + #- sh: chmod +x g.sh + #- sh: ./g.sh -f -b -u $(find . -name *.gcda) + #- sh: lcov --directory . --base-directory . --gcov-tool ./g.sh --capture -o cov.info + #- sh: lcov --remove cov.info '/Applications/*' --output-file coverage.info + #- sh: lcov --list coverage.info + #- sh: bash <(curl -s https://codecov.io/bash) -f coverage.info -t b8f07100-6985-49f7-aa4c-14e36f29ac80 skip_commits: files: @@ -90,8 +103,8 @@ before_build: build_script: - mkdir out - cd out - - cmd: cmake -G "Ninja" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DWITH_SDL2_STATIC=OFF -DBUILD_SNAPSHOT=OFF -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/%VCPKG_SCRIPT% .. - - sh : cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION -DWITH_SDL2_STATIC=ON -DBUILD_SNAPSHOT=OFF -DCMAKE_TOOLCHAIN_FILE=$WS/vcpkg/$VCPKG_SCRIPT .. + - cmd: cmake -G "Ninja" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DWITH_SDL2_STATIC=OFF -DBUILD_SNAPSHOT=OFF -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/%VCPKG_SCRIPT% .. + - sh : cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION -DWITH_SDL2_STATIC=ON -DBUILD_SNAPSHOT=OFF -DENABLE_CODE_COVERAGE=$ENABLE_CODE_COVERAGE -DCMAKE_TOOLCHAIN_FILE=$WS/vcpkg/$VCPKG_SCRIPT .. - cmake --build . test_script: diff --git a/azure-pipelines/analyzer.yml b/azure-pipelines/analyzer.yml index d0d2ecf6..7faaaf2a 100644 --- a/azure-pipelines/analyzer.yml +++ b/azure-pipelines/analyzer.yml @@ -25,7 +25,9 @@ pr: - LICENSE variables: - - template: variables.yml + - template: variables/global.yml + - template: variables/images.yml + - template: variables/build_switches.yml stages: - stage: Dep @@ -33,10 +35,9 @@ stages: - job: vcpkg strategy: matrix: - Win 64 bits: - imageName: ${{ variables.windows_image }} - TRIPLET: x64-windows - ARCH: 64 + osx: + imageName: ${{ variables.mac_image }} + TRIPLET: x64-osx pool: vmImage: $(imageName) steps: @@ -46,18 +47,34 @@ stages: triplet: $(TRIPLET) arch: $(ARCH) + - stage: Analyzer + variables: + BUILD_EXAMPLES: OFF + BUILD_SHARED_LIBS: ON + ENABLE_CODE_COVERAGE: ON jobs: + # - template: 'templates/sonarcloud-job.yml' + # parameters: + # imageName: ${{ variables.windows_image }} + # jobName: SonarCloud_win + # jobDisplayName: SonarCloud (WIN) + # vcpkg_key_cache: $(CACHE_VCPKG_KEY) + # triplet: x64-windows + # arch: 64 + # build_type: Debug + # sonar_wrapper_url: 'https://sonarcloud.io/static/cpp/build-wrapper-win-x86.zip' + # build_wrapper: 'build-wrapper-win-x86\build-wrapper-win-x86-64.exe' + # build_wrapper_path: build/build-wrapper-win-x86 + # cmake_ignore_path: $(CMAKE_IGNORE_PATH_WIN) - template: 'templates/sonarcloud-job.yml' parameters: - imageName: ${{ variables.windows_image }} - jobName: SonarCloud_win - jobDisplayName: SonarCloud (WIN) + imageName: ${{ variables.mac_image }} + jobName: SonarCloud_macos + jobDisplayName: SonarCloud (macOS) vcpkg_key_cache: $(CACHE_VCPKG_KEY) - triplet: x64-windows - arch: 64 + triplet: x64-osx build_type: Debug - sonar_wrapper_url: 'https://sonarcloud.io/static/cpp/build-wrapper-win-x86.zip' - build_wrapper: 'build-wrapper-win-x86\build-wrapper-win-x86-64.exe' - build_wrapper_path: build/build-wrapper-win-x86 - cmake_ignore_path: $(CMAKE_IGNORE_PATH_WIN) + sonar_wrapper_url: 'https://sonarcloud.io/static/cpp/build-wrapper-macosx-x86.zip' + build_wrapper: 'build-wrapper-macosx-x86/build-wrapper-macosx-x86' + build_wrapper_path: build/build-wrapper-macosx-x86 diff --git a/azure-pipelines/linux.yml b/azure-pipelines/linux.yml index d58f09a4..f8e37d2b 100644 --- a/azure-pipelines/linux.yml +++ b/azure-pipelines/linux.yml @@ -25,31 +25,25 @@ pr: - LICENSE variables: - - template: variables.yml + - template: variables/global.yml + - template: variables/images.yml + - template: variables/build_switches.yml stages: - stage: Dep jobs: - job: vcpkg - strategy: - matrix: - Linux: - imageName: ${{ variables.linux_image }} - TRIPLET: x64-linux pool: - vmImage: $(imageName) + vmImage: ${{ variables.linux_image }} steps: - template: templates/dep-vcpkg-steps.yml parameters: vcpkg_key_cache: $(CACHE_VCPKG_KEY) - triplet: $(TRIPLET) - arch: $(ARCH) + triplet: x64-linux - stage: CI jobs: - job: Linux - variables: - TRIPLET: x64-linux strategy: matrix: GCC Debug: @@ -62,7 +56,7 @@ stages: - template: 'templates/ci-steps.yml' parameters: vcpkg_key_cache: $(CACHE_VCPKG_KEY) - triplet: $(TRIPLET) + triplet: x64-linux build_type: $(CONFIGURATION) test: false install: false diff --git a/azure-pipelines/macos.yml b/azure-pipelines/macos.yml index 808b10e9..e8707b2d 100644 --- a/azure-pipelines/macos.yml +++ b/azure-pipelines/macos.yml @@ -23,33 +23,26 @@ pr: - README.md - appveyor.yml - LICENSE - variables: - - template: variables.yml + - template: variables/global.yml + - template: variables/images.yml + - template: variables/build_switches.yml stages: - stage: Dep jobs: - job: vcpkg - strategy: - matrix: - MacOS: - imageName: ${{ variables.mac_image }} - TRIPLET: x64-osx pool: - vmImage: $(imageName) + vmImage: ${{ variables.mac_image }} steps: - template: templates/dep-vcpkg-steps.yml parameters: vcpkg_key_cache: $(CACHE_VCPKG_KEY) - triplet: $(TRIPLET) - arch: $(ARCH) + triplet: x64-osx - stage: CI jobs: - job: macOS - variables: - TRIPLET: x64-osx strategy: matrix: Debug: @@ -62,6 +55,6 @@ stages: - template: 'templates/ci-steps.yml' parameters: vcpkg_key_cache: $(CACHE_VCPKG_KEY) - triplet: $(TRIPLET) + triplet: x64-osx build_type: $(CONFIGURATION) install: false diff --git a/azure-pipelines/monolithic.yml b/azure-pipelines/monolithic.yml index 7be7250b..6fb014b8 100644 --- a/azure-pipelines/monolithic.yml +++ b/azure-pipelines/monolithic.yml @@ -27,7 +27,9 @@ pr: - LICENSE variables: - - template: variables.yml + - template: variables/global.yml + - template: variables/images.yml + - template: variables/build_switches.yml stages: - stage: Dep diff --git a/azure-pipelines/templates/ci-steps.yml b/azure-pipelines/templates/ci-steps.yml index e997ba82..c8d4b8c9 100644 --- a/azure-pipelines/templates/ci-steps.yml +++ b/azure-pipelines/templates/ci-steps.yml @@ -57,15 +57,27 @@ steps: - template: 'cmake-gen-build-steps.yml' parameters: build_type: ${{ parameters.build_type }} + triplet: ${{ parameters.triplet }} vcpkg_cmake: ${{ parameters.vcpkg_cmake }} cmake_args: ${{ parameters.cmake_args }} cmake_ignore_path: ${{ parameters.cmake_ignore_path }} arch: ${{ parameters.arch }} #build_wrapper: - ${{ if eq(parameters.test, true) }}: - - script: ctest -C ${{ parameters.build_type }} -V + - script: ctest -C ${{ parameters.build_type }} -v -V -T Test displayName: cmake test (ctest) workingDirectory: build + - task: PublishTestResults@2 + inputs: + testResultsFormat: 'cTest' # Options: JUnit, NUnit, VSTest, xUnit, cTest + testResultsFiles: '**/Test.xml' + searchFolder: build # Optional + #mergeTestResults: false # Optional + #failTaskOnFailedTests: false # Optional + #testRunTitle: # Optional + #buildPlatform: # Optional + #buildConfiguration: # Optional + #publishRunAttachments: true # Optional - ${{ if eq(parameters.install, true) }}: - script: cmake --build . --target install diff --git a/azure-pipelines/templates/cmake-gen-build-steps.yml b/azure-pipelines/templates/cmake-gen-build-steps.yml index 74545c13..b0c18732 100644 --- a/azure-pipelines/templates/cmake-gen-build-steps.yml +++ b/azure-pipelines/templates/cmake-gen-build-steps.yml @@ -2,6 +2,10 @@ parameters: - name: build_type displayName: Build Type type: string + + - name: triplet + displayName: triplet + type: string - name: vcpkg_cmake displayName: VCPKG_CMAKE @@ -31,7 +35,7 @@ parameters: steps: - bash: | mkdir -p build && cd build - cmake -DCMAKE_BUILD_TYPE=${{ parameters.build_type }} -DCMAKE_TOOLCHAIN_FILE=${{ parameters.vcpkg_cmake }} ${{ parameters.cmake_args }} .. + cmake -DVCPKG_TARGET_TRIPLET=${{ parameters.triplet }} -DCMAKE_BUILD_TYPE=${{ parameters.build_type }} -DCMAKE_TOOLCHAIN_FILE=${{ parameters.vcpkg_cmake }} ${{ parameters.cmake_args }} .. displayName: cmake generator (UNIX) condition: ne(variables['Agent.OS'], 'Windows_NT') - bash: ${{ parameters.build_wrapper }} cmake --build . @@ -42,7 +46,7 @@ steps: - script: | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars${{ parameters.arch }}.bat" mkdir build & cd build - cmake -DCMAKE_IGNORE_PATH="${{ parameters.cmake_ignore_path }}" -G"Ninja" -DCMAKE_BUILD_TYPE=${{ parameters.build_type }} -DCMAKE_TOOLCHAIN_FILE=${{ parameters.vcpkg_cmake }} ${{ parameters.cmake_args }} .. + cmake -DVCPKG_TARGET_TRIPLET=${{ parameters.triplet }} -DCMAKE_IGNORE_PATH="${{ parameters.cmake_ignore_path }}" -G"Ninja" -DCMAKE_BUILD_TYPE=${{ parameters.build_type }} -DCMAKE_TOOLCHAIN_FILE=${{ parameters.vcpkg_cmake }} ${{ parameters.cmake_args }} .. displayName: 'CMake generator (WIN)' condition: eq(variables['Agent.OS'], 'Windows_NT') - script: | diff --git a/azure-pipelines/templates/dep-vcpkg-steps.yml b/azure-pipelines/templates/dep-vcpkg-steps.yml index 6d3bb399..e68e82db 100644 --- a/azure-pipelines/templates/dep-vcpkg-steps.yml +++ b/azure-pipelines/templates/dep-vcpkg-steps.yml @@ -25,11 +25,10 @@ parameters: steps: - checkout: none -- task: Cache@2 - inputs: - key: '${{ parameters.vcpkg_key_cache }} | ${{ parameters.triplet }}' - path: "vcpkg" - cacheHitVar: CACHE_RESTORED +- template: 'vcpkg-cache-step.yml' + parameters: + vcpkg_key_cache: ${{ parameters.vcpkg_key_cache }} + triplet: ${{ parameters.triplet }} - bash: test -d vcpkg || git clone https://github.com/Microsoft/vcpkg.git displayName: clone vcpkg - script: echo "installing packages ${{ parameters.packages }}" diff --git a/azure-pipelines/templates/sonarcloud-job.yml b/azure-pipelines/templates/sonarcloud-job.yml index 1f5a59e4..3726ce80 100644 --- a/azure-pipelines/templates/sonarcloud-job.yml +++ b/azure-pipelines/templates/sonarcloud-job.yml @@ -74,6 +74,11 @@ parameters: - build/build-wrapper-linux-x86-64 - build/build-wrapper-macosx-x86 + - name: test + displayName: Run Test? + type: boolean + default: true + - name: publish_timeout displayName: PUBLISH_TIMEOUT type: number @@ -90,6 +95,7 @@ jobs: parameters: vcpkg_key_cache: ${{ parameters.vcpkg_key_cache }} triplet: ${{ parameters.triplet }} + - task: Cache@2 inputs: key: '"${{ parameters.sonar_wrapper_url }}" | "$(Agent.OS)"' @@ -102,6 +108,7 @@ jobs: unzip build-wrapper.zip displayName: build-wrapper condition: ne(variables.CACHED_BUILD_WRAPPER, 'true') + - task: SonarCloudPrepare@1 inputs: SonarCloud: 'sonarCloud' @@ -109,14 +116,49 @@ jobs: scannerMode: 'CLI' configMode: 'file' displayName: Prepare sonarCloud + - template: 'cmake-gen-build-steps.yml' parameters: build_type: ${{ parameters.build_type }} + triplet: ${{ parameters.triplet }} vcpkg_cmake: ${{ parameters.vcpkg_cmake }} cmake_args: ${{ parameters.cmake_args }} cmake_ignore_path: ${{ parameters.cmake_ignore_path }} arch: ${{ parameters.arch }} - build_wrapper: "${{ parameters.build_wrapper }} --out-dir bw-output" + build_wrapper: "${{ parameters.build_wrapper }} --out-dir bw-output" + + - ${{ if eq(parameters.test, true) }}: + - script: ctest -C ${{ parameters.build_type }} + displayName: ctest + workingDirectory: build + # /usr/local/Cellar/llvm/10.0.0_3/bin/llvm-cov + - bash: | + echo '#!/bin/bash' > g.sh + echo 'exec /usr/local/Cellar/llvm/10.0.0_3/bin/llvm-cov gcov "$@"' >> g.sh + chmod +x g.sh + cat g.sh + displayName: llvm-cov gcov wrapper + workingDirectory: build + condition: ne(variables['Agent.OS'], 'Windows_NT') + + #- bash: sudo find / -name llvm-cov 2> /dev/null + # displayName: llvm-cov DEBUG + # condition: ne(variables['Agent.OS'], 'Windows_NT') + - bash: | + echo $OSTYPE + test $OSTYPE = "darwin19" && brew install lcov || apt-get install -y lcov + #brew install lcov + #echo "finding..." + #find . -name *.gcda + #echo "...." + ./g.sh -f -b -u $(find . -name *.gcda) + lcov --directory . --base-directory . --gcov-tool ./g.sh --capture -o cov.info + lcov --remove cov.info '/Applications/*' --output-file coverage.info + lcov --list coverage.info + bash <(curl -s https://codecov.io/bash) -f coverage.info -t b8f07100-6985-49f7-aa4c-14e36f29ac80 + displayName: collect coverage data + workingDirectory: build + condition: ne(variables['Agent.OS'], 'Windows_NT') - task: SonarCloudAnalyze@1 - task: SonarCloudPublish@1 inputs: diff --git a/azure-pipelines/variables/build_switches.yml b/azure-pipelines/variables/build_switches.yml new file mode 100644 index 00000000..49888b70 --- /dev/null +++ b/azure-pipelines/variables/build_switches.yml @@ -0,0 +1,7 @@ +variables: + SDL2_STATIC: ON + BUILD_TESTING: ON + BUILD_SHARED_LIBS: ON + BUILD_EXAMPLES: ON + BUILD_SNAPSHOT: OFF + ENABLE_CODE_COVERAGE: OFF diff --git a/azure-pipelines/variables.yml b/azure-pipelines/variables/global.yml similarity index 69% rename from azure-pipelines/variables.yml rename to azure-pipelines/variables/global.yml index d6fd212c..09849b1a 100644 --- a/azure-pipelines/variables.yml +++ b/azure-pipelines/variables/global.yml @@ -1,13 +1,5 @@ variables: - windows_image: 'windows-2019' - linux_image: 'ubuntu-18.04' - mac_image: 'macOS-10.15' CACHE_VCPKG_KEY: v4 | vcpkg-root VCPKG_CMAKE: "$(Build.SourcesDirectory)/vcpkg/scripts/buildsystems/vcpkg.cmake" - SDL2_STATIC: ON - BUILD_TESTING: ON - BUILD_SHARED_LIBS: ON - BUILD_EXAMPLES: ON - BUILD_SNAPSHOT: OFF - CMAKE_ARGS: -DWITH_SDL2_STATIC=$(SDL2_STATIC) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DBUILD_SNAPSHOT=$(BUILD_SNAPSHOT) + CMAKE_ARGS: -DWITH_SDL2_STATIC=$(SDL2_STATIC) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DBUILD_SNAPSHOT=$(BUILD_SNAPSHOT) -DENABLE_CODE_COVERAGE=$(ENABLE_CODE_COVERAGE) CMAKE_IGNORE_PATH_WIN: "C:/MinGW/bin;C:/Strawberry/c/bin;C:/Program Files (x86)/LLVM/bin;C:/ProgramData/chocolatey/bin" diff --git a/azure-pipelines/variables/images.yml b/azure-pipelines/variables/images.yml new file mode 100644 index 00000000..1b47b328 --- /dev/null +++ b/azure-pipelines/variables/images.yml @@ -0,0 +1,4 @@ +variables: + windows_image: 'windows-2019' + linux_image: 'ubuntu-18.04' + mac_image: 'macOS-10.15' diff --git a/azure-pipelines/windows.yml b/azure-pipelines/windows.yml index 44b08d02..49eab1ad 100644 --- a/azure-pipelines/windows.yml +++ b/azure-pipelines/windows.yml @@ -25,7 +25,9 @@ pr: - LICENSE variables: - - template: variables.yml + - template: variables/global.yml + - template: variables/images.yml + - template: variables/build_switches.yml stages: - stage: Dep @@ -34,15 +36,13 @@ stages: strategy: matrix: Win 32 bits: - imageName: ${{ variables.windows_image }} TRIPLET: x86-windows ARCH: 32 Win 64 bits: - imageName: ${{ variables.windows_image }} TRIPLET: x64-windows ARCH: 64 pool: - vmImage: $(imageName) + vmImage: ${{ variables.windows_image }} steps: - template: templates/dep-vcpkg-steps.yml parameters: @@ -53,9 +53,6 @@ stages: - stage: CI jobs: - job: Windows - variables: - #SDL2_STATIC: OFF - BUILD_SHARED_LIBS: ON strategy: matrix: 64-bit Debug: diff --git a/sdl2-vga-terminal/CMakeLists.txt b/sdl2-vga-terminal/CMakeLists.txt index 237a36ed..aaf19f06 100644 --- a/sdl2-vga-terminal/CMakeLists.txt +++ b/sdl2-vga-terminal/CMakeLists.txt @@ -146,56 +146,70 @@ if (BUILD_SHARED_LIBS) endif() ######################## add compiler options ################################ -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") +if(CMAKE_CXX_COMPILER_ID MATCHES "^MSVC") # @see https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=vs-2019 - target_compile_options(vga-terminal-static PRIVATE /W4 /WX + target_compile_options(vga-terminal-static PRIVATE /W4 #/WX $<$:/Od /GR /GS /Gs /guard:cf /RTC1c /D_ALLOW_RTCc_IN_STL> $<$:/O2 /Ot /GA /GL /Gw> ) if (BUILD_SHARED_LIBS) - target_compile_options(vga-terminal PRIVATE /W4 /WX + target_compile_options(vga-terminal PRIVATE /W4 #/WX $<$:/Od /GR /GS /Gs /guard:cf /RTC1c /D_ALLOW_RTCc_IN_STL> $<$:/O2 /Ot /GA /GL /Gw> ) endif() -elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +elseif(CMAKE_CXX_COMPILER_ID MATCHES "^GNU") target_compile_options(vga-terminal-static PRIVATE -Wall -Wextra -pedantic -fPIC $<$: -O0;-D_GLIBCXX_DEBUG;-D_GLIBCXX_ASSERTIONS;-fexceptions; -W; -Wshadow; -Wunused-variable; -Wunused-parameter; -Wunused-function; -Wunused; -Wno-system-headers; - -Wno-deprecated; -Woverloaded-virtual; -Wwrite-strings; -fprofile-arcs; -ftest-coverage; + -Wno-deprecated; -Woverloaded-virtual; -Wwrite-strings; > #$<$:-O2;-fexceptions;-fstack-clash-protection;-D_FORTIFY_SOURCE=2> $<$:-O2;-fexceptions;-D_FORTIFY_SOURCE=2> ) #-Werror) - target_link_options(vga-terminal-static INTERFACE $<$:-fprofile-arcs; -ftest-coverage --coverage>;) - if (BUILD_SHARED_LIBS) - target_compile_options(vga-terminal PRIVATE - $<$: - -O0;-D_GLIBCXX_DEBUG;-D_GLIBCXX_ASSERTIONS;-fexceptions; - -W; -Wshadow; -Wunused-variable; - -Wunused-parameter; -Wunused-function; -Wunused; -Wno-system-headers; - -Wno-deprecated; -Woverloaded-virtual; -Wwrite-strings; -fprofile-arcs; -ftest-coverage; - > - $<$:-fexceptions;-D_FORTIFY_SOURCE=2> - ) #-Werror) - target_link_options(vga-terminal PRIVATE $<$:-fprofile-arcs; -ftest-coverage>;) + + if (ENABLE_CODE_COVERAGE) + target_compile_options(vga-terminal-static PRIVATE + $<$: -fprofile-arcs; -ftest-coverage;> + ) + target_link_options(vga-terminal-static PRIVATE $<$:-fprofile-arcs; -ftest-coverage; --coverage;>) endif() +elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang") + target_compile_options(vga-terminal-static PRIVATE -WCL4 -Wabstract-vbase-init -Wassign-enum + -Watomic-implicit-seq-cst -Watomic-properties -Wbad-function-cast -Wbinary-literal + ) -elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if (WIN32) + set(LINK_SUBSYS_WIN /subsystem:windows) + message(STATUS ${LINK_SUBSYS_WIN}) + target_link_options(vga-terminal-static PUBLIC ${LINK_SUBSYS_WIN}) + elseif(UNIX) + target_compile_options(vga-terminal-static PRIVATE -fPIC + $<$: -g;> + $<$:-O2;> + ) + + if(ENABLE_CODE_COVERAGE) + target_compile_options(vga-terminal-static PRIVATE + $<$:-c;-fprofile-arcs; -ftest-coverage;> + ) + target_link_options(vga-terminal-static PUBLIC $<$: -ftest-coverage;-fprofile-arcs; --coverage;>) + #target_link_options(vga-terminal-static PUBLIC $<$: -fprofile-instr-generate; -fcoverage-mapping;>) + endif() + else() + message(ERROR "Unknown OS") + endif() +else() + message(WARNING ${CMAKE_CXX_COMPILER_ID}) endif() -message("target compiler options:") +message("target interface compiler options:") get_target_property(vga-terminal-static_copts vga-terminal-static COMPILE_OPTIONS) message(STATUS "vga-terminal-static " ${vga-terminal-static_copts}) unset(vga-terminal-static_copts) -if (BUILD_SHARED_LIBS) - get_target_property(vga-terminal_copts vga-terminal COMPILE_OPTIONS) - message(STATUS "vga-terminal " ${vga-terminal_copts}) - unset(vga-terminal_copts) -endif() diff --git a/sdl2-vga-terminal/examples/CMakeLists.txt b/sdl2-vga-terminal/examples/CMakeLists.txt index 3280e5e0..a88846e0 100644 --- a/sdl2-vga-terminal/examples/CMakeLists.txt +++ b/sdl2-vga-terminal/examples/CMakeLists.txt @@ -3,13 +3,13 @@ cmake_minimum_required (VERSION 3.16) ############################## Main Example ################################## add_executable (${PROJECT_NAME} "sdl2-vga-terminal.cpp") add_dependencies(${PROJECT_NAME} vga-terminal-static) -target_link_libraries(${PROJECT_NAME} vga-terminal-static ${LIB_SDL2main}) +target_link_libraries(${PROJECT_NAME} ${LIB_SDL2main} vga-terminal-static) if (BUILD_SHARED_LIBS) ################## C example using SO/DLL with lazy loading ################## add_executable (${PROJECT_NAME}-so "sdl2-vga-terminal-so.c") add_dependencies(${PROJECT_NAME}-so vga-terminal) - target_link_libraries(${PROJECT_NAME}-so vga-terminal ${LIB_SDL2main}) + target_link_libraries(${PROJECT_NAME}-so ${LIB_SDL2main} vga-terminal) add_custom_command(TARGET "${PROJECT_NAME}-so" POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ ) @@ -24,7 +24,9 @@ if (BUILD_SHARED_LIBS) ################## C example using SO/DLL run-time loading ################## add_executable (${PROJECT_NAME}-load-so "sdl2-vga-terminal-load-so.c") - target_link_libraries(${PROJECT_NAME}-load-so PUBLIC ${LIB_SDL2} ${LIB_SDL2main} ${CMAKE_DL_LIBS}) + target_link_libraries(${PROJECT_NAME}-load-so PUBLIC ${LIB_SDL2main} ${LIB_SDL2} ${CMAKE_DL_LIBS}) + target_link_options(${PROJECT_NAME}-load-so PUBLIC ${LINK_SUBSYS_WIN}) + add_custom_command(TARGET "${PROJECT_NAME}-load-so" POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ ) diff --git a/sdl2-vga-terminal/src/VgaTerminal.cpp b/sdl2-vga-terminal/src/VgaTerminal.cpp index ca123798..429da21e 100644 --- a/sdl2-vga-terminal/src/VgaTerminal.cpp +++ b/sdl2-vga-terminal/src/VgaTerminal.cpp @@ -416,7 +416,7 @@ uint32_t VgaTerminal::_timerCallBack(uint32_t interval) interval = cursor_time; userevent.code = 0; - userevent.data1 = userevent.data2 = NULL; + userevent.data1 = userevent.data2 = nullptr; event.type = userevent.type = SDL_USEREVENT; event.user = userevent; userevent.windowID = event.window.windowID = getWindowId(); diff --git a/sdl2-vga-terminal/test/CMakeLists.txt b/sdl2-vga-terminal/test/CMakeLists.txt index f09ceb00..df6a9c17 100644 --- a/sdl2-vga-terminal/test/CMakeLists.txt +++ b/sdl2-vga-terminal/test/CMakeLists.txt @@ -10,7 +10,7 @@ else() ### VgaTerminal tests ### add_executable(runUnitTests "tests.cpp") add_test(UnitTestsInMain runUnitTests) - target_link_libraries(runUnitTests PRIVATE vga-terminal-static GTest::gtest GTest::gmock ${LIB_SDL2main}) + target_link_libraries(runUnitTests PRIVATE ${LIB_SDL2main} vga-terminal-static GTest::gtest GTest::gmock) add_custom_command(TARGET runUnitTests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ @@ -22,7 +22,7 @@ else() if (BUILD_SHARED_LIBS) add_executable(runSOTest "so-test.cpp") add_test(SOTest runSOTest) - target_link_libraries(runSOTest PRIVATE vga-terminal GTest::gtest ${LIB_SDL2main}) + target_link_libraries(runSOTest PRIVATE ${LIB_SDL2main} vga-terminal GTest::gtest) add_custom_command(TARGET runSOTest POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ @@ -36,7 +36,7 @@ if (BUILD_SNAPSHOT) find_package(SDL2-image CONFIG REQUIRED) add_executable(runSnapshotTests "snapshotTest.cpp") - target_link_libraries(runSnapshotTests PRIVATE vga-terminal-static GTest::gtest GTest::gmock SDL2::SDL2_image ${LIB_SDL2main}) + target_link_libraries(runSnapshotTests PRIVATE ${LIB_SDL2main} vga-terminal-static GTest::gtest GTest::gmock SDL2::SDL2_image) add_test(SnapshotTestsInMain runSnapshotTests) add_custom_command(TARGET runSnapshotTests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ @@ -49,7 +49,7 @@ endif() ### Valgrind tests ### if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") add_executable(runHelgrindTests "valgrind/helgrind.cpp") - target_link_libraries(runHelgrindTests PRIVATE vga-terminal-static ${LIB_SDL2main}) + target_link_libraries(runHelgrindTests PRIVATE ${LIB_SDL2main} vga-terminal-static) add_executable(runMultiThreadFuzzTests "valgrind/multithreading.cpp") - target_link_libraries(runMultiThreadFuzzTests PRIVATE vga-terminal-static ${LIB_SDL2main}) + target_link_libraries(runMultiThreadFuzzTests PRIVATE ${LIB_SDL2main} vga-terminal-static) endif() diff --git a/sonar-project.properties b/sonar-project.properties index 8e051305..c5cf681a 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,4 +6,5 @@ sonar.tests=sdl2-vga-terminal/test sonar.cfamily.build-wrapper-output=build/bw-output sonar.cfamily.threads=2 sonar.cfamily.cache.enabled=false -sonar.cfamily.gcov.reportsPath=build/sdl2-vga-terminal/CMakeFiles/vga-terminal-static.dir/src,build/sdl2-vga-terminal/CMakeFiles/vga-terminal.dir/src +sonar.cfamily.gcov.reportsPath=build +#sonar.cfamily.llvm-cov.reportPath=build