target_compile_options as list
@@ -28,6 +28,8 @@ set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain.cmake"
CACHE FILEPATH
"Toolchain to use for building this project")
+option(ENABLE_COVERAGE "Enable compiling tests with coverage." ON)
+
if(WIN32)
set(SHELL PowerShell -Command)
@@ -47,24 +49,27 @@ set(H3_SOVERSION 1)
project(h3 VERSION ${H3_VERSION})
-set(H3_FLAGS "")
+set(H3_COMPILE_FLAGS "")
+set(H3_LINK_FLAGS "")
if(NOT WIN32)
# Compiler options are set only on non-Windows, since these options
# are not correct for MSVC.
- string(CONCAT H3_FLAGS ${H3_FLAGS} "-Wall ")
+ list(APPEND H3_COMPILE_FLAGS -Wall)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
- string(CONCAT H3_FLAGS
- ${H3_FLAGS}
- "-g -gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types ")
+ list(APPEND H3_COMPILE_FLAGS
+ -g -gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types)
if(ENABLE_COVERAGE)
- string(CONCAT H3_FLAGS ${H3_FLAGS} "--coverage ")
+ list(APPEND H3_COMPILE_FLAGS --coverage)
+ # --coverage is not passed to the linker, so this option is needed
+ # to fully enable coverage.
+ list(APPEND H3_LINK_FLAGS -fprofile-arcs)
endif()
endif()
option(WARNINGS_AS_ERRORS "Warnings are treated as errors" ON)
if(WARNINGS_AS_ERRORS)
- string(CONCAT H3_FLAGS ${H3_FLAGS} "-Werror ")
+ list(APPEND H3_COMPILE_FLAGS -Werror)
endif()
endif()
@@ -168,7 +173,8 @@ set(ALL_SOURCE_FILES
# Build the H3 library
add_library(h3 ${LIB_SOURCE_FILES})
-target_compile_options(h3 PRIVATE ${H3_FLAGS})
+target_compile_options(h3 PRIVATE ${H3_COMPILE_FLAGS})
+target_link_libraries(h3 PUBLIC ${H3_LINK_FLAGS})
find_library(M_LIB m)
if(M_LIB)
@@ -266,7 +272,7 @@ macro(add_h3_executable name)
target_link_libraries(${name} PUBLIC h3)
target_include_directories(${name} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/apps/applib/include>)
- target_compile_options(${name} PRIVATE ${H3_FLAGS})
+ target_compile_options(${name} PRIVATE ${H3_COMPILE_FLAGS})
endif()
endmacro()
@@ -315,7 +321,6 @@ if(BUILD_TESTING)
# Macros and support code needed to build and add the tests
set(test_number 0)
- option(ENABLE_COVERAGE "Enable compiling tests with coverage." ON)
if(ENABLE_COVERAGE)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "coverage.info")
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "coverage.cleaned.info")
