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-06 07:26:53 +00:00
|
|
|
# Required libclang version
|
|
|
|
set(LIBCLANG_VERSION 6.0.0 CACHE STRING "libclang version")
|
|
|
|
set(LIBCLANG_DOWNLOAD_LOCATION ${CMAKE_BINARY_DIR}
|
|
|
|
CACHE STRING "Downloaded libclang location")
|
|
|
|
option(SYSTEM_LIBCLANG "Use system installation of libclang instead of \
|
|
|
|
downloading libclang" OFF)
|
2018-03-17 19:03:41 +00:00
|
|
|
option(ASAN "Compile with address sanitizers" OFF)
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
|
|
|
|
# Common MSVC/Clang(Windows) options
|
2018-03-31 03:16:33 +00:00
|
|
|
target_compile_options(ccls PRIVATE
|
2018-03-22 05:01:21 +00:00
|
|
|
/nologo
|
|
|
|
/EHsc
|
2018-03-17 19:03:41 +00:00
|
|
|
/W3 # roughly -Wall
|
|
|
|
/wd4996 # disable loguru unsafe warnings
|
2018-03-22 05:01:21 +00:00
|
|
|
/wd4722 # ignores warning C4722
|
2018-03-17 19:03:41 +00:00
|
|
|
# (destructor never returns) in loguru
|
2018-03-22 05:01:21 +00:00
|
|
|
/wd4267 # ignores warning C4267
|
|
|
|
# (conversion from 'size_t' to 'type'),
|
2018-03-17 19:03:41 +00:00
|
|
|
# roughly -Wno-sign-compare
|
|
|
|
/wd4800
|
|
|
|
$<$<CONFIG:Debug>:/FS>
|
|
|
|
)
|
|
|
|
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-06 07:26:53 +00:00
|
|
|
### Download libclang if required
|
2018-03-17 19:03:41 +00:00
|
|
|
|
2018-04-06 07:26:53 +00:00
|
|
|
if(NOT SYSTEM_LIBCLANG)
|
|
|
|
message(STATUS "Using downloaded libclang")
|
|
|
|
|
|
|
|
include(DownloadAndExtractClang)
|
|
|
|
download_and_extract_clang(${LIBCLANG_VERSION} ${LIBCLANG_DOWNLOAD_LOCATION})
|
2018-03-17 19:03:41 +00:00
|
|
|
# Used by FindClang
|
|
|
|
set(CLANG_ROOT ${DOWNLOADED_CLANG_DIR})
|
2018-04-06 07:26:53 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "Using system libclang")
|
2018-03-17 19:03:41 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
### Libraries
|
|
|
|
|
|
|
|
# See cmake/FindClang.cmake
|
2018-04-06 07:26:53 +00:00
|
|
|
find_package(Clang ${CLANG_VERSION} REQUIRED)
|
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-04-06 07:26:53 +00:00
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
|
|
|
|
target_link_libraries(ccls PRIVATE -lc++experimental)
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
|
2018-03-31 17:37:03 +00:00
|
|
|
else()
|
|
|
|
target_link_libraries(ccls PRIVATE -lstdc++fs)
|
|
|
|
endif()
|
|
|
|
|
2018-03-17 19:03:41 +00:00
|
|
|
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
|
|
|
|
# loguru calls dladdr
|
2018-03-31 03:16:33 +00:00
|
|
|
target_link_libraries(ccls PRIVATE ${CMAKE_DL_LIBS})
|
2018-03-17 19:03:41 +00:00
|
|
|
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
|
|
|
|
# loguru::stacktrace_as_stdstring calls backtrace_symbols
|
|
|
|
# sparsepp/spp_memory.h uses libkvm
|
|
|
|
# src/platform_posix.cc uses libthr
|
|
|
|
find_package(Backtrace REQUIRED)
|
2018-03-31 03:16:33 +00:00
|
|
|
target_link_libraries(ccls PRIVATE ${Backtrace_LIBRARIES} kvm thr)
|
2018-03-17 19:03:41 +00:00
|
|
|
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
|
|
|
|
# sparsepp/spp_memory.h uses LibPsapi
|
2018-03-31 03:16:33 +00:00
|
|
|
target_link_libraries(ccls PRIVATE Psapi)
|
2018-03-17 19:03:41 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
### Definitions
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
target_compile_definitions(ccls PRIVATE
|
2018-03-17 19:03:41 +00:00
|
|
|
LOGURU_WITH_STREAMS=1
|
|
|
|
LOGURU_FILENAME_WIDTH=18
|
|
|
|
LOGURU_THREADNAME_WIDTH=13
|
|
|
|
DEFAULT_RESOURCE_DIRECTORY="${Clang_RESOURCE_DIR}")
|
|
|
|
|
|
|
|
### Includes
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
target_include_directories(ccls PRIVATE
|
2018-03-17 19:03:41 +00:00
|
|
|
src
|
|
|
|
third_party
|
|
|
|
third_party/rapidjson/include
|
|
|
|
third_party/sparsepp
|
|
|
|
third_party/loguru
|
|
|
|
third_party/doctest
|
|
|
|
third_party/msgpack-c/include)
|
|
|
|
|
|
|
|
### 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-06 07:26:53 +00:00
|
|
|
# TODO: install libclang.dll on Windows as well
|
|
|
|
if(NOT SYSTEM_LIBCLANG 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
|
|
|
|
if(NOT SYSTEM_LIBCLANG AND ${CMAKE_SYSTEM_NAME} STREQUAL Windows)
|
|
|
|
add_custom_command(TARGET ccls
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
${DOWNLOADED_CLANG_DIR}/bin/libclang.dll
|
|
|
|
$<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)
|
|
|
|
|
|
|
|
if(Clang_FORMAT AND ${Clang_VERSION} STREQUAL 6.0.0)
|
|
|
|
add_custom_target(format
|
|
|
|
COMMAND ${Clang_FORMAT} -i ${SOURCES}
|
|
|
|
# .clang-format is located in the ccls root project dir
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
COMMENT "Running clang-format ...")
|
|
|
|
else()
|
|
|
|
# Set error message depending on which condition was false
|
|
|
|
if (NOT Clang_FORMAT)
|
|
|
|
set(Clang_FORMAT_ERROR "Error: clang-format executable not found")
|
|
|
|
elseif(NOT ${Clang_VERSION} STREQUAL 6.0.0)
|
|
|
|
set(Clang_FORMAT_ERROR "Error: clang-format version does not match \
|
|
|
|
6.0.0. Due to differences in clang-format output between versions we only \
|
|
|
|
support clang-format 6.0.0")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_target(format
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --red --bold
|
|
|
|
${Clang_FORMAT_ERROR})
|
|
|
|
endif()
|
|
|
|
|
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-03-17 19:03:41 +00:00
|
|
|
src/cache_manager.cc
|
|
|
|
src/clang_complete.cc
|
|
|
|
src/clang_cursor.cc
|
|
|
|
src/clang_indexer.cc
|
|
|
|
src/clang_translation_unit.cc
|
|
|
|
src/clang_utils.cc
|
|
|
|
src/command_line.cc
|
2018-03-31 20:59:27 +00:00
|
|
|
src/config.cc
|
2018-03-17 19:03:41 +00:00
|
|
|
src/diagnostics_engine.cc
|
|
|
|
src/file_consumer.cc
|
2018-04-08 00:10:54 +00:00
|
|
|
src/filesystem.cc
|
2018-03-17 19:03:41 +00:00
|
|
|
src/fuzzy_match.cc
|
|
|
|
src/iindexer.cc
|
|
|
|
src/import_pipeline.cc
|
|
|
|
src/include_complete.cc
|
2018-03-22 05:01:21 +00:00
|
|
|
src/method.cc
|
2018-03-17 19:03:41 +00:00
|
|
|
src/lex_utils.cc
|
|
|
|
src/lsp.cc
|
|
|
|
src/match.cc
|
|
|
|
src/message_handler.cc
|
|
|
|
src/platform_posix.cc
|
|
|
|
src/platform_win.cc
|
|
|
|
src/port.cc
|
|
|
|
src/position.cc
|
|
|
|
src/project.cc
|
|
|
|
src/query_utils.cc
|
|
|
|
src/query.cc
|
|
|
|
src/queue_manager.cc
|
|
|
|
src/serializer.cc
|
|
|
|
src/standard_includes.cc
|
|
|
|
src/test.cc
|
|
|
|
src/third_party_impl.cc
|
|
|
|
src/timer.cc
|
|
|
|
src/timestamp_manager.cc
|
|
|
|
src/type_printer.cc
|
|
|
|
src/utils.cc
|
|
|
|
src/working_files.cc)
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
target_sources(ccls PRIVATE
|
|
|
|
src/messages/ccls_base.cc
|
|
|
|
src/messages/ccls_call_hierarchy.cc
|
|
|
|
src/messages/ccls_callers.cc
|
|
|
|
src/messages/ccls_derived.cc
|
|
|
|
src/messages/ccls_file_info.cc
|
|
|
|
src/messages/ccls_freshen_index.cc
|
|
|
|
src/messages/ccls_index_file.cc
|
|
|
|
src/messages/ccls_inheritance_hierarchy.cc
|
|
|
|
src/messages/ccls_member_hierarchy.cc
|
|
|
|
src/messages/ccls_random.cc
|
|
|
|
src/messages/ccls_vars.cc
|
2018-03-17 19:03:41 +00:00
|
|
|
src/messages/exit.cc
|
|
|
|
src/messages/initialize.cc
|
|
|
|
src/messages/shutdown.cc
|
|
|
|
src/messages/text_document_code_lens.cc
|
|
|
|
src/messages/text_document_completion.cc
|
|
|
|
src/messages/text_document_definition.cc
|
|
|
|
src/messages/text_document_did_change.cc
|
|
|
|
src/messages/text_document_did_close.cc
|
|
|
|
src/messages/text_document_did_open.cc
|
|
|
|
src/messages/text_document_did_save.cc
|
|
|
|
src/messages/text_document_document_highlight.cc
|
|
|
|
src/messages/text_document_document_symbol.cc
|
|
|
|
src/messages/text_document_hover.cc
|
|
|
|
src/messages/text_document_references.cc
|
|
|
|
src/messages/text_document_rename.cc
|
|
|
|
src/messages/text_document_signature_help.cc
|
|
|
|
src/messages/text_document_type_definition.cc
|
|
|
|
src/messages/workspace_did_change_configuration.cc
|
|
|
|
src/messages/workspace_did_change_watched_files.cc
|
2018-03-31 03:16:33 +00:00
|
|
|
src/messages/workspace_symbol.cc
|
|
|
|
)
|