Skip to content

Commit

Permalink
Enhance warnings as error flag to be language specific
Browse files Browse the repository at this point in the history
We start off by replacing `OMR_WARNING_AS_ERROR_FLAG` with a definition
per language, i.e. `OMR_<LANG>_WARNINGS_AS_ERROR_FLAG`. This lets us
define custom flags per compiler toolchain. More specifically for cross
compilations, ex. Cygwin, we can supply a custom flag for NASM file
compilations correctly.

We will add subsequent flags for other languages in new commits.
  • Loading branch information
fjeremic committed Jun 15, 2021
1 parent 04c2abf commit 1a5a46e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
16 changes: 8 additions & 8 deletions cmake/modules/OmrTargetSupport.cmake
Expand Up @@ -77,16 +77,16 @@ function(omr_add_library name)
if(OMR_WARNINGS_AS_ERRORS)
target_compile_options(${name}
PRIVATE
$<$<COMPILE_LANGUAGE:C>:${OMR_WARNING_AS_ERROR_FLAG}>
$<$<COMPILE_LANGUAGE:CXX>:${OMR_WARNING_AS_ERROR_FLAG}>
$<$<COMPILE_LANGUAGE:C>:${OMR_C_WARNINGS_AS_ERROR_FLAG}>
$<$<COMPILE_LANGUAGE:CXX>:${OMR_CXX_WARNINGS_AS_ERROR_FLAG}>
)
endif()

if(OMR_ENHANCED_WARNINGS)
target_compile_options(${name}
PRIVATE
$<$<COMPILE_LANGUAGE:C>:${OMR_ENHANCED_WARNING_FLAG}>
$<$<COMPILE_LANGUAGE:CXX>:${OMR_ENHANCED_WARNING_FLAG}>
$<$<COMPILE_LANGUAGE:C>:${OMR_C_ENHANCED_WARNINGS_FLAG}>
$<$<COMPILE_LANGUAGE:CXX>:${OMR_CXX_ENHANCED_WARNINGS_FLAG}>
)
else()
target_compile_options(${name}
Expand Down Expand Up @@ -123,16 +123,16 @@ function(omr_add_executable name)
if(OMR_WARNINGS_AS_ERRORS)
target_compile_options(${name}
PRIVATE
$<$<COMPILE_LANGUAGE:C>:${OMR_WARNING_AS_ERROR_FLAG}>
$<$<COMPILE_LANGUAGE:CXX>:${OMR_WARNING_AS_ERROR_FLAG}>
$<$<COMPILE_LANGUAGE:C>:${OMR_C_WARNINGS_AS_ERROR_FLAG}>
$<$<COMPILE_LANGUAGE:CXX>:${OMR_CXX_WARNINGS_AS_ERROR_FLAG}>
)
endif()

if(OMR_ENHANCED_WARNINGS)
target_compile_options(${name}
PRIVATE
$<$<COMPILE_LANGUAGE:C>:${OMR_ENHANCED_WARNING_FLAG}>
$<$<COMPILE_LANGUAGE:CXX>:${OMR_ENHANCED_WARNING_FLAG}>
$<$<COMPILE_LANGUAGE:C>:${OMR_C_ENHANCED_WARNINGS_FLAG}>
$<$<COMPILE_LANGUAGE:CXX>:${OMR_CXX_ENHANCED_WARNINGS_FLAG}>
)
else()
target_compile_options(${name}
Expand Down
6 changes: 4 additions & 2 deletions cmake/modules/platform/toolcfg/gnu.cmake
Expand Up @@ -19,9 +19,11 @@
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
#############################################################################

set(OMR_WARNING_AS_ERROR_FLAG -Werror)
set(OMR_C_WARNINGS_AS_ERROR_FLAG -Werror)
set(OMR_CXX_WARNINGS_AS_ERROR_FLAG -Werror)

set(OMR_ENHANCED_WARNING_FLAG -Wall)
set(OMR_C_ENHANCED_WARNINGS_FLAG -Wall)
set(OMR_CXX_ENHANCED_WARNINGS_FLAG -Wall)

# disable builtin strncpy buffer length check for components that use variable length
# array fields at the end of structs
Expand Down
6 changes: 4 additions & 2 deletions cmake/modules/platform/toolcfg/msvc.cmake
Expand Up @@ -21,9 +21,11 @@

include(OmrUtility)

set(OMR_WARNING_AS_ERROR_FLAG /WX)
set(OMR_C_WARNINGS_AS_ERROR_FLAG /WX)
set(OMR_CXX_WARNINGS_AS_ERROR_FLAG /WX)

set(OMR_ENHANCED_WARNING_FLAG /W3)
set(OMR_C_ENHANCED_WARNINGS_FLAG /W3)
set(OMR_CXX_ENHANCED_WARNINGS_FLAG /W3)

list(APPEND OMR_PLATFORM_COMPILE_OPTIONS
/GR- # Disable RTTI
Expand Down
3 changes: 2 additions & 1 deletion cmake/modules/platform/toolcfg/verify.cmake
Expand Up @@ -19,5 +19,6 @@
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
#############################################################################

omr_assert(WARNING TEST DEFINED OMR_WARNING_AS_ERROR_FLAG)
omr_assert(WARNING TEST DEFINED OMR_C_WARNINGS_AS_ERROR_FLAG)
omr_assert(WARNING TEST DEFINED OMR_CXX_WARNINGS_AS_ERROR_FLAG)
omr_assert(FATAL_ERROR TEST DEFINED OMR_PLATFORM_THREAD_LIBRARY)
12 changes: 8 additions & 4 deletions cmake/modules/platform/toolcfg/xlc.cmake
Expand Up @@ -31,10 +31,12 @@ if(CMAKE_C_COMPILER_IS_XLCLANG)
endif()

if(OMR_HOST_ARCH STREQUAL "ppc")
set(OMR_WARNING_AS_ERROR_FLAG -qhalt=w)
set(OMR_C_WARNINGS_AS_ERROR_FLAG -qhalt=w)
set(OMR_CXX_WARNINGS_AS_ERROR_FLAG -qhalt=w)

# There is no enhanced warning for XLC right now
set(OMR_ENHANCED_WARNING_FLAG )
set(OMR_C_ENHANCED_WARNINGS_FLAG )
set(OMR_CXX_ENHANCED_WARNINGS_FLAG )

list(APPEND OMR_PLATFORM_COMPILE_OPTIONS
-qalias=noansi
Expand Down Expand Up @@ -119,10 +121,12 @@ elseif(OMR_OS_ZOS)
# TODO: This should technically be -qhalt=w however c89 compiler used to compile the C sources does not like this
# flag. We'll need to investigate whether we actually need c89 for C sources or if we can use xlc and what to do
# with this flag. For now I'm leaving it as empty.
set(OMR_WARNING_AS_ERROR_FLAG )
set(OMR_C_WARNINGS_AS_ERROR_FLAG )
set(OMR_CXX_WARNINGS_AS_ERROR_FLAG )

# There is no enhanced warning for XLC right now
set(OMR_ENHANCED_WARNING_FLAG )
set(OMR_C_ENHANCED_WARNINGS_FLAG )
set(OMR_CXX_ENHANCED_WARNINGS_FLAG )

list(APPEND OMR_PLATFORM_COMPILE_OPTIONS
"\"-Wc,xplink\"" # link with xplink calling convention
Expand Down

0 comments on commit 1a5a46e

Please sign in to comment.