From dc8f31c3f25921788ba6b52ee317173f9c80d6be Mon Sep 17 00:00:00 2001 From: ykiko Date: Sun, 20 Oct 2024 17:27:35 +0800 Subject: [PATCH] Refactor `CMakeLists.txt`. --- CMakeLists.txt | 111 ++++++++++++++++++----------------- include/Support/FileSystem.h | 1 + src/Compiler/Diagnostic.cpp | 10 ++-- src/Server/Config.cpp | 1 + unittests/Test.h | 1 + 5 files changed, 64 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99acc29f..9cf7d965 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() + + diff --git a/include/Support/FileSystem.h b/include/Support/FileSystem.h index 9dd17dbc..22053e17 100644 --- a/include/Support/FileSystem.h +++ b/include/Support/FileSystem.h @@ -1,5 +1,6 @@ #pragma once +#include #include namespace clice { diff --git a/src/Compiler/Diagnostic.cpp b/src/Compiler/Diagnostic.cpp index 7a28b727..9029625f 100644 --- a/src/Compiler/Diagnostic.cpp +++ b/src/Compiler/Diagnostic.cpp @@ -4,7 +4,7 @@ #include #include -#include +// #include 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(); diff --git a/src/Server/Config.cpp b/src/Server/Config.cpp index fa690839..11408f97 100644 --- a/src/Server/Config.cpp +++ b/src/Server/Config.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace clice::config { diff --git a/unittests/Test.h b/unittests/Test.h index 076e840f..396ca39a 100644 --- a/unittests/Test.h +++ b/unittests/Test.h @@ -4,6 +4,7 @@ #include #include +#include namespace clice { std::string test_dir();