From a10cdb715290ab06982891342aed9795e5ef9a9d Mon Sep 17 00:00:00 2001 From: Araragi Hokuto Date: Sat, 14 Nov 2020 04:23:13 +0800 Subject: [PATCH] Add -m64 to gcc by default on illumos GCC on illumos generates 32-bit object files by default to maintain backward compatibility, despite 32-bit platforms are no longer supported. This may cause link errors, since most distros seem to supply 64-bit LLVM in their repositories (verified on OpenIndiana and OmniOS). This commit adds an ILLUMOS_USE_M64 option, which is turned on by default, to instruct gcc on illumos to generate 64-bit object files, as this is usually the desired behaviour. --- CMakeLists.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b3a02386..c97e0d42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,6 +120,23 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD) target_link_libraries(ccls PRIVATE thr) endif() +if (${CMAKE_SYSTEM_NAME} STREQUAL SunOS) + # Check if we are on illumos + execute_process(COMMAND /usr/bin/uname -o OUTPUT_VARIABLE UNAME_O + OUTPUT_STRIP_TRAILING_WHITESPACE) + if ((UNAME_O STREQUAL illumos) AND (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)) + # As a workaround for legacy packages, illumos' GCC generates 32-bit object files + # despite 32-bit platform support has already been dropped. This will probably cause a linker error + # since most distros seem to supply 64-bit LLVM in their repositories + # (verified on OpenIndiana and OmniOS). + # Add -m64 on illumos with GCC by default to generate 64-bit object files. + option(ILLUMOS_USE_M64 "Use -m64 on illumos to generate 64-bit object files" ON) + if (ILLUMOS_USE_M64) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64") + endif() + endif() +endif() + if(LLVM_ENABLE_ZLIB) find_package(ZLIB) endif()