CheckCCompilerFlag: Strict signature of 'main' (#11615)

Use "int main(void)" instead of just "int main()" so that compiling with
"gcc -Werror=strict-prototypes" works.  Test this check using the flags
"-Werror -Wstrict-prototypes" to work with old GCC versions.
This commit is contained in:
Brad King 2010-12-16 13:34:54 -05:00
parent aadee46c60
commit b3efdb58d5
2 changed files with 7 additions and 1 deletions

View File

@ -25,7 +25,7 @@ INCLUDE(CheckCSourceCompiles)
MACRO (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
CHECK_C_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT}
CHECK_C_SOURCE_COMPILES("int main(void) { return 0; }" ${_RESULT}
# Some compilers do not fail with a bad flag
FAIL_REGEX "unrecognized .*option" # GNU
FAIL_REGEX "ignoring unknown option" # MSVC

View File

@ -226,3 +226,9 @@ UNSET(CXX_BOGUS_FLAG CACHE)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(${CXX_DD}-_this_is_not_a_flag_ CXX_BOGUS_FLAG)
TEST_FAIL(CXX_BOGUS_FLAG "CHECK_CXX_COMPILER_FLAG() succeeded, but should have failed")
IF("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
UNSET(C_STRICT_PROTOTYPES CACHE)
CHECK_C_COMPILER_FLAG("-Werror;-Wstrict-prototypes" C_STRICT_PROTOTYPES)
TEST_ASSERT(C_STRICT_PROTOTYPES "CHECK_C_COMPILER_FLAG failed -Werror -Wstrict-prototypes")
ENDIF()