2018-06-08 16:00:56 +00:00
|
|
|
# Use Ninja instead of Unix Makefiles by default.
|
2018-06-08 16:07:52 +00:00
|
|
|
# https://stackoverflow.com/questions/11269833/cmake-selecting-a-generator-within-cmakelists-txt
|
|
|
|
#
|
2019-01-17 19:04:21 +00:00
|
|
|
# Reason: it has better startup time than make and it parallelizes jobs more uniformly.
|
2018-06-08 16:07:52 +00:00
|
|
|
# (when comparing to make with Makefiles that was generated by CMake)
|
|
|
|
#
|
|
|
|
# How to install Ninja on Ubuntu:
|
|
|
|
# sudo apt-get install ninja-build
|
2018-06-08 16:00:56 +00:00
|
|
|
|
2018-09-07 13:02:52 +00:00
|
|
|
|
2022-08-26 10:30:05 +00:00
|
|
|
if (NOT DEFINED ENV{XCODE_IDE})
|
2018-09-07 00:24:59 +00:00
|
|
|
find_program(NINJA_PATH ninja)
|
|
|
|
if (NINJA_PATH)
|
2022-06-02 13:44:10 +00:00
|
|
|
set(CMAKE_GENERATOR "Ninja" CACHE INTERNAL "")
|
2018-09-07 00:24:59 +00:00
|
|
|
endif ()
|
|
|
|
endif()
|
2021-10-12 00:30:08 +00:00
|
|
|
|
2022-04-30 06:37:08 +00:00
|
|
|
# Check if environment is polluted.
|
2022-06-03 14:30:43 +00:00
|
|
|
if (NOT "$ENV{CFLAGS}" STREQUAL ""
|
|
|
|
OR NOT "$ENV{CXXFLAGS}" STREQUAL ""
|
|
|
|
OR NOT "$ENV{LDFLAGS}" STREQUAL ""
|
2023-03-26 17:59:39 +00:00
|
|
|
OR CMAKE_C_FLAGS OR CMAKE_CXX_FLAGS OR CMAKE_EXE_LINKER_FLAGS OR CMAKE_MODULE_LINKER_FLAGS
|
|
|
|
OR CMAKE_C_FLAGS_INIT OR CMAKE_CXX_FLAGS_INIT OR CMAKE_EXE_LINKER_FLAGS_INIT OR CMAKE_MODULE_LINKER_FLAGS_INIT)
|
2022-04-30 06:37:08 +00:00
|
|
|
|
2022-06-03 14:22:36 +00:00
|
|
|
# if $ENV
|
2022-04-30 06:37:08 +00:00
|
|
|
message("CFLAGS: $ENV{CFLAGS}")
|
|
|
|
message("CXXFLAGS: $ENV{CXXFLAGS}")
|
|
|
|
message("LDFLAGS: $ENV{LDFLAGS}")
|
2022-06-03 14:22:36 +00:00
|
|
|
# if *_FLAGS
|
2022-04-30 06:37:08 +00:00
|
|
|
message("CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
|
|
|
|
message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
|
|
|
message("CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
|
|
|
|
message("CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}")
|
|
|
|
message("CMAKE_MODULE_LINKER_FLAGS: ${CMAKE_MODULE_LINKER_FLAGS}")
|
2022-06-03 14:22:36 +00:00
|
|
|
# if *_FLAGS_INIT
|
|
|
|
message("CMAKE_C_FLAGS_INIT: ${CMAKE_C_FLAGS_INIT}")
|
|
|
|
message("CMAKE_CXX_FLAGS_INIT: ${CMAKE_CXX_FLAGS_INIT}")
|
|
|
|
message("CMAKE_EXE_LINKER_FLAGS_INIT: ${CMAKE_EXE_LINKER_FLAGS_INIT}")
|
|
|
|
message("CMAKE_MODULE_LINKER_FLAGS_INIT: ${CMAKE_MODULE_LINKER_FLAGS_INIT}")
|
2022-04-30 06:37:08 +00:00
|
|
|
|
2024-11-21 19:08:59 +00:00
|
|
|
message( "
|
2022-04-30 06:37:08 +00:00
|
|
|
Some of the variables like CFLAGS, CXXFLAGS, LDFLAGS are not empty.
|
|
|
|
It is not possible to build ClickHouse with custom flags.
|
|
|
|
These variables can be set up by previous invocation of some other build tools.
|
|
|
|
You should cleanup these variables and start over again.
|
|
|
|
|
|
|
|
Run the `env` command to check the details.
|
|
|
|
You will also need to remove the contents of the build directory.
|
|
|
|
|
|
|
|
Note: if you don't like this behavior, you can manually edit the cmake files, but please don't complain to developers.")
|
|
|
|
endif()
|
2021-10-12 00:30:08 +00:00
|
|
|
|
|
|
|
# Default toolchain - this is needed to avoid dependency on OS files.
|
2024-08-13 08:30:31 +00:00
|
|
|
execute_process(COMMAND uname -s
|
|
|
|
OUTPUT_VARIABLE OS
|
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
|
|
|
)
|
|
|
|
execute_process(COMMAND uname -m
|
|
|
|
OUTPUT_VARIABLE ARCH
|
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
|
|
|
)
|
2021-10-12 00:30:08 +00:00
|
|
|
|
2022-06-02 13:40:56 +00:00
|
|
|
# By default, prefer clang on Linux
|
|
|
|
# But note, that you still may change the compiler with -DCMAKE_C_COMPILER/-DCMAKE_CXX_COMPILER.
|
2022-06-03 14:26:13 +00:00
|
|
|
if (OS MATCHES "Linux"
|
|
|
|
AND "$ENV{CC}" STREQUAL ""
|
2023-02-02 19:56:18 +00:00
|
|
|
AND "$ENV{CXX}" STREQUAL ""
|
|
|
|
AND NOT DEFINED CMAKE_C_COMPILER
|
|
|
|
AND NOT DEFINED CMAKE_CXX_COMPILER)
|
2022-06-02 13:40:56 +00:00
|
|
|
find_program(CLANG_PATH clang)
|
|
|
|
if (CLANG_PATH)
|
|
|
|
set(CMAKE_C_COMPILER "clang" CACHE INTERNAL "")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_program(CLANG_CXX_PATH clang++)
|
|
|
|
if (CLANG_CXX_PATH)
|
|
|
|
set(CMAKE_CXX_COMPILER "clang++" CACHE INTERNAL "")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-10-12 22:12:50 +00:00
|
|
|
if (OS MATCHES "Linux"
|
|
|
|
AND NOT DEFINED CMAKE_TOOLCHAIN_FILE
|
|
|
|
AND NOT DISABLE_HERMETIC_BUILD
|
2022-06-03 14:30:43 +00:00
|
|
|
AND ("$ENV{CC}" MATCHES ".*clang.*" OR CMAKE_C_COMPILER MATCHES ".*clang.*"))
|
2021-10-12 22:12:50 +00:00
|
|
|
|
2021-10-12 00:30:08 +00:00
|
|
|
if (ARCH MATCHES "amd64|x86_64")
|
2023-09-04 19:56:41 +00:00
|
|
|
# NOTE: right now musl is not ready, since unwind is too slow with it
|
|
|
|
#
|
|
|
|
# FWIW the following had been tried:
|
|
|
|
# - update musl
|
|
|
|
# - compile musl with debug
|
|
|
|
# - compile musl with debug and -fasynchronous-unwind-tables
|
|
|
|
#
|
|
|
|
# But none of this changes anything so far.
|
|
|
|
set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-x86_64.cmake" CACHE INTERNAL "")
|
2021-10-12 00:30:08 +00:00
|
|
|
elseif (ARCH MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)")
|
2022-06-02 13:44:10 +00:00
|
|
|
set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-aarch64.cmake" CACHE INTERNAL "")
|
2021-10-12 00:30:08 +00:00
|
|
|
elseif (ARCH MATCHES "^(ppc64le.*|PPC64LE.*)")
|
2022-06-02 13:44:10 +00:00
|
|
|
set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-ppc64le.cmake" CACHE INTERNAL "")
|
2023-01-20 21:16:55 +00:00
|
|
|
elseif (ARCH MATCHES "^(s390x.*|S390X.*)")
|
|
|
|
set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-s390x.cmake" CACHE INTERNAL "")
|
2024-03-15 03:11:24 +00:00
|
|
|
elseif (ARCH MATCHES "^(loongarch64.*|LOONGARCH64.*)")
|
|
|
|
set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-loongarch64.cmake" CACHE INTERNAL "")
|
2023-02-02 21:00:49 +00:00
|
|
|
else ()
|
2021-10-12 00:30:08 +00:00
|
|
|
message (FATAL_ERROR "Unsupported architecture: ${ARCH}")
|
|
|
|
endif ()
|
2023-01-20 21:16:55 +00:00
|
|
|
|
2021-10-12 00:30:08 +00:00
|
|
|
endif()
|