Skip to content

Commit

Permalink
[DEPENDENCIES] Bump Slang to v7.0 and fix hash def
Browse files Browse the repository at this point in the history
In order to align the indexer with v7.0, it was required to remove a
definition of a hash on slang::SourceRange that has been introduced in
v7.0

This commit also integrate personnal work in order to perform a better
split of the project in sub-libs.

Fix #14
  • Loading branch information
suzizecat committed Oct 12, 2024
1 parent f4a00cb commit a748871
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 116 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## Changed

- Reorganization of all "sub applications" in sub-cmake files

## Fixed

- Removed definition of hash for slang::SourceRange introduced by Slang 7.0 (#14)

## Dependencies

- Slang from 6.0 to 7.0
- uri from `master` to a fixed hash + remove shallow clone (#13)


# 0.2.0

## Added

- Add support for `include` folders in config files.
Expand Down
121 changes: 17 additions & 104 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ endif()

message(STATUS "Software version: " ${VERSION_STRING})


# Use sockpp as a static lib
option(SOCKPP_BUILD_SHARED "" OFF)
option(SOCKPP_BUILD_STATIC "" ON)
Expand All @@ -44,128 +45,36 @@ option(SPDLOG_FMT_EXTERNAL "" ON)
# As workaround
option(SLANG_USE_MIMALLOC "" ON)

# Add all third parties
include(third-party.cmake)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(LSP_METAMODEL_PATH ${CMAKE_CURRENT_BINARY_DIR}/metaModel.json)
set(LSP_DATASTRUCT_ROOT ${CMAKE_SOURCE_DIR}/lsp-server/include/types)
set(LSP_DATASTRUCT_CMAKE ${LSP_DATASTRUCT_ROOT}/generated_headers.cmake)

if(NOT EXISTS ${LSP_DATASTRUCT_CMAKE} OR NOT EXISTS ${LSP_METAMODEL_PATH})

message(STATUS "Regenerating LSP data structures using " ${LSP_METAMODEL_PATH})
file(
DOWNLOAD https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/metaModel/metaModel.json
${LSP_METAMODEL_PATH}
)
# Add all third parties
include(cmake/third-party.cmake)
include(cmake/create-component.cmake)
include(cmake/lsp-datastructures.cmake)

execute_process(COMMAND python3 ${CMAKE_SOURCE_DIR}/tools/LSPGen/main.py -fo ${LSP_DATASTRUCT_ROOT} ${LSP_METAMODEL_PATH})
message(STATUS "Regeneration done. ")

endif()

include(${LSP_DATASTRUCT_CMAKE})
list(TRANSFORM SVLS_GEN_HEADERS PREPEND ${LSP_DATASTRUCT_ROOT}/)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# add_subdirectory(lib-diplomat-index)
###########################################################
# SV-FORMATTER
###########################################################
message(STATUS "Setup SV-Formatter library and executable ")
add_library(sv-formatter-lib STATIC
formatter/format_DataDeclaration.cpp
formatter/spacing_manager.cpp
)

target_link_libraries(sv-formatter-lib PRIVATE slang::slang)
target_include_directories(sv-formatter-lib INTERFACE formatter/)

add_executable(sv-formatter-exe

utils/ast-printer/ast_print.cpp

formatter/main_formatter.cpp
)

target_link_libraries(sv-formatter-exe
PRIVATE argparse::argparse
PRIVATE fmt::fmt
PRIVATE spdlog::spdlog

PRIVATE slang::slang
PRIVATE sv-formatter-lib
)


target_include_directories(sv-formatter-exe
PRIVATE $<TARGET_PROPERTY:sv-formatter-lib,INTERFACE_INCLUDE_DIRECTORIES>
PRIVATE utils/ast-printer)

set_property(TARGET sv-formatter-exe PROPERTY OUTPUT_NAME sv-formatter)
set_property(TARGET sv-formatter-lib PROPERTY OUTPUT_NAME sv-formatter)

message(STATUS "Setup SV-Explorer library and executable ")
include(cmake/sv-formatter.cmake)
include(cmake/sv-explorer.cmake)
# include(cmake/sv-indexer.cmake)


add_library(sv-explorer-lib STATIC
explorer/hier_visitor.cpp
)

target_link_libraries(sv-explorer-lib
PRIVATE slang::slang
PRIVATE nlohmann_json::nlohmann_json)
target_include_directories(sv-explorer-lib INTERFACE explorer/)


add_executable(sv-explorer-exe
explorer/main.cpp
explorer/explorer_visitor.cpp
)

target_link_libraries(sv-explorer-exe
PRIVATE nlohmann_json::nlohmann_json
PRIVATE slang::slang
PRIVATE sv-explorer-lib
)


target_include_directories(sv-explorer-exe
PRIVATE $<TARGET_PROPERTY:sv-explorer-lib,INTERFACE_INCLUDE_DIRECTORIES>
PRIVATE utils/ast_print)

set_property(TARGET sv-explorer-exe PROPERTY OUTPUT_NAME sv-explorer)
set_property(TARGET sv-explorer-lib PROPERTY OUTPUT_NAME sv-explorer)

######################################################################
######################################################################
######################################################################


# target_link_libraries(sv-explorer
# PRIVATE nlohmann_json::nlohmann_json
# PRIVATE slang::slang)

# target_include_directories(sv-explorer
# PRIVATE explorer/)

######################################################################
######################################################################
######################################################################

message(STATUS "Setup SV-LSP executable and other stuff")


# add_library(diplomat-system-lib STATIC
# system/src/process_handler_lnx.cpp
# )

# target_include_directories(diplomat-system-lib PRIVATE system/include)


add_executable(sv-blackbox main_blackbox.cpp
documenter_visitor.h
documenter_visitor.cpp)
Expand Down Expand Up @@ -194,7 +103,6 @@ lsp-server/diplomat/src/visitor_module_bb.cpp
lsp-server/diplomat/src/visitor_index.cpp
lsp-server/diplomat/src/diagnostic_client.cpp
lsp-server/diplomat/src/diplomat_index.cpp

)

target_compile_definitions(slang-lsp PUBLIC DIPLOMAT_VERSION_STRING=\"${VERSION_STRING}\")
Expand All @@ -214,6 +122,7 @@ PRIVATE spdlog::spdlog
PRIVATE nlohmann_json::nlohmann_json
PRIVATE sv-formatter-lib
PRIVATE sv-explorer-lib
# PRIVATE sv-indexer-lib
PUBLIC slang::slang
)

Expand All @@ -238,8 +147,12 @@ utils/ast-printer/ast_print.cpp
utils/ast-printer/ast_print_main.cpp
)

target_include_directories(sv-tree
PRIVATE utils/ast-printer
)

target_link_libraries(sv-tree
PRIVATE slang::slang
PUBLIC slang::slang
PRIVATE argparse::argparse)

# target_include_directories(sv-explorer
Expand Down
62 changes: 62 additions & 0 deletions cmake/create-component.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function(create_component NAME)
set(options NOLIB)
set(multiValueArgs
LIB_SRC
LIB_INC
LIB_LINK
EXE_SRC
EXE_INC
EXE_LINK
)
cmake_parse_arguments(PARSE_ARGV 1 COMP "${options}" "${oneValueArgs}" "${multiValueArgs}")

if(NOT ${COMP_NOLIB})
add_library(${NAME}-lib STATIC)
if(DEFINED COMP_LIB_SRC)
target_sources(${NAME}-lib ${COMP_LIB_SRC})
endif()

if(DEFINED COMP_LIB_LINK)
target_link_libraries(${NAME}-lib ${COMP_LIB_LINK})
endif()

if(DEFINED COMP_LIB_INC)
target_include_directories(${NAME}-lib ${COMP_LIB_INC})
endif()

if(NOT DEFINED COMP_EXE_LINK)
set(COMP_EXE_LINK "")
endif()

if(NOT DEFINED COMP_EXE_INC)
set(COMP_EXE_LINK "")
endif()

list(PREPEND COMP_EXE_LINK PRIVATE ${NAME}-lib)
list(PREPEND COMP_EXE_INC PRIVATE $<TARGET_PROPERTY:${NAME}-lib,INTERFACE_INCLUDE_DIRECTORIES>)
# message(STATUS " EXE INC : ${COMP_EXE_INC}")
# Override the output name to avoid libNAME-lib.so
# The lib prefix is automatically added.
set_property(TARGET ${NAME}-lib PROPERTY OUTPUT_NAME ${NAME})
else()
message(STATUS "No library for target component ${NAME}")
endif()

add_executable(${NAME}-exe)
if(DEFINED COMP_EXE_SRC)
target_sources(${NAME}-exe ${COMP_EXE_SRC})
else()
message(ERROR "Component ${NAME} have no source specified for its executable (EXE_SRC)")
endif()


target_link_libraries(${NAME}-exe ${COMP_EXE_LINK})
target_include_directories(${NAME}-exe ${COMP_EXE_INC})

# Override the output name of the executable to have a clean NAME
# instead of NAME-exe.
set_property(TARGET ${NAME}-exe PROPERTY OUTPUT_NAME ${NAME})

message(STATUS "Created targets for component ${NAME}.")

endfunction(create_component)
19 changes: 19 additions & 0 deletions cmake/lsp-datastructures.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set(LSP_METAMODEL_PATH ${CMAKE_CURRENT_BINARY_DIR}/metaModel.json)
set(LSP_DATASTRUCT_ROOT ${CMAKE_SOURCE_DIR}/lsp-server/include/types)
set(LSP_DATASTRUCT_CMAKE ${LSP_DATASTRUCT_ROOT}/generated_headers.cmake)

if(NOT EXISTS ${LSP_DATASTRUCT_CMAKE} OR NOT EXISTS ${LSP_METAMODEL_PATH})

message(STATUS "Regenerating LSP data structures using " ${LSP_METAMODEL_PATH})
file(
DOWNLOAD https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/metaModel/metaModel.json
${LSP_METAMODEL_PATH}
)

execute_process(COMMAND python3 ${CMAKE_SOURCE_DIR}/tools/LSPGen/main.py -fo ${LSP_DATASTRUCT_ROOT} ${LSP_METAMODEL_PATH})
message(STATUS "Regeneration done. ")

endif()

include(${LSP_DATASTRUCT_CMAKE})
list(TRANSFORM SVLS_GEN_HEADERS PREPEND ${LSP_DATASTRUCT_ROOT}/)
18 changes: 18 additions & 0 deletions cmake/sv-explorer.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

create_component(sv-explorer
LIB_SRC
PRIVATE explorer/hier_visitor.cpp
LIB_INC
INTERFACE explorer/
LIB_LINK
PUBLIC slang::slang
PUBLIC nlohmann_json::nlohmann_json
EXE_SRC
PRIVATE explorer/main.cpp
PRIVATE explorer/explorer_visitor.cpp
EXE_INC
PRIVATE utils/ast-printer
EXE_LINK
PRIVATE slang::slang
PRIVATE nlohmann_json::nlohmann_json
)
20 changes: 20 additions & 0 deletions cmake/sv-formatter.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
create_component(sv-formatter
LIB_SRC
PRIVATE formatter/format_DataDeclaration.cpp
PRIVATE formatter/spacing_manager.cpp
LIB_INC
INTERFACE formatter/
LIB_LINK
PUBLIC slang::slang
EXE_SRC
PRIVATE utils/ast-printer/ast_print.cpp
PRIVATE formatter/main_formatter.cpp
EXE_INC
PRIVATE utils/ast-printer
EXE_LINK
PRIVATE argparse::argparse
PRIVATE fmt::fmt
PRIVATE spdlog::spdlog
PRIVATE slang::slang
PRIVATE sv-formatter-lib
)
14 changes: 14 additions & 0 deletions cmake/sv-indexer.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
create_component(sv-indexer
LIB_SRC
PRIVATE indexer/index_elements.cpp
PRIVATE indexer/diplomat_index.cpp
PRIVATE indexer/visitor_index.cpp
LIB_INC
PUBLIC indexer/include
LIB_LINK
PUBLIC slang::slang
PUBLIC nlohmann_json::nlohmann_json
spdlog::spdlog
EXE_SRC
PRIVATE indexer/main_indexer.cpp
)
57 changes: 57 additions & 0 deletions cmake/third-party.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
include(FetchContent)

# Base library, might be used as dependencies for others


FetchContent_Declare(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
#GIT_TAG 10.2.1 # For correct management with slang
GIT_TAG 11.0.2
GIT_SHALLOW ON)

FetchContent_Declare(network
GIT_REPOSITORY https://github.com/fpagliughi/sockpp.git
GIT_TAG v1.0.0
GIT_SHALLOW ON)

FetchContent_Declare(spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.14.1
GIT_SHALLOW ON)

FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
GIT_SHALLOW ON)

FetchContent_Declare(uri
GIT_REPOSITORY https://github.com/ben-zen/uri-library.git
GIT_TAG 6b1b15a
GIT_SHALLOW OFF)

FetchContent_Declare(uuid
GIT_REPOSITORY https://github.com/mariusbancila/stduuid.git
GIT_TAG v1.2.3
GIT_SHALLOW ON)

# Core feature providers
FetchContent_Declare( slang
GIT_REPOSITORY https://github.com/MikePopoloski/slang.git
GIT_TAG v7.0
GIT_SHALLOW ON)


FetchContent_Declare(argparse
GIT_REPOSITORY https://github.com/p-ranav/argparse.git
GIT_TAG v3.1
GIT_SHALLOW ON)

FetchContent_MakeAvailable(uri)

# FetchContent_MakeAvailable(pgm-index)

FetchContent_MakeAvailable(fmt network uuid)
FetchContent_MakeAvailable(json spdlog)
FetchContent_MakeAvailable(argparse slang)

include_directories($<BUILD_INTERFACE:${uri_SOURCE_DIR}>)
Loading

0 comments on commit a748871

Please sign in to comment.