2017-09-25 12:47:47 +00:00
|
|
|
##============================================================================
|
|
|
|
## Copyright (c) Kitware, Inc.
|
|
|
|
## All rights reserved.
|
|
|
|
## See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
##
|
2017-09-25 12:47:47 +00:00
|
|
|
## This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
## PURPOSE. See the above copyright notice for more information.
|
|
|
|
##============================================================================
|
|
|
|
|
2019-05-14 12:12:44 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR
|
|
|
|
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
|
|
|
|
set(VTKM_COMPILER_IS_MSVC 1)
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "PGI")
|
2017-09-25 12:47:47 +00:00
|
|
|
set(VTKM_COMPILER_IS_PGI 1)
|
2019-05-14 12:12:44 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
2017-09-25 12:47:47 +00:00
|
|
|
set(VTKM_COMPILER_IS_ICC 1)
|
2019-05-14 12:12:44 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
|
|
|
set(VTKM_COMPILER_IS_CLANG 1)
|
|
|
|
set(VTKM_COMPILER_IS_APPLECLANG 1)
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
set(VTKM_COMPILER_IS_CLANG 1)
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
set(VTKM_COMPILER_IS_GNU 1)
|
2020-08-21 19:40:05 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "XLClang")
|
|
|
|
set(VTKM_COMPILER_IS_XL 1)
|
2017-09-25 12:47:47 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
2018-05-08 20:43:23 +00:00
|
|
|
# vtkm_compiler_flags is used by all the vtkm targets and consumers of VTK-m
|
|
|
|
# The flags on vtkm_compiler_flags are needed when using/building vtk-m
|
2017-09-25 12:47:47 +00:00
|
|
|
add_library(vtkm_compiler_flags INTERFACE)
|
2022-12-09 23:46:56 +00:00
|
|
|
set_target_properties(
|
|
|
|
vtkm_compiler_flags
|
|
|
|
PROPERTIES
|
|
|
|
EXPORT_NAME compiler_flags
|
|
|
|
)
|
2017-09-25 12:47:47 +00:00
|
|
|
|
2018-05-08 20:43:23 +00:00
|
|
|
# When building libraries/tests that are part of the VTK-m repository
|
2018-12-05 20:30:45 +00:00
|
|
|
# inherit the properties from vtkm_vectorization_flags.
|
2018-05-08 20:43:23 +00:00
|
|
|
# The flags are intended only for VTK-m itself and are not needed by consumers.
|
2018-12-05 20:30:45 +00:00
|
|
|
# We will export vtkm_vectorization_flags in general
|
2018-11-09 19:26:01 +00:00
|
|
|
# so consumer can either enable vectorization or use VTK-m's build flags if
|
|
|
|
# they so desire
|
2018-05-08 20:43:23 +00:00
|
|
|
target_link_libraries(vtkm_compiler_flags
|
2018-05-10 15:55:23 +00:00
|
|
|
INTERFACE $<BUILD_INTERFACE:vtkm_vectorization_flags>)
|
2018-05-08 20:43:23 +00:00
|
|
|
|
2021-04-12 17:29:46 +00:00
|
|
|
# setup that we need C++14 support
|
|
|
|
target_compile_features(vtkm_compiler_flags INTERFACE cxx_std_14)
|
2017-09-25 12:47:47 +00:00
|
|
|
|
2019-09-09 16:31:01 +00:00
|
|
|
# setup our static libraries so that a separate ELF section
|
|
|
|
# is generated for each function. This allows for the linker to
|
|
|
|
# remove unused sections. This allows for programs that use VTK-m
|
|
|
|
# to have the smallest binary impact as they can drop any VTK-m symbol
|
|
|
|
# they don't use.
|
|
|
|
if(VTKM_COMPILER_IS_MSVC)
|
2019-12-05 19:02:55 +00:00
|
|
|
target_compile_options(vtkm_compiler_flags INTERFACE $<$<COMPILE_LANGUAGE:CXX>:/Gy>)
|
2022-12-09 23:46:56 +00:00
|
|
|
if(TARGET vtkm_cuda)
|
2019-09-09 16:31:01 +00:00
|
|
|
target_compile_options(vtkm_compiler_flags INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler="/Gy">)
|
|
|
|
endif()
|
2020-08-21 19:40:05 +00:00
|
|
|
elseif(NOT (VTKM_COMPILER_IS_PGI OR VTKM_COMPILER_IS_XL)) #can't find an equivalant PGI/XL flag
|
2019-09-09 16:31:01 +00:00
|
|
|
target_compile_options(vtkm_compiler_flags INTERFACE $<$<COMPILE_LANGUAGE:CXX>:-ffunction-sections>)
|
2022-12-09 23:46:56 +00:00
|
|
|
if(TARGET vtkm_cuda)
|
2019-09-09 16:31:01 +00:00
|
|
|
target_compile_options(vtkm_compiler_flags INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=-ffunction-sections>)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-09-25 12:47:47 +00:00
|
|
|
# Enable large object support so we can have 2^32 addressable sections
|
2019-05-14 12:12:44 +00:00
|
|
|
if(VTKM_COMPILER_IS_MSVC)
|
2018-05-11 20:31:00 +00:00
|
|
|
target_compile_options(vtkm_compiler_flags INTERFACE $<$<COMPILE_LANGUAGE:CXX>:/bigobj>)
|
2022-12-09 23:46:56 +00:00
|
|
|
if(TARGET vtkm_cuda)
|
2018-05-11 20:31:00 +00:00
|
|
|
target_compile_options(vtkm_compiler_flags INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler="/bigobj">)
|
2018-04-12 12:35:16 +00:00
|
|
|
endif()
|
2017-09-25 12:47:47 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Setup the include directories that are needed for vtkm
|
|
|
|
target_include_directories(vtkm_compiler_flags INTERFACE
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
2018-01-16 20:38:43 +00:00
|
|
|
$<INSTALL_INTERFACE:${VTKm_INSTALL_INCLUDE_DIR}>
|
2017-09-25 12:47:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
2017-10-31 21:25:21 +00:00
|
|
|
# vtkm_developer_flags is used ONLY BY libraries that are built as part of this
|
2017-09-25 12:47:47 +00:00
|
|
|
# repository
|
2017-10-31 21:25:21 +00:00
|
|
|
add_library(vtkm_developer_flags INTERFACE)
|
2022-12-09 23:46:56 +00:00
|
|
|
set_target_properties(
|
|
|
|
vtkm_developer_flags
|
|
|
|
PROPERTIES
|
|
|
|
EXPORT_NAME developer_flags
|
|
|
|
)
|
2017-09-25 12:47:47 +00:00
|
|
|
|
2024-04-24 17:29:26 +00:00
|
|
|
# Intel OneAPI compilers >= 2021.2.0 turn on "fast math" at any non-zero
|
|
|
|
# optimization level. Suppress this non-standard behavior using the
|
|
|
|
# `-fp-model=precise` flag.
|
|
|
|
set(intel_oneapi_compiler_version_min "2021.2.0")
|
|
|
|
set(is_lang "$<COMPILE_LANGUAGE:CXX>")
|
|
|
|
set(is_intelllvm "$<CXX_COMPILER_ID:IntelLLVM>")
|
|
|
|
set(is_intelllvm_fastmath_assuming_version "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,${intel_oneapi_compiler_version_min}>")
|
|
|
|
set(intel_oneapi_compiler_detections
|
|
|
|
"$<AND:${is_lang},${is_intelllvm},${is_intelllvm_fastmath_assuming_version}>")
|
|
|
|
target_compile_options(vtkm_developer_flags
|
|
|
|
INTERFACE
|
|
|
|
"$<BUILD_INTERFACE:$<${intel_oneapi_compiler_detections}:-fp-model=precise>>")
|
|
|
|
|
2018-05-08 20:43:23 +00:00
|
|
|
# Additional warnings just for Clang 3.5+, and AppleClang 7+
|
|
|
|
# about failures to vectorize.
|
2019-05-14 12:12:44 +00:00
|
|
|
if (VTKM_COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.4)
|
2018-11-09 19:26:01 +00:00
|
|
|
target_compile_options(vtkm_developer_flags INTERFACE $<$<COMPILE_LANGUAGE:CXX>:-Wno-pass-failed>)
|
2019-05-14 12:12:44 +00:00
|
|
|
elseif(VTKM_COMPILER_IS_APPLECLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.99)
|
2018-11-09 19:26:01 +00:00
|
|
|
target_compile_options(vtkm_developer_flags INTERFACE $<$<COMPILE_LANGUAGE:CXX>:-Wno-pass-failed>)
|
2018-05-08 20:43:23 +00:00
|
|
|
endif()
|
|
|
|
|
2017-09-25 12:47:47 +00:00
|
|
|
if(VTKM_COMPILER_IS_MSVC)
|
2017-10-31 21:25:21 +00:00
|
|
|
target_compile_definitions(vtkm_developer_flags INTERFACE "_SCL_SECURE_NO_WARNINGS"
|
2018-01-04 18:15:34 +00:00
|
|
|
"_CRT_SECURE_NO_WARNINGS")
|
2017-09-25 12:47:47 +00:00
|
|
|
|
2019-08-20 14:36:53 +00:00
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
|
|
|
|
set(cxx_flags "-W3")
|
|
|
|
set(cuda_flags "-Xcompiler=-W3")
|
|
|
|
endif()
|
|
|
|
list(APPEND cxx_flags -wd4702 -wd4505)
|
|
|
|
list(APPEND cuda_flags "-Xcompiler=-wd4702,-wd4505")
|
|
|
|
|
2018-11-09 19:26:01 +00:00
|
|
|
#Setup MSVC warnings with CUDA and CXX
|
2019-08-20 14:36:53 +00:00
|
|
|
target_compile_options(vtkm_developer_flags INTERFACE $<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>)
|
2022-12-09 23:46:56 +00:00
|
|
|
if(TARGET vtkm_cuda)
|
2019-08-20 14:36:53 +00:00
|
|
|
target_compile_options(vtkm_developer_flags INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:${cuda_flags} -Xcudafe=--diag_suppress=1394,--diag_suppress=766>)
|
2018-11-09 19:26:01 +00:00
|
|
|
endif()
|
2017-09-25 12:47:47 +00:00
|
|
|
|
|
|
|
if(MSVC_VERSION LESS 1900)
|
2018-01-04 18:15:34 +00:00
|
|
|
# In VS2013 the C4127 warning has a bug in the implementation and
|
|
|
|
# generates false positive warnings for lots of template code
|
2018-11-09 19:26:01 +00:00
|
|
|
target_compile_options(vtkm_developer_flags INTERFACE $<$<COMPILE_LANGUAGE:CXX>:-wd4127>)
|
2022-12-09 23:46:56 +00:00
|
|
|
if(TARGET vtkm_cuda)
|
2018-11-09 19:26:01 +00:00
|
|
|
target_compile_options(vtkm_developer_flags INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=-wd4127>)
|
|
|
|
endif()
|
2017-09-25 12:47:47 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
elseif(VTKM_COMPILER_IS_ICC)
|
|
|
|
#Intel compiler offers header level suppression in the form of
|
|
|
|
# #pragma warning(disable : 1478), but for warning 1478 it seems to not
|
|
|
|
#work. Instead we add it as a definition
|
|
|
|
# Likewise to suppress failures about being unable to apply vectorization
|
|
|
|
# to loops, the #pragma warning(disable seems to not work so we add a
|
|
|
|
# a compile define.
|
2018-07-11 15:02:13 +00:00
|
|
|
target_compile_options(vtkm_developer_flags INTERFACE $<$<COMPILE_LANGUAGE:CXX>:-wd1478 -wd13379>)
|
2017-09-25 12:47:47 +00:00
|
|
|
|
|
|
|
elseif(VTKM_COMPILER_IS_GNU OR VTKM_COMPILER_IS_CLANG)
|
2020-09-23 18:03:16 +00:00
|
|
|
set(cxx_flags -Wall -Wcast-align -Wextra -Wpointer-arith -Wformat -Wformat-security -Wshadow -Wunused -fno-common -Wno-unused-function)
|
|
|
|
set(cuda_flags -Xcompiler=-Wall,-Wcast-align,-Wpointer-arith,-Wformat,-Wformat-security,-Wshadow,-fno-common,-Wunused,-Wno-unknown-pragmas,-Wno-unused-local-typedefs,-Wno-unused-function)
|
|
|
|
|
|
|
|
#Clang does not support the -Wchar-subscripts flag for warning if an array
|
|
|
|
#subscript has a char type.
|
|
|
|
if (VTKM_COMPILER_IS_GNU)
|
|
|
|
list(APPEND cxx_flags -Wchar-subscripts)
|
|
|
|
set(cuda_flags "${cuda_flags},-Wchar-subscripts")
|
|
|
|
endif()
|
2019-07-18 17:33:18 +00:00
|
|
|
|
|
|
|
#Only add float-conversion warnings for gcc as the integer warnigns in GCC
|
|
|
|
#include the implicit casting of all types smaller than int to ints.
|
2019-03-04 13:52:45 +00:00
|
|
|
if (VTKM_COMPILER_IS_GNU AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.99)
|
2019-03-01 20:25:48 +00:00
|
|
|
list(APPEND cxx_flags -Wfloat-conversion)
|
2019-03-05 21:21:15 +00:00
|
|
|
set(cuda_flags "${cuda_flags},-Wfloat-conversion")
|
2019-03-01 20:25:48 +00:00
|
|
|
elseif (VTKM_COMPILER_IS_CLANG)
|
|
|
|
list(APPEND cxx_flags -Wconversion)
|
2019-03-05 21:21:15 +00:00
|
|
|
set(cuda_flags "${cuda_flags},-Wconversion")
|
2019-03-01 20:25:48 +00:00
|
|
|
endif()
|
2018-05-08 21:37:33 +00:00
|
|
|
|
2019-07-18 17:33:18 +00:00
|
|
|
#Add in the -Wodr warning for GCC versions 5.2+
|
|
|
|
if (VTKM_COMPILER_IS_GNU AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.1)
|
|
|
|
list(APPEND cxx_flags -Wodr)
|
|
|
|
set(cuda_flags "${cuda_flags},-Wodr")
|
|
|
|
elseif (VTKM_COMPILER_IS_CLANG)
|
|
|
|
list(APPEND cxx_flags -Wodr)
|
|
|
|
set(cuda_flags "${cuda_flags},-Wodr")
|
|
|
|
endif()
|
|
|
|
|
2018-05-08 21:37:33 +00:00
|
|
|
#GCC 5, 6 don't properly handle strict-overflow suppression through pragma's.
|
|
|
|
#Instead of suppressing around the location of the strict-overflow you
|
|
|
|
#have to suppress around the entry point, or in vtk-m case the worklet
|
|
|
|
#invocation site. This is incredibly tedious and has been fixed in gcc 7
|
|
|
|
#
|
|
|
|
if(VTKM_COMPILER_IS_GNU AND
|
|
|
|
(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.99) AND
|
|
|
|
(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.99) )
|
|
|
|
list(APPEND cxx_flags -Wno-strict-overflow)
|
|
|
|
endif()
|
2019-07-18 17:33:18 +00:00
|
|
|
|
2018-11-09 19:26:01 +00:00
|
|
|
target_compile_options(vtkm_developer_flags INTERFACE $<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>)
|
2022-12-09 23:46:56 +00:00
|
|
|
if(TARGET vtkm_cuda)
|
2018-11-09 19:26:01 +00:00
|
|
|
target_compile_options(vtkm_developer_flags INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:${cuda_flags}>)
|
2018-04-12 12:35:16 +00:00
|
|
|
endif()
|
2017-09-25 12:47:47 +00:00
|
|
|
endif()
|
|
|
|
|
2020-06-16 12:54:01 +00:00
|
|
|
function(setup_cuda_flags)
|
2018-12-24 19:28:46 +00:00
|
|
|
set(display_error_nums -Xcudafe=--display_error_number)
|
2019-01-09 15:04:34 +00:00
|
|
|
target_compile_options(vtkm_developer_flags INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:${display_error_nums}>)
|
2020-06-16 12:54:01 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
#common warnings for all platforms when building cuda
|
2022-12-26 18:40:12 +00:00
|
|
|
if ((TARGET vtkm_cuda) OR (TARGET vtkm_kokkos_cuda))
|
2020-06-16 12:54:01 +00:00
|
|
|
setup_cuda_flags()
|
2018-12-24 19:28:46 +00:00
|
|
|
endif()
|
|
|
|
|
2018-01-02 16:06:40 +00:00
|
|
|
if(NOT VTKm_INSTALL_ONLY_LIBRARIES)
|
2022-12-09 23:46:56 +00:00
|
|
|
vtkm_install_targets(TARGETS vtkm_compiler_flags vtkm_developer_flags)
|
2018-01-02 16:06:40 +00:00
|
|
|
endif()
|