ci: add clang code coverage check #10
					 2 changed files with 25 additions and 10 deletions
				
			
		| 
						 | 
					@ -1,23 +1,38 @@
 | 
				
			||||||
cmake_minimum_required(VERSION 3.14)
 | 
					cmake_minimum_required(VERSION 3.14)
 | 
				
			||||||
project(Light)
 | 
					project(Light)
 | 
				
			||||||
set(CMAKE_CXX_STANDARD 23)
 | 
					set(CMAKE_CXX_STANDARD 23)
 | 
				
			||||||
 | 
					set(CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include(${CMAKE_DIR}/functions.cmake)
 | 
				
			||||||
 | 
					include(${CMAKE_DIR}/definitions.cmake)
 | 
				
			||||||
 | 
					include(${CMAKE_DIR}/dependencies.cmake)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_option(ENABLE_TESTS "Enables the building of the test modules")
 | 
					add_option(ENABLE_TESTS "Enables the building of the test modules")
 | 
				
			||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/functions.cmake)
 | 
					 | 
				
			||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/definitions.cmake)
 | 
					 | 
				
			||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/dependencies.cmake)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_option(ENABLE_STATIC_ANALYSIS "Performs static analysis via clang-tidy and fails build on failing checks")
 | 
					add_option(ENABLE_STATIC_ANALYSIS "Makes clang-tidy checks mandatory for compilation")
 | 
				
			||||||
if (ENABLE_STATIC_ANALYSIS)
 | 
					if (ENABLE_STATIC_ANALYSIS)
 | 
				
			||||||
    set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--warnings-as-errors=*;--allow-no-checks")
 | 
					    set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--warnings-as-errors=*;--allow-no-checks")
 | 
				
			||||||
endif ()
 | 
					endif ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_option(ENABLE_LCOV "Enables the code coverage instrumentation for clang")
 | 
					add_option(ENABLE_LLVM_COVERAGE "Enables the code coverage instrumentation for clang")
 | 
				
			||||||
if(ENABLE_LCOV)
 | 
					if(ENABLE_LLVM_COVERAGE)
 | 
				
			||||||
    if (CMAKE_CXX_COMPILER_ID NOT STREQUAL "Clang")
 | 
					    if (CMAKE_CXX_COMPILER_ID NOT STREQUAL "Clang")
 | 
				
			||||||
        message(FATAL_ERROR "ENABLE_LCOV option is only supported when compiling with clang")
 | 
					        message(FATAL_ERROR "ENABLE_LLVM_COVERAGE only supports the clang compiler")
 | 
				
			||||||
    endif ()
 | 
					    endif ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Check for libc++
 | 
				
			||||||
 | 
					    check_cxx_source_compiles("
 | 
				
			||||||
 | 
					        #include <string>
 | 
				
			||||||
 | 
					        #ifdef _LIBCPP_VERSION
 | 
				
			||||||
 | 
					        int main() { return 0; }
 | 
				
			||||||
 | 
					        #else
 | 
				
			||||||
 | 
					        #error Not using libc++
 | 
				
			||||||
 | 
					        #endif
 | 
				
			||||||
 | 
					    " USING_LIBCXX)
 | 
				
			||||||
 | 
					    if(NOT USING_LIBCXX)
 | 
				
			||||||
 | 
					        message(FATAL_ERROR "ENABLE_LLVM_COVERAGE requires libc++, please compile with -stdlib=libc++")
 | 
				
			||||||
 | 
					    endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
 | 
					    add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
 | 
				
			||||||
    add_link_options(-fprofile-instr-generate -fcoverage-mapping)
 | 
					    add_link_options(-fprofile-instr-generate -fcoverage-mapping)
 | 
				
			||||||
endif ()
 | 
					endif ()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,7 +12,7 @@ class LightRecipe(ConanFile):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    options = {
 | 
					    options = {
 | 
				
			||||||
        "enable_tests": [True, False],
 | 
					        "enable_tests": [True, False],
 | 
				
			||||||
        "enable_lcov": [True, False],
 | 
					        "enable_llvm_coverage": [True, False],
 | 
				
			||||||
        "enable_static_analysis": [True, False],
 | 
					        "enable_static_analysis": [True, False],
 | 
				
			||||||
        "use_mold": [True, False],
 | 
					        "use_mold": [True, False],
 | 
				
			||||||
        "export_compile_commands": [True, False],
 | 
					        "export_compile_commands": [True, False],
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,7 @@ class LightRecipe(ConanFile):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    default_options = {
 | 
					    default_options = {
 | 
				
			||||||
        "enable_tests": True,
 | 
					        "enable_tests": True,
 | 
				
			||||||
        "enable_lcov": False,
 | 
					        "enable_llvm_coverage": False,
 | 
				
			||||||
        "enable_static_analysis": False,
 | 
					        "enable_static_analysis": False,
 | 
				
			||||||
        "use_mold": False,
 | 
					        "use_mold": False,
 | 
				
			||||||
        "export_compile_commands": True,
 | 
					        "export_compile_commands": True,
 | 
				
			||||||
| 
						 | 
					@ -47,7 +47,7 @@ class LightRecipe(ConanFile):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        tc.cache_variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = self.options.export_compile_commands
 | 
					        tc.cache_variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = self.options.export_compile_commands
 | 
				
			||||||
        tc.cache_variables["ENABLE_TESTS"] = self.options.enable_tests
 | 
					        tc.cache_variables["ENABLE_TESTS"] = self.options.enable_tests
 | 
				
			||||||
        tc.cache_variables["ENABLE_LCOV"] = self.options.enable_lcov
 | 
					        tc.cache_variables["ENABLE_LLVM_COVERAGE"] = self.options.enable_llvm_coverage
 | 
				
			||||||
        tc.cache_variables["ENABLE_STATIC_ANALYSIS"] = self.options.enable_static_analysis
 | 
					        tc.cache_variables["ENABLE_STATIC_ANALYSIS"] = self.options.enable_static_analysis
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        repo = git.Repo(search_parent_directories=True)
 | 
					        repo = git.Repo(search_parent_directories=True)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue