2018-03-17 19:03:41 +00:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2018-03-31 03:16:33 +00:00
|
|
|
project(ccls LANGUAGES CXX)
|
2018-03-17 19:03:41 +00:00
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)
|
|
|
|
include(DefaultCMakeBuildType)
|
|
|
|
|
2018-04-15 17:21:26 +00:00
|
|
|
# Required Clang version
|
|
|
|
set(CLANG_DOWNLOAD_LOCATION ${CMAKE_BINARY_DIR}
|
|
|
|
CACHE STRING "Downloaded Clang location")
|
|
|
|
option(SYSTEM_CLANG "Use system installation of Clang instead of \
|
|
|
|
downloading Clang" OFF)
|
2018-03-17 19:03:41 +00:00
|
|
|
option(ASAN "Compile with address sanitizers" OFF)
|
2018-08-23 22:18:15 +00:00
|
|
|
option(LLVM_ENABLE_RTTI "-fno-rtti if OFF. This should match LLVM libraries" OFF)
|
2018-05-08 06:56:53 +00:00
|
|
|
option(CLANG_USE_BUNDLED_LIBC++ "Let Clang use bundled libc++" OFF)
|
2018-05-14 02:09:26 +00:00
|
|
|
option(USE_SHARED_LLVM "Link against libLLVM.so instead separate LLVM{Option,Support,...}" OFF)
|
2018-03-17 19:03:41 +00:00
|
|
|
|
|
|
|
# Sources for the executable are specified at end of CMakeLists.txt
|
2018-03-31 03:16:33 +00:00
|
|
|
add_executable(ccls "")
|
2018-03-17 19:03:41 +00:00
|
|
|
|
|
|
|
### Compile options
|
|
|
|
|
|
|
|
# CMake default compile flags:
|
2018-03-22 05:01:21 +00:00
|
|
|
# MSVC + Clang(Windows):
|
2018-03-17 19:03:41 +00:00
|
|
|
# debug: /MDd /Zi /Ob0 /Od /RTC1
|
|
|
|
# release: /MD /O2 /Ob2 /DNDEBUG
|
|
|
|
# GCC + Clang(Linux):
|
|
|
|
# debug: -g
|
|
|
|
# release: -O3 -DNDEBUG
|
|
|
|
|
2018-04-02 03:55:10 +00:00
|
|
|
# Enable C++17 (Required)
|
2018-03-31 03:16:33 +00:00
|
|
|
set_property(TARGET ccls PROPERTY CXX_STANDARD 17)
|
|
|
|
set_property(TARGET ccls PROPERTY CXX_STANDARD_REQUIRED ON)
|
2018-03-26 15:30:33 +00:00
|
|
|
# Disable gnu extensions except for Cygwin which needs them to build properly
|
|
|
|
if(NOT CYGWIN)
|
2018-03-31 03:16:33 +00:00
|
|
|
set_property(TARGET ccls PROPERTY CXX_EXTENSIONS OFF)
|
2018-03-26 15:30:33 +00:00
|
|
|
endif()
|
2018-03-17 19:03:41 +00:00
|
|
|
|
2018-08-23 22:18:15 +00:00
|
|
|
if(NOT LLVM_ENABLE_RTTI)
|
|
|
|
# releases.llvm.org libraries are compiled with -fno-rtti
|
|
|
|
# The mismatch between lib{clang,LLVM}* and ccls can make libstdc++ std::make_shared return nullptr
|
|
|
|
# _Sp_counted_ptr_inplace::_M_get_deleter
|
|
|
|
target_compile_options(ccls PRIVATE -fno-rtti)
|
|
|
|
endif()
|
2018-05-13 16:52:19 +00:00
|
|
|
|
2018-04-14 18:57:23 +00:00
|
|
|
# CMake sets MSVC for both MSVC and Clang(Windows)
|
|
|
|
if(MSVC)
|
2018-03-17 19:03:41 +00:00
|
|
|
# Common MSVC/Clang(Windows) options
|
2018-03-31 03:16:33 +00:00
|
|
|
target_compile_options(ccls PRIVATE
|
2018-07-29 22:17:59 +00:00
|
|
|
/nologo
|
|
|
|
/EHsc
|
|
|
|
/D_CRT_SECURE_NO_WARNINGS # don't try to use MSVC std replacements
|
|
|
|
/W3 # roughly -Wall
|
|
|
|
/wd4996 # disable loguru unsafe warnings
|
|
|
|
/wd4722 # ignores warning C4722
|
|
|
|
# (destructor never returns) in loguru
|
|
|
|
/wd4267 # ignores warning C4267
|
|
|
|
# (conversion from 'size_t' to 'type'),
|
|
|
|
# roughly -Wno-sign-compare
|
|
|
|
/wd4800
|
|
|
|
/wd4068 # Disable unknown pragma warning
|
|
|
|
$<$<CONFIG:Debug>:/FS>
|
|
|
|
)
|
2018-03-17 19:03:41 +00:00
|
|
|
else()
|
|
|
|
# Common GCC/Clang(Linux) options
|
2018-03-31 03:16:33 +00:00
|
|
|
target_compile_options(ccls PRIVATE
|
2018-03-22 05:01:21 +00:00
|
|
|
-Wall
|
|
|
|
-Wno-sign-compare
|
2018-03-17 19:03:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
|
2018-03-31 03:16:33 +00:00
|
|
|
target_compile_options(ccls PRIVATE -Wno-return-type -Wno-unused-result)
|
2018-03-17 19:03:41 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
|
2018-03-31 03:16:33 +00:00
|
|
|
target_compile_options(ccls PRIVATE
|
2018-03-17 19:03:41 +00:00
|
|
|
$<$<CONFIG:Debug>:-fno-limit-debug-info>)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(ASAN)
|
2018-03-31 03:16:33 +00:00
|
|
|
target_compile_options(ccls PRIVATE -fsanitize=address,undefined)
|
2018-03-17 19:03:41 +00:00
|
|
|
# target_link_libraries also takes linker flags
|
2018-03-31 03:16:33 +00:00
|
|
|
target_link_libraries(ccls PRIVATE -fsanitize=address,undefined)
|
2018-03-17 19:03:41 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-04-15 17:21:26 +00:00
|
|
|
### Download Clang if required
|
|
|
|
|
|
|
|
if(NOT SYSTEM_CLANG)
|
|
|
|
message(STATUS "Using downloaded Clang")
|
2018-03-17 19:03:41 +00:00
|
|
|
|
2018-04-06 07:26:53 +00:00
|
|
|
include(DownloadAndExtractClang)
|
2018-07-29 22:17:59 +00:00
|
|
|
download_and_extract_clang(${CLANG_DOWNLOAD_LOCATION})
|
2018-03-17 19:03:41 +00:00
|
|
|
# Used by FindClang
|
|
|
|
set(CLANG_ROOT ${DOWNLOADED_CLANG_DIR})
|
2018-05-08 06:56:53 +00:00
|
|
|
|
|
|
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang AND CLANG_USE_BUNDLED_LIBC++)
|
|
|
|
message(STATUS "Using bundled libc++")
|
2018-05-11 21:23:53 +00:00
|
|
|
target_compile_options(ccls PRIVATE -nostdinc++ -cxx-isystem ${CLANG_ROOT}/include/c++/v1)
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
|
2018-05-12 20:31:56 +00:00
|
|
|
# Don't use -stdlib=libc++ because while ccls is linked with libc++, bundled clang+llvm require libstdc++
|
2018-05-13 20:30:24 +00:00
|
|
|
target_link_libraries(ccls PRIVATE -L${CLANG_ROOT}/lib c++ c++abi)
|
|
|
|
|
|
|
|
# FreeBSD defaults to -stdlib=libc++ and uses system libcxxrt.a
|
2018-05-11 21:23:53 +00:00
|
|
|
endif()
|
2018-05-08 06:56:53 +00:00
|
|
|
endif()
|
|
|
|
|
2018-04-06 07:26:53 +00:00
|
|
|
else()
|
2018-04-15 17:21:26 +00:00
|
|
|
message(STATUS "Using system Clang")
|
2018-03-17 19:03:41 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
### Libraries
|
|
|
|
|
|
|
|
# See cmake/FindClang.cmake
|
2018-07-29 22:17:59 +00:00
|
|
|
find_package(Clang 6.0.0)
|
2018-03-31 03:16:33 +00:00
|
|
|
target_link_libraries(ccls PRIVATE Clang::Clang)
|
2018-03-17 19:03:41 +00:00
|
|
|
|
|
|
|
# Enable threading support
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
2018-03-31 03:16:33 +00:00
|
|
|
target_link_libraries(ccls PRIVATE Threads::Threads)
|
2018-03-17 19:03:41 +00:00
|
|
|
|
2018-07-09 00:44:40 +00:00
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
|
2018-07-14 16:19:27 +00:00
|
|
|
find_package(Backtrace REQUIRED)
|
|
|
|
target_link_libraries(ccls PRIVATE ${Backtrace_LIBRARIES})
|
2018-03-17 19:03:41 +00:00
|
|
|
# src/platform_posix.cc uses libthr
|
2018-07-09 00:44:40 +00:00
|
|
|
target_link_libraries(ccls PRIVATE thr)
|
2018-03-17 19:03:41 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
### Definitions
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
target_compile_definitions(ccls PRIVATE
|
2018-08-06 07:45:04 +00:00
|
|
|
DEFAULT_RESOURCE_DIRECTORY=R"\(${Clang_RESOURCE_DIR}\)")
|
2018-03-17 19:03:41 +00:00
|
|
|
|
|
|
|
### Includes
|
|
|
|
|
2018-07-25 03:25:13 +00:00
|
|
|
target_include_directories(ccls PRIVATE src)
|
|
|
|
target_include_directories(ccls SYSTEM PRIVATE
|
2018-03-17 19:03:41 +00:00
|
|
|
third_party
|
2018-07-09 00:13:41 +00:00
|
|
|
third_party/rapidjson/include)
|
2018-03-17 19:03:41 +00:00
|
|
|
|
|
|
|
### Install
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
install(TARGETS ccls RUNTIME DESTINATION bin)
|
2018-03-17 19:03:41 +00:00
|
|
|
|
2018-04-15 17:21:26 +00:00
|
|
|
if(NOT SYSTEM_CLANG AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows)
|
2018-03-17 19:03:41 +00:00
|
|
|
|
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES Linux|FreeBSD)
|
2018-03-31 03:16:33 +00:00
|
|
|
set_property(TARGET ccls APPEND PROPERTY
|
2018-03-17 19:03:41 +00:00
|
|
|
INSTALL_RPATH $ORIGIN/../lib)
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
|
2018-03-31 03:16:33 +00:00
|
|
|
set_property(TARGET ccls APPEND PROPERTY
|
2018-03-22 05:01:21 +00:00
|
|
|
INSTALL_RPATH @loader_path/../lib)
|
2018-03-17 19:03:41 +00:00
|
|
|
endif()
|
|
|
|
|
2018-03-22 05:01:21 +00:00
|
|
|
file(GLOB LIBCLANG_PLUS_SYMLINKS
|
2018-03-17 19:03:41 +00:00
|
|
|
${DOWNLOADED_CLANG_DIR}/lib/libclang.[so,dylib]*)
|
|
|
|
install(FILES ${LIBCLANG_PLUS_SYMLINKS} DESTINATION lib)
|
|
|
|
endif()
|
|
|
|
|
2018-04-06 07:26:53 +00:00
|
|
|
# Allow running from build Windows by copying libclang.dll to build directory
|
2018-04-15 17:21:26 +00:00
|
|
|
if(NOT SYSTEM_CLANG AND ${CMAKE_SYSTEM_NAME} STREQUAL Windows)
|
2018-04-06 07:26:53 +00:00
|
|
|
add_custom_command(TARGET ccls
|
|
|
|
POST_BUILD
|
2018-04-14 18:57:23 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
${DOWNLOADED_CLANG_DIR}/bin/libclang.dll
|
2018-04-06 07:26:53 +00:00
|
|
|
$<TARGET_FILE_DIR:ccls>
|
|
|
|
COMMENT "Copying libclang.dll to build directory ...")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
### Tools
|
|
|
|
|
|
|
|
# We use glob here since source files are already manually added with
|
|
|
|
# target_sources further down
|
|
|
|
file(GLOB SOURCES src/*.cc src/*.h src/serializers/*.cc src/serializers/*.h
|
|
|
|
src/messages/*.h src/messages/*.cc)
|
|
|
|
|
2018-03-17 19:03:41 +00:00
|
|
|
### Sources
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
target_sources(ccls PRIVATE third_party/siphash.cc)
|
2018-03-17 19:03:41 +00:00
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
target_sources(ccls PRIVATE
|
2018-07-29 22:17:59 +00:00
|
|
|
src/clang_complete.cc
|
|
|
|
src/clang_tu.cc
|
|
|
|
src/config.cc
|
|
|
|
src/filesystem.cc
|
|
|
|
src/fuzzy_match.cc
|
|
|
|
src/main.cc
|
|
|
|
src/include_complete.cc
|
|
|
|
src/indexer.cc
|
|
|
|
src/log.cc
|
|
|
|
src/lsp.cc
|
|
|
|
src/match.cc
|
|
|
|
src/message_handler.cc
|
|
|
|
src/pipeline.cc
|
|
|
|
src/platform_posix.cc
|
|
|
|
src/platform_win.cc
|
|
|
|
src/position.cc
|
|
|
|
src/project.cc
|
|
|
|
src/query_utils.cc
|
|
|
|
src/query.cc
|
|
|
|
src/serializer.cc
|
|
|
|
src/test.cc
|
|
|
|
src/utils.cc
|
|
|
|
src/working_files.cc
|
|
|
|
)
|
2018-03-17 19:03:41 +00:00
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
target_sources(ccls PRIVATE
|
2018-09-13 07:18:37 +00:00
|
|
|
src/messages/ccls_call.cc
|
2018-10-01 07:57:24 +00:00
|
|
|
src/messages/ccls_info.cc
|
2018-09-13 07:18:37 +00:00
|
|
|
src/messages/ccls_inheritance.cc
|
|
|
|
src/messages/ccls_member.cc
|
2018-09-03 22:08:34 +00:00
|
|
|
src/messages/ccls_navigate.cc
|
2018-09-12 06:31:06 +00:00
|
|
|
src/messages/ccls_reload.cc
|
2018-07-29 22:17:59 +00:00
|
|
|
src/messages/ccls_vars.cc
|
|
|
|
src/messages/initialize.cc
|
2018-10-28 17:49:31 +00:00
|
|
|
src/messages/textDocument_code.cc
|
2018-07-29 22:17:59 +00:00
|
|
|
src/messages/textDocument_completion.cc
|
|
|
|
src/messages/textDocument_definition.cc
|
2018-09-28 05:16:42 +00:00
|
|
|
src/messages/textDocument_did.cc
|
2018-10-24 03:48:12 +00:00
|
|
|
src/messages/textDocument_foldingRange.cc
|
2018-09-28 05:19:26 +00:00
|
|
|
src/messages/textDocument_formatting.cc
|
2018-10-25 01:03:57 +00:00
|
|
|
src/messages/textDocument_document.cc
|
2018-07-29 22:17:59 +00:00
|
|
|
src/messages/textDocument_hover.cc
|
|
|
|
src/messages/textDocument_references.cc
|
|
|
|
src/messages/textDocument_rename.cc
|
|
|
|
src/messages/textDocument_signatureHelp.cc
|
2018-10-28 17:49:31 +00:00
|
|
|
src/messages/workspace.cc
|
2018-07-29 22:17:59 +00:00
|
|
|
)
|