ClickHouse/cmake/tools.cmake

64 lines
2.4 KiB
CMake
Raw Normal View History

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set (COMPILER_GCC 1)
2019-11-01 16:33:43 +00:00
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
set (COMPILER_CLANG 1)
endif ()
if (COMPILER_GCC)
# Require minimum version of gcc
set (GCC_MINIMUM_VERSION 8)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${GCC_MINIMUM_VERSION} AND NOT CMAKE_VERSION VERSION_LESS 2.8.9)
message (FATAL_ERROR "GCC version must be at least ${GCC_MINIMUM_VERSION}. For example, if GCC ${GCC_MINIMUM_VERSION} is available under gcc-${GCC_MINIMUM_VERSION}, g++-${GCC_MINIMUM_VERSION} names, do the following: export CC=gcc-${GCC_MINIMUM_VERSION} CXX=g++-${GCC_MINIMUM_VERSION}; rm -rf CMakeCache.txt CMakeFiles; and re run cmake or ./release.")
endif ()
elseif (COMPILER_CLANG)
# Require minimum version of clang
set (CLANG_MINIMUM_VERSION 7)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${CLANG_MINIMUM_VERSION})
message (FATAL_ERROR "Clang version must be at least ${CLANG_MINIMUM_VERSION}.")
endif ()
else ()
message (WARNING "You are using an unsupported compiler. Compilation has only been tested with Clang 6+ and GCC 7+.")
endif ()
2019-12-09 09:29:59 +00:00
STRING(REGEX MATCHALL "[0-9]+" COMPILER_VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION})
LIST(GET COMPILER_VERSION_LIST 0 COMPILER_VERSION_MAJOR)
2019-12-09 09:29:59 +00:00
option (LINKER_NAME "Linker name or full path")
2019-12-11 10:04:51 +00:00
if (COMPILER_GCC)
find_program (LLD_PATH NAMES "ld.lld")
find_program (GOLD_PATH NAMES "ld.gold")
else ()
find_program (LLD_PATH NAMES "ld.lld-${COMPILER_VERSION_MAJOR}" "lld-${COMPILER_VERSION_MAJOR}" "ld.lld" "lld")
find_program (GOLD_PATH NAMES "ld.gold" "gold")
endif ()
2019-12-10 20:14:57 +00:00
# We prefer LLD linker over Gold or BFD.
2020-02-16 08:48:01 +00:00
if (NOT LINKER_NAME)
if (LLD_PATH)
2019-12-10 13:59:54 +00:00
if (COMPILER_GCC)
2019-12-11 10:04:51 +00:00
# GCC driver requires one of supported linker names like "lld".
set (LINKER_NAME "lld")
2019-12-10 13:59:54 +00:00
else ()
2019-12-11 10:04:51 +00:00
# Clang driver simply allows full linker path.
2019-12-10 13:59:54 +00:00
set (LINKER_NAME ${LLD_PATH})
endif ()
endif ()
2020-02-16 08:48:01 +00:00
endif ()
2019-12-10 13:59:54 +00:00
2020-02-16 08:48:01 +00:00
if (NOT LINKER_NAME)
2019-12-10 13:59:54 +00:00
if (GOLD_PATH)
if (COMPILER_GCC)
2019-12-11 10:04:51 +00:00
set (LINKER_NAME "gold")
2019-12-10 13:59:54 +00:00
else ()
set (LINKER_NAME ${GOLD_PATH})
endif ()
endif ()
endif ()
if (LINKER_NAME)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=${LINKER_NAME}")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=${LINKER_NAME}")
message(STATUS "Using custom linker by name: ${LINKER_NAME}")
endif ()