Skip to content

Commit

Permalink
#1602: use target_compile_options for enabling warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Nov 23, 2021
1 parent 7dd2246 commit 0c3584b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ cmake_policy(SET CMP0082 NEW)

get_directory_property(hasParent PARENT_DIRECTORY)

include(cmake/turn_on_warnings.cmake)

include(cmake/check_system_functions.cmake)

set(VIRTUAL_TRANSPORT_LIBRARY vt CACHE INTERNAL "" FORCE )
set(FCONTEXT_LIBRARY fcontext)

# Set the local module path so custom cmake scripts can be located automatically
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules/")
set(
CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules/"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
)

# Try to find ccache to speed up compilation
find_program(ccache_binary ccache)
Expand Down
35 changes: 17 additions & 18 deletions cmake/turn_on_warnings.cmake
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
include(CheckCXXCompilerFlag)

function(enable_cxx_compiler_flag_if_supported flag)
string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set)
if(flag_already_set EQUAL -1)
check_cxx_compiler_flag("${flag}" flag_supported)
if(flag_supported)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
endif()
unset(flag_supported CACHE)
check_cxx_compiler_flag("${flag}" flag_supported)
if(flag_supported)
target_compile_options(${vt_target} PUBLIC ${flag})
endif()
unset(flag_supported CACHE)
endfunction()

if(NOT hasParent)
enable_cxx_compiler_flag_if_supported("-Wall")
enable_cxx_compiler_flag_if_supported("-pedantic")
enable_cxx_compiler_flag_if_supported("-Wshadow")
enable_cxx_compiler_flag_if_supported("-Wno-unknown-pragmas")
enable_cxx_compiler_flag_if_supported("-Wsign-compare")
# Not really a warning, is still diagnostic related..
enable_cxx_compiler_flag_if_supported("-ftemplate-backtrace-limit=100")
function(turn_on_warnings vt_target)
if(NOT hasParent)
enable_cxx_compiler_flag_if_supported("-Wall")
enable_cxx_compiler_flag_if_supported("-pedantic")
enable_cxx_compiler_flag_if_supported("-Wshadow")
enable_cxx_compiler_flag_if_supported("-Wno-unknown-pragmas")
enable_cxx_compiler_flag_if_supported("-Wsign-compare")
# Not really a warning, is still diagnostic related..
enable_cxx_compiler_flag_if_supported("-ftemplate-backtrace-limit=100")

if (vt_werror_enabled) # Treat warning as errors
enable_cxx_compiler_flag_if_supported("-Werror")
if (vt_werror_enabled) # Treat warning as errors
enable_cxx_compiler_flag_if_supported("-Werror")
endif()
endif()
endif()
endfunction()
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ target_compile_features(
include(SetCXXCompilerFlags)
set_darma_compiler_flags(${VIRTUAL_TRANSPORT_LIBRARY})

include(turn_on_warnings)
turn_on_warnings(${VIRTUAL_TRANSPORT_LIBRARY})

if (vt_gold_linker_enabled)
if (UNIX AND NOT APPLE)
execute_process(
Expand Down

0 comments on commit 0c3584b

Please sign in to comment.