From adb8094108ff3e177335792c6f10fa4d2c718521 Mon Sep 17 00:00:00 2001 From: Stella Laurenzo Date: Sat, 4 Jul 2020 17:38:01 -0700 Subject: [PATCH] Fix some compiler option and warning levels. --- CMakeLists.txt | 11 ++++++++++- cmake/modules/NpcompIREEBackend.cmake | 8 ++++++++ cmake/modules/NpcompPython.cmake | 14 ++++++++++++++ lib/Backend/IREE/CMakeLists.txt | 11 ++++++----- lib/Python/CMakeLists.txt | 12 +++--------- python_native/CMakeLists.txt | 11 ++++------- 6 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 cmake/modules/NpcompIREEBackend.cmake create mode 100644 cmake/modules/NpcompPython.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 083cd1008..c0ad78778 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ endif() project(npcomp LANGUAGES CXX C) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 14) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") #------------------------------------------------------------------------------- # Options and settings @@ -65,6 +66,14 @@ set(NPCOMP_TABLEGEN_ARGS "") # IREE configuration #------------------------------------------------------------------------------- +function(npcomp_add_iree_src) + # TODO: Find a way to fix this upstream as globally demoting warnings + # like this is a really bad thing to be doing. Also, Abseil seems to try + # really hard to keep us from touching these so some still get through. + add_compile_options(-Wno-sign-compare -Wno-unused-template) + add_subdirectory("${NPCOMP_IREE_SRCDIR}" "iree" EXCLUDE_FROM_ALL) +endfunction() + if(NPCOMP_ENABLE_IREE) add_compile_definitions(NPCOMP_ENABLE_IREE) string(APPEND NPCOMP_TABLEGEN_ARGS "-DNPCOMP_ENABLE_IREE") @@ -74,7 +83,7 @@ if(NPCOMP_ENABLE_IREE) set(IREE_BUILD_SAMPLES OFF CACHE BOOL "Override IREE setting" FORCE) set(IREE_BUILD_PYTHON_BINDINGS ON CACHE BOOL "Override IREE setting" FORCE) set(IREE_MLIR_DEP_MODE "DISABLED" CACHE STRING "Override IREE setting") - add_subdirectory("${NPCOMP_IREE_SRCDIR}" "iree" EXCLUDE_FROM_ALL) + npcomp_add_iree_src() else() find_package(IREE REQUIRED CONFIG) endif() diff --git a/cmake/modules/NpcompIREEBackend.cmake b/cmake/modules/NpcompIREEBackend.cmake new file mode 100644 index 000000000..4224eabd9 --- /dev/null +++ b/cmake/modules/NpcompIREEBackend.cmake @@ -0,0 +1,8 @@ + function(npcomp_iree_target_compile_options target) + target_compile_options(${target} PRIVATE + $<$,$,$>: + -Wno-sign-compare + > + $<$:> + ) +endfunction() diff --git a/cmake/modules/NpcompPython.cmake b/cmake/modules/NpcompPython.cmake new file mode 100644 index 000000000..b3bee1f9d --- /dev/null +++ b/cmake/modules/NpcompPython.cmake @@ -0,0 +1,14 @@ +function(npcomp_python_target_compile_options target) + target_compile_options(${target} PRIVATE + $<$,$,$>: + # Enable RTTI and exceptions. + -frtti -fexceptions + # Noisy pybind warnings + -Wno-unused-value + -Wno-covered-switch-default + > + $<$: + # Enable RTTI and exceptions. + /EHsc /GR> + ) +endfunction() diff --git a/lib/Backend/IREE/CMakeLists.txt b/lib/Backend/IREE/CMakeLists.txt index c8c943728..0caeed724 100644 --- a/lib/Backend/IREE/CMakeLists.txt +++ b/lib/Backend/IREE/CMakeLists.txt @@ -2,14 +2,12 @@ # NPCOMPBackendIREEPythonModule ################################################################################ +include(NpcompPython) +include(NpcompIREEBackend) + set(PYBIND_SOURCES PythonModule.cpp ) -set_source_files_properties( - ${PYBIND_SOURCES} - PROPERTIES COMPILE_FLAGS - "-frtti -fexceptions") - add_library(NPCOMPBackendIREEPythonModule ${PYBIND_SOURCES} ) @@ -20,3 +18,6 @@ target_link_libraries(NPCOMPBackendIREEPythonModule iree_compiler_Dialect_HAL_Transforms_Transforms iree_compiler_Dialect_VM_Transforms_Transforms ) + +npcomp_python_target_compile_options(NPCOMPBackendIREEPythonModule) +npcomp_iree_target_compile_options(NPCOMPBackendIREEPythonModule) diff --git a/lib/Python/CMakeLists.txt b/lib/Python/CMakeLists.txt index 7e30cf3ea..4274d7b71 100644 --- a/lib/Python/CMakeLists.txt +++ b/lib/Python/CMakeLists.txt @@ -2,12 +2,7 @@ # NPCOMPPythonCommon ################################################################################ -if(MSVC) - # Exceptions and RTTI - set(extension_cflags "/EHsc /GR") -else() - set(extension_cflags "-frtti -fexceptions") -endif() +include(NpcompPython) set(PYBIND_SOURCES MlirInit.cpp @@ -17,9 +12,6 @@ set(PYBIND_SOURCES PybindUtils.cpp CoreDialects.cpp ) -set_source_files_properties( - ${PYBIND_SOURCES} - PROPERTIES COMPILE_FLAGS "${extension_cflags}") add_library(NPCOMPPythonCommon ${PYBIND_SOURCES} @@ -43,3 +35,5 @@ target_link_libraries(NPCOMPPythonCommon MLIRPass MLIRTransforms ) + +npcomp_python_target_compile_options(NPCOMPPythonCommon) diff --git a/python_native/CMakeLists.txt b/python_native/CMakeLists.txt index bb3ebdea4..fe4eba725 100644 --- a/python_native/CMakeLists.txt +++ b/python_native/CMakeLists.txt @@ -2,6 +2,8 @@ # Native extensions ################################################################################ +include(NpcompPython) + # Normally on unix-like platforms, extensions are built as "MODULE" libraries # and do not explicitly link to the python shared object. This allows for # come greater deployment flexibility since the extension will bind to @@ -15,13 +17,6 @@ set(NPCOMP_PYEXT_LINK_MODE SHARED) set(NPCOMP_PYEXT_LIBADD ${PYTHON_LIBRARIES}) -if(MSVC) - # Exceptions and RTTI - set(extension_cflags "/EHsc /GR") -else() - set(extension_cflags "-frtti -fexceptions") -endif() - if(NPCOMP_ENABLE_IREE) list(APPEND NPCOMP_PYEXT_LIBADD NPCOMPBackendIREEPythonModule) endif() @@ -92,3 +87,5 @@ target_link_libraries(${extension_target} ${NPCOMP_PYEXT_LIBADD} ) + +npcomp_python_target_compile_options(${extension_target})