properly set C[XX]FLAGS during CMake configure-time checks
Summary: Some compilers require `-std=c++11` for the `cstdint` header to be available. We already have logic to add `-std=c++11` to `CXXFLAGS` when the compiler is not MSVC; simply reorder CMakeLists.txt so that logic happens before the calls to `CHECK_CXX_SOURCE_COMPILES`. Additionally add a missing `set(CMAKE_REQUIRED_FLAGS, ...)` before a call to `CHECK_C_SOURCE_COMPILES`. Closes https://github.com/facebook/rocksdb/pull/2535 Differential Revision: D5384244 Pulled By: yiwu-arbug fbshipit-source-id: 2dbae4297c5d8ab4636e08b1457ffb2d3e37aef4
This commit is contained in:
parent
c5f0c6cc66
commit
279296f4d8
@ -148,6 +148,31 @@ if(WIN32 AND MSVC)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(BUILD_VERSION_CC ${CMAKE_BINARY_DIR}/build_version.cc)
|
||||||
|
configure_file(util/build_version.cc.in ${BUILD_VERSION_CC} @ONLY)
|
||||||
|
add_library(build_version OBJECT ${BUILD_VERSION_CC})
|
||||||
|
target_include_directories(build_version PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/util)
|
||||||
|
if(MSVC)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W3 /wd4127 /wd4800 /wd4996 /wd4351")
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wextra -Wall")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers")
|
||||||
|
if(MINGW)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format")
|
||||||
|
endif()
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fno-omit-frame-pointer")
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
CHECK_CXX_COMPILER_FLAG("-momit-leaf-frame-pointer" HAVE_OMIT_LEAF_FRAME_POINTER)
|
||||||
|
if(HAVE_OMIT_LEAF_FRAME_POINTER)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -momit-leaf-frame-pointer")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
option(PORTABLE "build a portable binary" OFF)
|
option(PORTABLE "build a portable binary" OFF)
|
||||||
option(FORCE_SSE42 "force building with SSE4.2, even when PORTABLE=ON" OFF)
|
option(FORCE_SSE42 "force building with SSE4.2, even when PORTABLE=ON" OFF)
|
||||||
if(PORTABLE)
|
if(PORTABLE)
|
||||||
@ -191,31 +216,6 @@ if(HAVE_THREAD_LOCAL)
|
|||||||
add_definitions(-DROCKSDB_SUPPORT_THREAD_LOCAL)
|
add_definitions(-DROCKSDB_SUPPORT_THREAD_LOCAL)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(BUILD_VERSION_CC ${CMAKE_BINARY_DIR}/build_version.cc)
|
|
||||||
configure_file(util/build_version.cc.in ${BUILD_VERSION_CC} @ONLY)
|
|
||||||
add_library(build_version OBJECT ${BUILD_VERSION_CC})
|
|
||||||
target_include_directories(build_version PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/util)
|
|
||||||
if(MSVC)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W3 /wd4127 /wd4800 /wd4996 /wd4351")
|
|
||||||
else()
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wextra -Wall")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers")
|
|
||||||
if(MINGW)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format")
|
|
||||||
endif()
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
||||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fno-omit-frame-pointer")
|
|
||||||
include(CheckCXXCompilerFlag)
|
|
||||||
CHECK_CXX_COMPILER_FLAG("-momit-leaf-frame-pointer" HAVE_OMIT_LEAF_FRAME_POINTER)
|
|
||||||
if(HAVE_OMIT_LEAF_FRAME_POINTER)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -momit-leaf-frame-pointer")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
option(FAIL_ON_WARNINGS "Treat compile warnings as errors" ON)
|
option(FAIL_ON_WARNINGS "Treat compile warnings as errors" ON)
|
||||||
if(FAIL_ON_WARNINGS)
|
if(FAIL_ON_WARNINGS)
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
@ -325,6 +325,7 @@ endif()
|
|||||||
option(WITH_FALLOCATE "build with fallocate" ON)
|
option(WITH_FALLOCATE "build with fallocate" ON)
|
||||||
|
|
||||||
if(WITH_FALLOCATE)
|
if(WITH_FALLOCATE)
|
||||||
|
set(CMAKE_REQUIRED_FLAGS ${CMAKE_C_FLAGS})
|
||||||
include(CheckCSourceCompiles)
|
include(CheckCSourceCompiles)
|
||||||
CHECK_C_SOURCE_COMPILES("
|
CHECK_C_SOURCE_COMPILES("
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user