build: add enable_lcov compiler option
This commit is contained in:
		
							parent
							
								
									6dd489eed9
								
							
						
					
					
						commit
						9d31a5eb1a
					
				
					 2 changed files with 15 additions and 2 deletions
				
			
		| 
						 | 
					@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.14)
 | 
				
			||||||
project(Light)
 | 
					project(Light)
 | 
				
			||||||
set(CMAKE_CXX_STANDARD 23)
 | 
					set(CMAKE_CXX_STANDARD 23)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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/functions.cmake)
 | 
				
			||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/definitions.cmake)
 | 
					include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/definitions.cmake)
 | 
				
			||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/dependencies.cmake)
 | 
					include(${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/dependencies.cmake)
 | 
				
			||||||
| 
						 | 
					@ -11,6 +12,15 @@ 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_TESTS "Enables the building of the test modules")
 | 
					add_option(ENABLE_LCOV "Enables the code coverage instrumentation for clang")
 | 
				
			||||||
 | 
					if(ENABLE_LCOV)
 | 
				
			||||||
 | 
					    if (CMAKE_CXX_COMPILER_ID NOT STREQUAL "Clang")
 | 
				
			||||||
 | 
					        message(FATAL_ERROR "ENABLE_LCOV option is only supported when compiling with clang")
 | 
				
			||||||
 | 
					    endif ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
 | 
				
			||||||
 | 
					    add_link_options(-fprofile-instr-generate -fcoverage-mapping)
 | 
				
			||||||
 | 
					endif ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules)
 | 
					add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules)
 | 
				
			||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/glad)
 | 
					add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/glad)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,7 @@ class LightRecipe(ConanFile):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    options = {
 | 
					    options = {
 | 
				
			||||||
        "enable_tests": [True, False],
 | 
					        "enable_tests": [True, False],
 | 
				
			||||||
 | 
					        "enable_lcov": [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],
 | 
				
			||||||
| 
						 | 
					@ -19,6 +20,7 @@ class LightRecipe(ConanFile):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    default_options = {
 | 
					    default_options = {
 | 
				
			||||||
        "enable_tests": True,
 | 
					        "enable_tests": True,
 | 
				
			||||||
 | 
					        "enable_lcov": False,
 | 
				
			||||||
        "enable_static_analysis": False,
 | 
					        "enable_static_analysis": False,
 | 
				
			||||||
        "use_mold": False,
 | 
					        "use_mold": False,
 | 
				
			||||||
        "export_compile_commands": True,
 | 
					        "export_compile_commands": True,
 | 
				
			||||||
| 
						 | 
					@ -44,8 +46,9 @@ class LightRecipe(ConanFile):
 | 
				
			||||||
            tc.cache_variables["CMAKE_LINKER_TYPE"] = "MOLD"
 | 
					            tc.cache_variables["CMAKE_LINKER_TYPE"] = "MOLD"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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_STATIC_ANALYSIS"] = self.options.enable_static_analysis
 | 
					 | 
				
			||||||
        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_STATIC_ANALYSIS"] = self.options.enable_static_analysis
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        repo = git.Repo(search_parent_directories=True)
 | 
					        repo = git.Repo(search_parent_directories=True)
 | 
				
			||||||
        tc.cache_variables["GIT_HASH"] = repo.head.object.hexsha
 | 
					        tc.cache_variables["GIT_HASH"] = repo.head.object.hexsha
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue