Skip to content

Commit

Permalink
fix(build): #21 target option WARNING not propagated properly
Browse files Browse the repository at this point in the history
By default, for every target we build, a compiler option will be added
to treat warnings as errors, unless the target is added with `WARNING` as
an option.

When that option is used, we now properly propagate it to set the
corresponding compiler option to **NOT** treat warnings as errors.

This is useful when 3rd party dependencies have include files that
generate warnings.
  • Loading branch information
abdes committed Sep 21, 2022
1 parent 304e9ae commit 432cdaf
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 56 deletions.
85 changes: 43 additions & 42 deletions cmake/AsapTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,32 @@ endfunction()
# Target creation helpers
# ------------------------------------------------------------------------------

macro(_add_common_compiler_options target warnings)
# Set some common compiler options, and forward the 'WARNING' option if it was
# provided
if(warnings)
asap_set_compile_options(${target} WARNING)
else()
asap_set_compile_options(${target})
endif()
endmacro()

function(asap_add_library target)
set(argOption "")
set(argSingle "CONTRACTS")
set(argMulti "")
unset(x_CONTRACTS)
set(argOption EXCEPTIONS RTTI WARNING)
set(argSingle CONTRACTS)
set(argMulti)

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

swift_add_library("${target}" ${x_UNPARSED_ARGUMENTS})
if(x_WARNING)
set(warning_flag "WARNING")
else()
set(warning_flag)
endif()

# Contrarily to swift default, we enable exceptions and RTTI for all targets
swift_add_library("${target}" EXCEPTIONS RTTI ${warning_flag}
${x_UNPARSED_ARGUMENTS})

# We can refer to this target either with its standalone target name or with a
# project scoped name (<project>::<module>) which we will alias to the target
Expand All @@ -127,8 +145,8 @@ function(asap_add_library target)
if(NOT ${type} STREQUAL "INTERFACE_LIBRARY")
# Set some common private compiler defines
asap_set_compile_definitions(${target} CONTRACTS ${x_CONTRACTS})
# Set some common compiler options
asap_set_compile_options(${target})
# Set common compiler options
asap_set_compile_options(${target} ${warning_flag})
# Generate export headers for the library
asap_generate_export_headers(${target} ${META_MODULE_NAME})

Expand All @@ -144,51 +162,34 @@ function(asap_add_library target)
endfunction()

function(asap_add_executable target)
set(argOption "")
set(argSingle "CONTRACTS")
set(argMulti "")
unset(x_CONTRACTS)
set(argOption EXCEPTIONS RTTI WARNING)
set(argSingle CONTRACTS)
set(argMulti)

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

swift_add_executable("${target}" ${x_UNPARSED_ARGUMENTS})
if(x_WARNING)
set(warning_flag "WARNING")
else()
set(warning_flag)
endif()

# Contrarily to swift default, we enable exceptions and RTTI for all targets
swift_add_executable("${target}" EXCEPTIONS RTTI ${warning_flag}
${x_UNPARSED_ARGUMENTS})
# Set some common private compiler defines
asap_set_compile_definitions(${target} CONTRACTS ${x_CONTRACTS})
# Set some common compiler options
asap_set_compile_options(${target})
# Set common compiler options
asap_set_compile_options(${target} ${warning_flag})
set_target_properties(${target} PROPERTIES FOLDER "Executables")
endfunction()

function(asap_add_tool target)
set(argOption "")
set(argSingle "CONTRACTS")
set(argMulti "")
unset(x_CONTRACTS)
cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

swift_add_tool("${target}" ${x_UNPARSED_ARGUMENTS})
# Set some common private compiler defines
asap_set_compile_definitions(${target} CONTRACTS ${x_CONTRACTS})
# Set some common compiler options
asap_set_compile_options(${target})
asap_add_executable(${target} ${ARGN})
set_target_properties(${target} PROPERTIES FOLDER "Tools")
endfunction()

function(asap_add_tool_library target)
set(argOption "")
set(argSingle "CONTRACTS")
set(argMulti "")
unset(x_CONTRACTS)
cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

swift_add_tool_library("${target}" ${x_UNPARSED_ARGUMENTS})
# Set some common private compiler defines
asap_set_compile_definitions(${target} CONTRACTS ${x_CONTRACTS})
# Set some common compiler options
asap_set_compile_options(${target})
set_target_properties(
${target}
PROPERTIES FOLDER "Tool Libraries"
VERSION ${META_MODULE_VERSION}
SOVERSION ${META_MODULE_VERSION_MAJOR}
DEBUG_POSTFIX "d")
asap_add_library(${target} ${ARGN})
set_target_properties(${target} PROPERTIES FOLDER "Tool Libraries")
endfunction()
12 changes: 8 additions & 4 deletions cmake/CompileOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# RTTI. By default, both are enabled.

function(asap_set_compile_options)
swift_set_compile_options(EXCEPTIONS RTTI ${ARGV})

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# using Clang
swift_set_compile_options(
Expand Down Expand Up @@ -46,13 +44,19 @@ function(asap_set_compile_options)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# using Visual Studio C++
set(argOption "WARNING" "NO_EXCEPTIONS" "EXCEPTIONS" "NO_RTTI" "RTTI")
set(argOption "WARNING")
set(argSingle "")
set(argMulti "ADD" "REMOVE" "EXTRA_FLAGS")
set(argMulti "")

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

set(targets ${x_UNPARSED_ARGUMENTS})

foreach(target ${targets})
target_compile_options(${target} PRIVATE /EHsc /MP /W4)
if(NOT x_WARNING)
target_compile_options(${target} PRIVATE /WX)
endif()
endforeach()
endif()

Expand Down
22 changes: 12 additions & 10 deletions cmake/TestTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
include(common/TestTargets)

macro(asap_add_test target)
set(argOption "")
set(argSingle "CONTRACTS")
set(argMulti "")
unset(x_CONTRACTS)
set(argOption)
set(argSingle CONTRACTS)
set(argMulti)

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

swift_add_test("${target}" ${x_UNPARSED_ARGUMENTS})
# Contrarily to swift default, we enable exceptions and RTTI for all targets
swift_add_test("${target}" ${warning_flag} ${x_UNPARSED_ARGUMENTS})
# Set some common private compiler defines
asap_set_compile_definitions(${target} CONTRACTS ${x_CONTRACTS})
# Set some common compiler options
# Set common compiler options
asap_set_compile_options(${target})
if(TARGET gtest AND BUILD_SHARED_LIBS)
target_compile_definitions(${target} PRIVATE GTEST_LINKED_AS_SHARED_LIBRARY)
Expand All @@ -37,12 +38,13 @@ macro(asap_add_test_runner target)
endmacro()

function(asap_add_test_library target)
set(argOption "")
set(argSingle "CONTRACTS")
set(argMulti "")
unset(x_CONTRACTS)
set(argOption)
set(argSingle CONTRACTS)
set(argMulti)

cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN})

# Contrarily to swift default, we enable exceptions and RTTI for all targets
swift_add_test_library("${target}" ${x_UNPARSED_ARGUMENTS})
# Set some common private compiler defines
asap_set_compile_definitions(${target} CONTRACTS ${x_CONTRACTS})
Expand Down

0 comments on commit 432cdaf

Please sign in to comment.