Skip to content

Commit

Permalink
Add support for M4 CXX flag detection in CMakeLists
Browse files Browse the repository at this point in the history
Enables all flags that are detected by M4 builds to be detected by CMake builds
as well (except for -Wall which enables a bunch of junk).

(cherry picked from commit 2ea8a97)
  • Loading branch information
qris committed Jul 23, 2017
1 parent db79ca4 commit 04ece62
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
18 changes: 17 additions & 1 deletion infrastructure/cmake/CMakeLists.txt
Expand Up @@ -480,7 +480,7 @@ move_file_if_exists(
"${boxconfig_cmake_h_dir}/BoxConfig.cmake.h.bak")

foreach(m4_filename boxbackup_tests.m4 ax_check_mount_point.m4 ax_func_syscall.m4)
file(STRINGS "${base_dir}/infrastructure/m4/${m4_filename}" m4_functions REGEX "^ *AC[_A-Z]+\\(.*\\)$")
file(STRINGS "${base_dir}/infrastructure/m4/${m4_filename}" m4_functions REGEX "^ *(AC|AX|BOX)_[A-Z_]+\\(.*\\)$")
foreach(m4_function ${m4_functions})
if(DEBUG)
message(STATUS "Processing m4_function: ${m4_function}")
Expand Down Expand Up @@ -562,6 +562,22 @@ foreach(m4_filename boxbackup_tests.m4 ax_check_mount_point.m4 ax_func_syscall.m
}
]=] "HAVE_${platform_var_name}")
file(APPEND "${boxconfig_h_file}" "#cmakedefine HAVE_${platform_var_name}\n")
elseif(m4_function MATCHES "^ *BOX_CHECK_CXX_FLAG\\((-[A-Za-z_,=-]+)\\)")
if(DEBUG)
message(STATUS "Processing BOX_CHECK_CXX_FLAG: ${CMAKE_MATCH_1}")
endif()

if(NOT CMAKE_MATCH_1 STREQUAL "-Wall")
set(flag "${CMAKE_MATCH_1}")
string(TOLOWER "have_flag_${flag}" have_flag_var_name)
string(REGEX REPLACE "[^a-z_]" "_" have_flag_var_name ${have_flag_var_name})
string(REGEX REPLACE "__+" "_" have_flag_var_name ${have_flag_var_name})

CHECK_CXX_COMPILER_FLAG(${flag} ${have_flag_var_name})
if(${have_flag_var_name})
add_definitions("${flag}")
endif()
endif()
endif()
endforeach()

Expand Down
32 changes: 21 additions & 11 deletions infrastructure/m4/boxbackup_tests.m4
Expand Up @@ -10,17 +10,27 @@ solaris*)
;;
esac

# Use -Wall if the compiler supports it. This gives better warnings.
AX_CHECK_COMPILE_FLAG(-Wall, [cxxflags_strict="$cxxflags_strict -Wall"])
AX_CHECK_COMPILE_FLAG(-Wundef, [cxxflags_strict="$cxxflags_strict -Wundef"])
AX_CHECK_COMPILE_FLAG(-Werror=return-type,
[cxxflags_strict="$cxxflags_strict -Werror=return-type"])
AX_CHECK_COMPILE_FLAG(-Werror=non-virtual-dtor,
[cxxflags_strict="$cxxflags_strict -Werror=non-virtual-dtor"])
AX_CHECK_COMPILE_FLAG(-Werror=delete-non-virtual-dtor,
[cxxflags_strict="$cxxflags_strict -Werror=delete-non-virtual-dtor"])
AX_CHECK_COMPILE_FLAG(-Werror=narrowing,
[cxxflags_strict="$cxxflags_strict -Werror=narrowing"])
# If the compiler supports it, force errors on unknown flags, so that detection works:
AX_CHECK_COMPILE_FLAG(-Werror=unknown-warning-option,
[cxxflags_force_error="-Werror=unknown-warning-option"])

# Reduce compiler flag checking to a one-liner, needed for CMake to parse them
AC_DEFUN([BOX_CHECK_CXX_FLAG],
AX_CHECK_COMPILE_FLAG($1,
[cxxflags_strict="$cxxflags_strict $1"],,
$cxxflags_force_error)
)

# Enable some compiler flags if the compiler supports them. This gives better warnings
# and detects some problems early.
BOX_CHECK_CXX_FLAG(-Wall)
BOX_CHECK_CXX_FLAG(-Werror=return-type)
BOX_CHECK_CXX_FLAG(-Werror=non-virtual-dtor)
BOX_CHECK_CXX_FLAG(-Werror=delete-non-virtual-dtor)
# This error is detected by MSVC, but not usually by GCC/Clang:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58114
BOX_CHECK_CXX_FLAG(-Werror=delete-incomplete)

AC_SUBST([CXXFLAGS_STRICT], [$cxxflags_strict])

if test "x$GXX" = "xyes"; then
Expand Down

0 comments on commit 04ece62

Please sign in to comment.