Refactor CMakeLists.txt.

This commit is contained in:
ykiko
2024-10-20 17:27:35 +08:00
parent ca7e09606c
commit dc8f31c3f2
5 changed files with 64 additions and 60 deletions

View File

@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.22)
project(CLICE)
project(CLICE_PROJECT)
set(CLICE_LIB_TYPE SHARED)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
@@ -22,73 +23,73 @@ if(NOT EXISTS "${CMAKE_BINARY_DIR}/lib/clang")
file(COPY ${CLANG_BUILTIN_HEADERS_SOURCE} DESTINATION ${CLANG_BUILTIN_HEADERS_OUTPUT})
endif()
function(target_clang target)
target_precompile_headers(${target} PRIVATE
"${CMAKE_SOURCE_DIR}/include/Compiler/Clang.h"
)
target_include_directories(${target} PRIVATE
${LLVM_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/deps/clang-extra/include
)
target_link_libraries(${target} PRIVATE
LLVMSupport
LLVMFrontendOpenMP
clangAST
clangASTMatchers
clangBasic
clangDependencyScanning
clangDriver
clangFormat
clangFrontend
clangIndex
clangLex
clangSema
clangSerialization
clangTooling
clangToolingCore
clangToolingInclusions
clangToolingInclusionsStdlib
clangToolingSyntax
)
endfunction()
# build clice core part as library
file(GLOB_RECURSE CLICE_CORE_SOURCES
"${CMAKE_SOURCE_DIR}/src/Compiler/*.cpp"
"${CMAKE_SOURCE_DIR}/src/Index/*.cpp"
"${CMAKE_SOURCE_DIR}/src/Feature/*.cpp"
"${CMAKE_SOURCE_DIR}/src/Support/*.cpp"
)
add_library(clice-core ${CLICE_LIB_TYPE} ${CLICE_CORE_SOURCES})
target_precompile_headers(clice-core PRIVATE
"${CMAKE_SOURCE_DIR}/include/Compiler/Clang.h"
)
target_include_directories(clice-core PUBLIC
${LLVM_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/include
)
target_link_libraries(clice-core PUBLIC
LLVMSupport
LLVMFrontendOpenMP
clangAST
clangASTMatchers
clangBasic
clangDependencyScanning
clangDriver
clangFormat
clangFrontend
clangIndex
clangLex
clangSema
clangSerialization
clangTooling
clangToolingCore
clangToolingInclusions
clangToolingInclusionsStdlib
clangToolingSyntax
)
# clice executable
add_subdirectory(${CMAKE_SOURCE_DIR}/deps/libuv)
add_subdirectory(${CMAKE_SOURCE_DIR}/deps/spdlog)
add_executable(clice)
target_clang(clice)
file(GLOB_RECURSE SRC_FILES "${CMAKE_SOURCE_DIR}/src/*/*.cpp")
target_sources(clice PRIVATE ${SRC_FILES} "${CMAKE_SOURCE_DIR}/src/main.cpp")
set(CLICE_SERVER_SOURCES ${CMAKE_SOURCE_DIR}/src/main.cpp)
file(GLOB_RECURSE SRC_FILES "${CMAKE_SOURCE_DIR}/src/Server/*.cpp")
list(APPEND CLICE_SERVER_SOURCES ${SRC_FILES})
add_executable(clice ${CLICE_SERVER_SOURCES})
target_include_directories(clice PRIVATE
"${CMAKE_SOURCE_DIR}/deps/toml/include"
"${CMAKE_SOURCE_DIR}/deps/libuv/include"
"${CMAKE_SOURCE_DIR}/deps/spdlog/include"
"${CMAKE_SOURCE_DIR}/deps/toml/include"
)
target_link_libraries(clice PRIVATE clice-core uv spdlog::spdlog)
target_link_libraries(clice PRIVATE uv spdlog::spdlog)
# clice tests
if(CLICE_ENABLE_TEST)
add_executable(clice_test)
# add googletest
add_subdirectory("${CMAKE_SOURCE_DIR}/deps/googletest")
target_include_directories(clice_test PRIVATE
"${CMAKE_SOURCE_DIR}/deps/googletest/googletest/include"
"${CMAKE_SOURCE_DIR}/deps/spdlog/include"
)
target_link_libraries(clice_test PRIVATE gtest_main spdlog::spdlog)
set(CLICE_TEST_SOURCES ${CMAKE_SOURCE_DIR}/unittests/main.cpp)
file(GLOB_RECURSE TEST_SRC_FILES "${CMAKE_SOURCE_DIR}/unittests/*/*.cpp")
list(APPEND CLICE_TEST_SOURCES ${TEST_SRC_FILES})
target_clang(clice_test)
file(GLOB_RECURSE AST_SRC_FILES
"${CMAKE_SOURCE_DIR}/src/Compiler/*.cpp"
"${CMAKE_SOURCE_DIR}/src/Index/*.cpp"
"${CMAKE_SOURCE_DIR}/src/Feature/*.cpp"
"${CMAKE_SOURCE_DIR}/src/Support/*.cpp"
add_executable(clice-tests ${CLICE_TEST_SOURCES})
target_include_directories(clice-tests PRIVATE
"${CMAKE_SOURCE_DIR}/deps/spdlog/include"
"${CMAKE_SOURCE_DIR}/deps/googletest/googletest/include"
)
file(GLOB TEST_SRC_FILES "${CMAKE_SOURCE_DIR}/unittests/*/*.cpp")
target_sources(clice_test PRIVATE ${AST_SRC_FILES} ${TEST_SRC_FILES} ${CMAKE_SOURCE_DIR}/unittests/main.cpp)
target_link_libraries(clice-tests PRIVATE clice-core gtest_main spdlog::spdlog)
endif()

View File

@@ -1,5 +1,6 @@
#pragma once
#include <llvm/Support/Path.h>
#include <llvm/Support/FileSystem.h>
namespace clice {

View File

@@ -4,7 +4,7 @@
#include <clang/Basic/DiagnosticIDs.h>
#include <clang/Basic/AllDiagnostics.h>
#include <spdlog/fmt/bundled/color.h>
// #include <spdlog/fmt/bundled/color.h>
namespace clice {
@@ -113,10 +113,10 @@ void DiagnosticCollector::HandleDiagnostic(clang::DiagnosticsEngine::Level level
llvm::SmallString<128> message;
diagnostic.FormatDiagnostic(message);
// diagnostic.getLocation();
fmt::print(fg(fmt::color::red),
"[Diagnostic, kind: {}, message: {}]\n",
refl::enum_name(level),
message.str().str());
// fmt::print(fg(fmt::color::red),
// "[Diagnostic, kind: {}, message: {}]\n",
// refl::enum_name(level),
// message.str().str());
diagnostic.getLocation().dump(diagnostic.getDiags()->getSourceManager());
// get diagnostic text.
auto id = diagnostic.getID();

View File

@@ -4,6 +4,7 @@
#include <Server/Logger.h>
#include <Support/Reflection.h>
#include <Support/FileSystem.h>
#include <llvm/ADT/StringMap.h>
namespace clice::config {

View File

@@ -4,6 +4,7 @@
#include <Support/FileSystem.h>
#include <spdlog/fmt/bundled/color.h>
#include <llvm/Support/MemoryBuffer.h>
namespace clice {
std::string test_dir();