44# This source code is licensed under the BSD-style license found in the
55# LICENSE file in the root directory of this source tree.
66
7+ include (${CMAKE_CURRENT_LIST_DIR} /CppLibrary.cmake )
8+
79function (prepare_target_sources )
810 # This function does the following:
911 #
@@ -35,21 +37,14 @@ function(prepare_target_sources)
3537 ############################################################################
3638
3739 # Add the CPU CXX sources
38- LIST_FILTER (
39- INPUT ${args_CPU_SRCS}
40- OUTPUT cpu_sources_cpp
41- REGEX "^.+\. cpp$"
42- )
43- set (${args_PREFIX} _sources_cpp ${cpu_sources_cpp} )
40+ set (${args_PREFIX} _sources_cpp ${args_CPU_SRCS} )
41+ list (FILTER ${args_PREFIX} _sources_cpp INCLUDE REGEX "^.+\. cpp$" )
4442
4543 # For GPU mode, add the CXX sources from GPU_SRCS
4644 if (NOT FBGEMM_BUILD_VARIANT STREQUAL BUILD_VARIANT_CPU)
47- LIST_FILTER (
48- INPUT ${args_GPU_SRCS}
49- OUTPUT gpu_sources_cpp
50- REGEX "^.+\. cpp$"
51- )
52- list (APPEND ${args_PREFIX} _sources_cpp ${gpu_sources_cpp} )
45+ set (_gpu_sources_cpp ${args_GPU_SRCS} )
46+ list (FILTER _gpu_sources_cpp INCLUDE REGEX "^.+\. cpp$" )
47+ list (APPEND ${args_PREFIX} _sources_cpp ${_gpu_sources_cpp} )
5348 endif ()
5449
5550 # Set source properties
@@ -60,7 +55,7 @@ function(prepare_target_sources)
6055 if (CXX_AVX2_FOUND)
6156 set_source_files_properties (${${args_PREFIX}_sources_cpp}
6257 PROPERTIES COMPILE_OPTIONS
63- "${AVX2_FLAGS } " )
58+ "${CXX_AVX2_FLAGS } " )
6459 else ()
6560 set_source_files_properties (${${args_PREFIX}_sources_cpp}
6661 PROPERTIES COMPILE_OPTIONS
@@ -76,11 +71,8 @@ function(prepare_target_sources)
7671
7772 if (NOT FBGEMM_BUILD_VARIANT STREQUAL BUILD_VARIANT_CPU)
7873 # Filter GPU_SRCS for CU sources - these may be HIPified later if building in ROCm mode
79- LIST_FILTER (
80- INPUT ${args_GPU_SRCS}
81- OUTPUT ${args_PREFIX} _sources_cu
82- REGEX "^.+\. cu$"
83- )
74+ set (${args_PREFIX} _sources_cu ${args_GPU_SRCS} )
75+ list (FILTER ${args_PREFIX} _sources_cu INCLUDE REGEX "^.+\. cu$" )
8476
8577 # Append CUDA-specific sources, but ONLY when building in CUDA mode
8678 if (NOT FBGEMM_BUILD_VARIANT STREQUAL BUILD_VARIANT_ROCM)
@@ -126,11 +118,8 @@ function(prepare_target_sources)
126118
127119 if (FBGEMM_BUILD_VARIANT STREQUAL BUILD_VARIANT_ROCM)
128120 # Filter GPU_SRCS for HIP sources
129- LIST_FILTER (
130- INPUT ${args_GPU_SRCS}
131- OUTPUT ${args_PREFIX} _sources_hip
132- REGEX "^.+\. hip$"
133- )
121+ set (${args_PREFIX} _sources_hip ${args_GPU_SRCS} )
122+ list (FILTER ${args_PREFIX} _sources_hip INCLUDE REGEX "^.+\. hip$" )
134123
135124 # Append HIP-specific sources, but ONLY when building in HIP mode
136125 list (APPEND ${args_PREFIX} _sources_hip ${args_HIP_SPECIFIC_SRCS} )
@@ -281,59 +270,20 @@ function(gpu_cpp_library)
281270 PUBLIC FBGEMM_STATIC )
282271 endif ()
283272
284- set (lib_cc_flags
285- ${args_MSVC_FLAGS}
286- /wd4244
287- /wd4267
288- /wd4305
289- /wd4309 )
273+ fbgemm_get_warning_flags (
274+ MSVC_FLAGS_VAR _msvc_flags
275+ CC_FLAGS_VAR _cc_flags
276+ EXTRA_MSVC_FLAGS ${args_MSVC_FLAGS}
277+ EXTRA_CC_FLAGS ${args_CC_FLAGS} )
278+ set (lib_cc_flags ${_msvc_flags} )
290279
291280 else ()
292- set (lib_cc_flags
293- ${args_CC_FLAGS}
294- -Wall
295- -Wextra
296- -Werror
297- -Wunknown-pragmas
298- -Wimplicit-fallthrough
299- -Wno-deprecated-enum-enum-conversion
300- -Wno-deprecated-declarations
301- -Wno-strict-aliasing
302- -Wunused-variable
303- -Wno-sign-compare
304- -Wno-vla
305- -Wno-error=unused-parameter
306- -Wno-error=unknown-pragmas
307- -Wno-error=attributes)
308-
309- if (CMAKE_CXX_COMPILER_ID MATCHES Clang)
310- list (APPEND lib_cc_flags
311- -Wno-unused-command-line-argument
312- -Wno-c99-extensions
313- -Wno-gnu-zero-variadic-macro-arguments
314- -Wno-deprecated-enum-enum-conversion)
315-
316- if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 13.0.0)
317- list (APPEND lib_cc_flags
318- -Wno-error=unused-but-set-parameter
319- -Wno-error=unused-but-set-variable)
320- endif ()
321-
322- if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 17.0.0)
323- list (APPEND lib_cc_flags
324- -Wno-vla-cxx-extension
325- -Wno-error=global-constructors
326- -Wno-error=shadow)
327- endif ()
328-
329- elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
330- list (APPEND lib_cc_flags
331- -Wmaybe-uninitialized
332- -Wno-error=unused-but-set-parameter
333- -Wno-error=unused-but-set-variable
334- -Wno-error=array-bounds
335- -Wno-deprecated-enum-enum-conversion)
336- endif ()
281+ fbgemm_get_warning_flags (
282+ MSVC_FLAGS_VAR _msvc_flags
283+ CC_FLAGS_VAR _cc_flags
284+ EXTRA_MSVC_FLAGS ${args_MSVC_FLAGS}
285+ EXTRA_CC_FLAGS ${args_CC_FLAGS} )
286+ set (lib_cc_flags ${_cc_flags} )
337287 endif ()
338288
339289
0 commit comments