Skip to content

Commit 3c8fd23

Browse files
committed
Use target_compile_options instead of CMAKE_CXX_FLAGS
1 parent 4544ca0 commit 3c8fd23

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

CMakeLists.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,6 @@ endforeach()
214214
# none needed - please use AMReX_Config.H
215215

216216

217-
# Warnings ####################################################################
218-
#
219-
set_cxx_warnings()
220-
221-
222217
# Generate Configuration and .pc Files ########################################
223218
#
224219
# these files are used if pyAMReX is installed and picked up by a downstream
@@ -361,6 +356,14 @@ if(pyAMReX_BUILD_TESTING)
361356
endif()
362357

363358

359+
# Warnings ####################################################################
360+
#
361+
# FIXME _ALL_TARGETS is not defined
362+
foreach(pyamrex_tgt IN LISTS _ALL_TARGETS)
363+
pyamrex_set_compile_warnings(${pyamrex_tgt})
364+
endforeach()
365+
366+
364367
# Status Summary for Build Options ############################################
365368
#
366369
pyAMReX_print_summary()

cmake/pyAMReXFunctions.cmake

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,41 +186,36 @@ macro(set_testing_option project_build_var)
186186
${${project_build_var}_DEFAULT})
187187
endmacro()
188188

189-
# Set CXX
190-
# Note: this is a bit legacy and one should use CMake TOOLCHAINS instead.
189+
# Set compile warnings
191190
#
192-
macro(set_cxx_warnings)
191+
function(pyamrex_set_compile_warnings tgt)
193192
# On Windows, Clang -Wall aliases -Weverything; default is /W3
194193
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT WIN32)
195194
# list(APPEND CMAKE_CXX_FLAGS "-fsanitize=address") # address, memory, undefined
196195
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
197196
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
198197
# set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address")
199-
200198
# note: might still need a
201199
# export LD_PRELOAD=libclang_rt.asan.so
202200
# or on Debian 9 with Clang 6.0
203201
# export LD_PRELOAD=/usr/lib/llvm-6.0/lib/clang/6.0.0/lib/linux/libclang_rt.asan-x86_64.so:
204202
# /usr/lib/llvm-6.0/lib/clang/6.0.0/lib/linux/libclang_rt.ubsan_minimal-x86_64.so
205203
# at runtime when used with symbol-hidden code (e.g. pybind11 module)
206-
207-
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything")
208-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code")
204+
target_compile_options(${tgt} PRIVATE -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code)
209205
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
210-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code")
206+
target_compile_options(${tgt} PRIVATE -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code)
211207
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
212-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wunreachable-code")
208+
target_compile_options(${tgt} PRIVATE -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wunreachable-code)
213209
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
214210
# Warning C4503: "decorated name length exceeded, name was truncated"
215211
# Symbols longer than 4096 chars are truncated (and hashed instead)
216-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4503")
217212
# Yes, you should build against the same C++ runtime and with same
218213
# configuration (Debug/Release). MSVC does inconvenient choices for their
219214
# developers, so be it. (Our Windows-users use conda-forge builds, which
220215
# are consistent.)
221-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4251")
216+
target_compile_options(${tgt} PRIVATE /wd4503 /wd4251)
222217
endif ()
223-
endmacro()
218+
endfunction()
224219

225220

226221
# Enables interprocedural optimization for a list of targets

0 commit comments

Comments
 (0)