more right way to check if compiler support c++11

This commit is contained in:
Evgeniy A. Dushistov
2016-06-02 14:17:02 +03:00
parent d58e6caa25
commit 25c3b6047e
2 changed files with 45 additions and 8 deletions

View File

@@ -13,6 +13,8 @@ endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8)
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_policy(VERSION 2.8) cmake_policy(VERSION 2.8)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler.cmake")
set(ZLIB_FIND_REQUIRED True) set(ZLIB_FIND_REQUIRED True)
include(FindZLIB) include(FindZLIB)
@@ -28,7 +30,7 @@ endif()
find_path(READLINE_INCLUDE_DIR readline/readline.h) find_path(READLINE_INCLUDE_DIR readline/readline.h)
find_library(READLINE_LIBRARY NAMES readline) find_library(READLINE_LIBRARY NAMES readline)
if (READLINE_INCLUDE_DIR AND READLINE_LIBRARY) if (READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
set(WITH_READLINE TRUE) set(WITH_READLINE True)
endif () endif ()
option(ENABLE_NLS "Enable NLS support" True) option(ENABLE_NLS "Enable NLS support" True)
@@ -99,7 +101,7 @@ set(CPACK_PACKAGE_VERSION_PATCH "0-beta4")
set(sdcv_VERSION set(sdcv_VERSION
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
add_definitions(-DVERSION="${sdcv_VERSION}" -DHAVE_CONFIG_H "-std=c++11") add_definitions(-DVERSION="${sdcv_VERSION}" -DHAVE_CONFIG_H)
add_executable(sdcv ${sdcv_SRCS}) add_executable(sdcv ${sdcv_SRCS})
@@ -109,17 +111,17 @@ target_link_libraries(sdcv
${READLINE_LIBRARY} ${READLINE_LIBRARY}
) )
if (ENABLE_NLS) if (ENABLE_NLS)
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "locale") set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "locale")
endif () endif ()
include(CPack) include(CPack)
INSTALL(TARGETS sdcv DESTINATION "bin") install(TARGETS sdcv DESTINATION "bin")
INSTALL(FILES doc/sdcv.1 DESTINATION "share/man/man1") install(FILES doc/sdcv.1 DESTINATION "share/man/man1")
INSTALL(FILES doc/uk/sdcv.1 DESTINATION "share/man/uk/man1") install(FILES doc/uk/sdcv.1 DESTINATION "share/man/uk/man1")
if (ENABLE_NLS) if (ENABLE_NLS)
INSTALL(DIRECTORY "${gettext_outDir}" DESTINATION "share") install(DIRECTORY "${gettext_outDir}" DESTINATION "share")
endif () endif ()
option(BUILD_TESTS "Enable automatic testing" False) option(BUILD_TESTS "Enable automatic testing" False)
@@ -145,4 +147,4 @@ if (BUILD_TESTS)
add_sdcv_shell_test(t_utf8input) add_sdcv_shell_test(t_utf8input)
add_sdcv_shell_test(t_datadir) add_sdcv_shell_test(t_datadir)
endif () endif ()

35
cmake/compiler.cmake Normal file
View File

@@ -0,0 +1,35 @@
function(append value)
foreach(variable ${ARGN})
set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
endforeach(variable)
endfunction()
include(CheckCXXCompilerFlag)
if (NOT DEFINED SDCV_COMPILER_IS_GCC_COMPATIBLE)
if (CMAKE_COMPILER_IS_GNUCXX)
set(SDCV_COMPILER_IS_GCC_COMPATIBLE ON)
elseif (MSVC)
set(SDCV_COMPILER_IS_GCC_COMPATIBLE OFF)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set (SDCV_COMPILER_IS_GCC_COMPATIBLE ON)
endif()
endif()
if (MSVC AND (MSVC_VERSION LESS 1900))
message(FATAL_ERROR "MSVC version ${MSVC_VERSION} have no full c++11 support")
elseif (MSVC)
add_definitions(-DNOMINMAX)
elseif (NOT MSVC)
check_cxx_compiler_flag("-std=c++11" CXX_SUPPORTS_CXX11)
if (CXX_SUPPORTS_CXX11)
append("-std=c++11" CMAKE_CXX_FLAGS)
else ()
message(FATAL_ERROR "sdcv requires C++11 support but the '-std=c++11' flag isn't supported.")
endif()
endif ()
if (SDCV_COMPILER_IS_GCC_COMPATIBLE)
append("-Wall" "-Wextra" "-Wformat-security" "-Wcast-align" "-Werror=format" "-Wcast-qual" CMAKE_C_FLAGS)
append("-Wall" "-pedantic" "-Wextra" "-Wformat-security" "-Wcast-align" "-Werror=format" "-Wcast-qual" CMAKE_CXX_FLAGS)
endif ()