From 1a37acfe41a8e1dc9c17b5a73304c9ec5a224da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Cser=C3=A9p?= Date: Mon, 2 Oct 2023 02:32:48 +0200 Subject: [PATCH 1/4] Making the codebase compatible with macOS. --- CMakeLists.txt | 12 ++- FindGraphviz.cmake | 83 ++++++++++++++++ FindLibMagic.cmake | 99 +++++++++++++++++++ Functions.cmake | 2 + logger/src/ldlogger-util.h | 2 + model/include/model/buildaction.h | 1 + parser/CMakeLists.txt | 5 +- .../cpp/model/include/model/cppinheritance.h | 2 + plugins/cpp/parser/CMakeLists.txt | 7 ++ plugins/cpp/service/CMakeLists.txt | 9 +- plugins/cpp_metrics/service/CMakeLists.txt | 8 ++ plugins/cpp_reparse/service/CMakeLists.txt | 4 +- plugins/dummy/parser/CMakeLists.txt | 6 ++ plugins/dummy/service/CMakeLists.txt | 8 ++ plugins/git/parser/CMakeLists.txt | 4 +- plugins/git/service/CMakeLists.txt | 10 +- plugins/metrics/parser/CMakeLists.txt | 7 ++ plugins/metrics/service/CMakeLists.txt | 8 ++ plugins/search/indexer/CMakeLists.txt | 1 + plugins/search/parser/CMakeLists.txt | 12 ++- plugins/search/service/CMakeLists.txt | 1 + service/authentication/CMakeLists.txt | 8 ++ service/language/CMakeLists.txt | 1 + service/plugin/CMakeLists.txt | 8 ++ service/project/CMakeLists.txt | 8 ++ service/workspace/CMakeLists.txt | 8 ++ util/CMakeLists.txt | 16 +-- util/src/dynamiclibrary.cpp | 2 + util/src/pipedprocess.cpp | 6 ++ webserver/CMakeLists.txt | 14 ++- webserver/src/threadedmongoose.h | 5 + 31 files changed, 341 insertions(+), 26 deletions(-) create mode 100644 FindGraphviz.cmake create mode 100644 FindLibMagic.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 72f8bda3a..2757b3439 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,11 +10,13 @@ include(Functions.cmake) # Do some sanity check on the testing setup and enable testing if applicable. include(Testing.cmake) -find_package(Boost REQUIRED COMPONENTS filesystem log program_options regex system thread) -find_package(Java REQUIRED) -find_package(ODB REQUIRED) -find_package(Threads REQUIRED) -find_package(Thrift REQUIRED) +find_package(Boost REQUIRED COMPONENTS filesystem log program_options regex system thread) +find_package(Java REQUIRED) +find_package(ODB REQUIRED) +find_package(Threads REQUIRED) +find_package(Thrift REQUIRED) +find_package(Graphviz REQUIRED) +find_package(LibMagic REQUIRED) find_package(GTest) include(UseJava) diff --git a/FindGraphviz.cmake b/FindGraphviz.cmake new file mode 100644 index 000000000..ed3bebabd --- /dev/null +++ b/FindGraphviz.cmake @@ -0,0 +1,83 @@ +# - Try to find Graphviz +# Once done this will define +# +# GRAPHVIZ_FOUND - system has Graphviz +# GRAPHVIZ_INCLUDE_DIRS - Graphviz include directories +# GRAPHVIZ_CDT_LIBRARY - Graphviz CDT library +# GRAPHVIZ_GVC_LIBRARY - Graphviz GVC library +# GRAPHVIZ_CGRAPH_LIBRARY - Graphviz CGRAPH library +# GRAPHVIZ_PATHPLAN_LIBRARY - Graphviz PATHPLAN library +# GRAPHVIZ_VERSION - Graphviz version +# +# This module reads hints about search locations from the following cmake variables: +# GRAPHVIZ_ROOT - Graphviz installation prefix +# (containing bin/, include/, etc.) + +# Copyright (c) 2009, Adrien Bustany, +# Copyright (c) 2013-2014 Kevin Funk + +# Version computation and some cleanups by Allen Winter +# Copyright (c) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company + +# Simplified script by Dogan Can +# Copyright (c) 2014 University of Southern California + +# Redistribution and use is allowed according to the terms of the GPLv3+ license. +# Source: https://github.com/usc-sail/barista/blob/master/cmake/FindGraphviz.cmake + +if(GRAPHVIZ_ROOT) + set(_GRAPHVIZ_INCLUDE_DIR ${GRAPHVIZ_ROOT}/include) + set(_GRAPHVIZ_LIBRARY_DIR ${GRAPHVIZ_ROOT}/lib) +endif() + +find_path(GRAPHVIZ_INCLUDE_DIR NAMES graphviz/cgraph.h + HINTS ${_GRAPHVIZ_INCLUDE_DIR}) +find_library(GRAPHVIZ_CDT_LIBRARY NAMES cdt + HINTS ${_GRAPHVIZ_LIBRARY_DIR}) +find_library(GRAPHVIZ_GVC_LIBRARY NAMES gvc + HINTS ${_GRAPHVIZ_LIBRARY_DIR}) +find_library(GRAPHVIZ_CGRAPH_LIBRARY NAMES cgraph + HINTS ${_GRAPHVIZ_LIBRARY_DIR}) +find_library(GRAPHVIZ_PATHPLAN_LIBRARY NAMES pathplan + HINTS ${_GRAPHVIZ_LIBRARY_DIR}) + +if(GRAPHVIZ_INCLUDE_DIR AND GRAPHVIZ_CDT_LIBRARY AND GRAPHVIZ_GVC_LIBRARY + AND GRAPHVIZ_CGRAPH_LIBRARY AND GRAPHVIZ_PATHPLAN_LIBRARY) + set(GRAPHVIZ_FOUND TRUE) +else() + set(GRAPHVIZ_FOUND FALSE) +endif() + +# Ok, now compute the version +if(GRAPHVIZ_FOUND) + set(FIND_GRAPHVIZ_VERSION_SOURCE + "#include \n#include \n int main()\n {\n printf(\"%s\",PACKAGE_VERSION);return 1;\n }\n") + set(FIND_GRAPHVIZ_VERSION_SOURCE_FILE ${CMAKE_BINARY_DIR}/CMakeTmp/FindGRAPHVIZ.cxx) + file(WRITE "${FIND_GRAPHVIZ_VERSION_SOURCE_FILE}" "${FIND_GRAPHVIZ_VERSION_SOURCE}") + + set(FIND_GRAPHVIZ_VERSION_ADD_INCLUDES + "-DINCLUDE_DIRECTORIES:STRING=${GRAPHVIZ_INCLUDE_DIR}") + + try_run(RUN_RESULT COMPILE_RESULT + ${CMAKE_BINARY_DIR} + ${FIND_GRAPHVIZ_VERSION_SOURCE_FILE} + CMAKE_FLAGS "${FIND_GRAPHVIZ_VERSION_ADD_INCLUDES}" + RUN_OUTPUT_VARIABLE GRAPHVIZ_VERSION) + + if(COMPILE_RESULT AND RUN_RESULT EQUAL 1) + message(STATUS "Graphviz version: ${GRAPHVIZ_VERSION}") + else() + message(FATAL_ERROR "Unable to compile or run the graphviz version detection program.") + endif() + + set(GRAPHVIZ_INCLUDE_DIRS ${GRAPHVIZ_INCLUDE_DIR} ${GRAPHVIZ_INCLUDE_DIR}/graphviz) + + if(NOT Graphviz_FIND_QUIETLY) + message(STATUS "Graphviz include: ${GRAPHVIZ_INCLUDE_DIRS}") + message(STATUS "Graphviz libraries: ${GRAPHVIZ_CDT_LIBRARY} ${GRAPHVIZ_GVC_LIBRARY} ${GRAPHVIZ_CGRAPH_LIBRARY} ${GRAPHVIZ_PATHPLAN_LIBRARY}") + endif() +endif() + +if(Graphviz_FIND_REQUIRED AND NOT GRAPHVIZ_FOUND) + message(FATAL_ERROR "Could not find GraphViz.") +endif() diff --git a/FindLibMagic.cmake b/FindLibMagic.cmake new file mode 100644 index 000000000..3ced744ec --- /dev/null +++ b/FindLibMagic.cmake @@ -0,0 +1,99 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2013-2013, Lars Baehren +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#------------------------------------------------------------------------------- + +# - Check for the presence of LIBMAGIC +# +# The following variables are set when LIBMAGIC is found: +# LIBMAGIC_FOUND = Set to true, if all components of LIBMAGIC have been +# found. +# LIBMAGIC_INCLUDES = Include path for the header files of LIBMAGIC +# LIBMAGIC_LIBRARIES = Link these to use LIBMAGIC +# LIBMAGIC_LFLAGS = Linker flags (optional) + +if (NOT LIBMAGIC_FOUND) + + if (NOT LIBMAGIC_ROOT_DIR) + set (LIBMAGIC_ROOT_DIR ${CMAKE_INSTALL_PREFIX}) + endif (NOT LIBMAGIC_ROOT_DIR) + + ##____________________________________________________________________________ + ## Check for the header files + + find_path (LIBMAGIC_FILE_H + NAMES file/file.h + HINTS ${LIBMAGIC_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} + PATH_SUFFIXES include + ) + if (LIBMAGIC_FILE_H) + list (APPEND LIBMAGIC_INCLUDES ${LIBMAGIC_FILE_H}) + endif (LIBMAGIC_FILE_H) + + find_path (LIBMAGIC_MAGIC_H + NAMES magic.h + HINTS ${LIBMAGIC_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} + PATH_SUFFIXES include include/linux + ) + if (LIBMAGIC_MAGIC_H) + list (APPEND LIBMAGIC_INCLUDES ${LIBMAGIC_MAGIC_H}) + endif (LIBMAGIC_MAGIC_H) + + list (REMOVE_DUPLICATES LIBMAGIC_INCLUDES) + + ##____________________________________________________________________________ + ## Check for the library + + find_library (LIBMAGIC_LIBRARIES magic + HINTS ${LIBMAGIC_ROOT_DIR} ${CMAKE_INSTALL_PREFIX} + PATH_SUFFIXES lib + ) + + ##____________________________________________________________________________ + ## Actions taken when all components have been found + + find_package_handle_standard_args (LIBMAGIC DEFAULT_MSG LIBMAGIC_LIBRARIES LIBMAGIC_INCLUDES) + + if (LIBMAGIC_FOUND) + if (NOT LIBMAGIC_FIND_QUIETLY) + message (STATUS "Found components for LIBMAGIC") + message (STATUS "LIBMAGIC_ROOT_DIR = ${LIBMAGIC_ROOT_DIR}") + message (STATUS "LIBMAGIC_INCLUDES = ${LIBMAGIC_INCLUDES}") + message (STATUS "LIBMAGIC_LIBRARIES = ${LIBMAGIC_LIBRARIES}") + endif (NOT LIBMAGIC_FIND_QUIETLY) + else (LIBMAGIC_FOUND) + if (LIBMAGIC_FIND_REQUIRED) + message (FATAL_ERROR "Could not find LIBMAGIC!") + endif (LIBMAGIC_FIND_REQUIRED) + endif (LIBMAGIC_FOUND) + + ##____________________________________________________________________________ + ## Mark advanced variables + + mark_as_advanced ( + LIBMAGIC_ROOT_DIR + LIBMAGIC_INCLUDES + LIBMAGIC_LIBRARIES + ) + +endif (NOT LIBMAGIC_FOUND) \ No newline at end of file diff --git a/Functions.cmake b/Functions.cmake index 1d2dd3c6a..3ece8ab66 100644 --- a/Functions.cmake +++ b/Functions.cmake @@ -29,6 +29,7 @@ function(generate_odb_files _src) -I ${CMAKE_SOURCE_DIR}/model/include -I ${CMAKE_SOURCE_DIR}/util/include -I ${ODB_INCLUDE_DIRS} + -I ${Boost_INCLUDE_DIRS} ${DEPENDENCY_PLUGIN_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/${_file} COMMAND @@ -51,6 +52,7 @@ function(add_odb_library _name) target_link_libraries(${_name} ${ODB_LIBRARIES}) target_include_directories(${_name} PUBLIC ${ODB_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/util/include ${CMAKE_SOURCE_DIR}/model/include ${CMAKE_CURRENT_SOURCE_DIR}/include diff --git a/logger/src/ldlogger-util.h b/logger/src/ldlogger-util.h index 47952178c..aa8fcabdb 100644 --- a/logger/src/ldlogger-util.h +++ b/logger/src/ldlogger-util.h @@ -2,7 +2,9 @@ #define CC_LOGGER_UTIL_H #include +#ifdef __linux__ #include +#endif #include /** diff --git a/model/include/model/buildaction.h b/model/include/model/buildaction.h index 382ca817a..cc42ed562 100644 --- a/model/include/model/buildaction.h +++ b/model/include/model/buildaction.h @@ -1,6 +1,7 @@ #ifndef CC_MODEL_BUILDACTION_H #define CC_MODEL_BUILDACTION_H +#include #include #include #include diff --git a/parser/CMakeLists.txt b/parser/CMakeLists.txt index ce7024d7d..04e3fec92 100644 --- a/parser/CMakeLists.txt +++ b/parser/CMakeLists.txt @@ -4,7 +4,8 @@ include_directories( ${PROJECT_SOURCE_DIR}/model/include) include_directories(SYSTEM - ${ODB_INCLUDE_DIRS}) + ${ODB_INCLUDE_DIRS} + ${LIBMAGIC_INCLUDES}) add_executable(CodeCompass_parser src/pluginhandler.cpp @@ -21,7 +22,7 @@ target_link_libraries(CodeCompass_parser ${Boost_LIBRARIES} ${ODB_LIBRARIES} ${CMAKE_DL_LIBS} - magic + ${LIBMAGIC_LIBRARIES} pthread) install(TARGETS CodeCompass_parser diff --git a/plugins/cpp/model/include/model/cppinheritance.h b/plugins/cpp/model/include/model/cppinheritance.h index 286b378f5..17f98e41e 100644 --- a/plugins/cpp/model/include/model/cppinheritance.h +++ b/plugins/cpp/model/include/model/cppinheritance.h @@ -2,6 +2,8 @@ #define CC_MODEL_CPPINHERITANCE_H #include +#include + #include "common.h" namespace cc diff --git a/plugins/cpp/parser/CMakeLists.txt b/plugins/cpp/parser/CMakeLists.txt index 43c2cffb6..a8ae2fc74 100644 --- a/plugins/cpp/parser/CMakeLists.txt +++ b/plugins/cpp/parser/CMakeLists.txt @@ -66,6 +66,13 @@ target_link_libraries(cppparser target_compile_options(cppparser PUBLIC -Wno-unknown-pragmas) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # cppparser references headers from the parser without implementation + set_target_properties(cppparser PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS cppparser DESTINATION ${INSTALL_PARSER_DIR}) # Install Clang additional files diff --git a/plugins/cpp/service/CMakeLists.txt b/plugins/cpp/service/CMakeLists.txt index f5d7f9e13..fa4f7a335 100644 --- a/plugins/cpp/service/CMakeLists.txt +++ b/plugins/cpp/service/CMakeLists.txt @@ -26,7 +26,14 @@ target_link_libraries(cppservice mongoose projectservice languagethrift - gvc + ${GRAPHVIZ_GVC_LIBRARY} ${THRIFT_LIBTHRIFT_LIBRARIES}) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # cppservice references headers from the webserver without implementation + set_target_properties(cppservice PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS cppservice DESTINATION ${INSTALL_SERVICE_DIR}) diff --git a/plugins/cpp_metrics/service/CMakeLists.txt b/plugins/cpp_metrics/service/CMakeLists.txt index dbdd2fe0b..bcc1175e0 100644 --- a/plugins/cpp_metrics/service/CMakeLists.txt +++ b/plugins/cpp_metrics/service/CMakeLists.txt @@ -10,6 +10,7 @@ include_directories( ${PROJECT_SOURCE_DIR}/webserver/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) add_custom_command( @@ -55,5 +56,12 @@ target_link_libraries(cxxmetricsservice ${ODB_LIBRARIES} cxxmetricsthrift) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # cppmetricsservice references headers from the webserver without implementation + set_target_properties(cxxmetricsservice PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS cxxmetricsservice DESTINATION ${INSTALL_SERVICE_DIR}) install_js_thrift() diff --git a/plugins/cpp_reparse/service/CMakeLists.txt b/plugins/cpp_reparse/service/CMakeLists.txt index 80ab2fb11..5327ea7a3 100644 --- a/plugins/cpp_reparse/service/CMakeLists.txt +++ b/plugins/cpp_reparse/service/CMakeLists.txt @@ -13,6 +13,7 @@ include_directories( ${cpp_PLUGIN_DIR}/parser/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS}) @@ -69,8 +70,7 @@ target_link_libraries(cppreparseservice clangFrontend clangBasic clangAST - clang - ) + clang) install(TARGETS cppreparseservice DESTINATION ${INSTALL_SERVICE_DIR}) install_js_thrift() diff --git a/plugins/dummy/parser/CMakeLists.txt b/plugins/dummy/parser/CMakeLists.txt index 8542e1aba..43e8b0687 100644 --- a/plugins/dummy/parser/CMakeLists.txt +++ b/plugins/dummy/parser/CMakeLists.txt @@ -4,9 +4,15 @@ include_directories( ${PROJECT_SOURCE_DIR}/util/include ${PROJECT_SOURCE_DIR}/parser/include) +include_directories(SYSTEM + ${Boost_INCLUDE_DIRS}) + add_library(dummyparser SHARED src/dummyparser.cpp) target_compile_options(dummyparser PUBLIC -Wno-unknown-pragmas) +target_link_libraries(dummyparser + ${Boost_LIBRARIES}) + install(TARGETS dummyparser DESTINATION ${INSTALL_PARSER_DIR}) diff --git a/plugins/dummy/service/CMakeLists.txt b/plugins/dummy/service/CMakeLists.txt index 2243f91c9..bca4c0473 100644 --- a/plugins/dummy/service/CMakeLists.txt +++ b/plugins/dummy/service/CMakeLists.txt @@ -5,6 +5,7 @@ include_directories( ${PROJECT_SOURCE_DIR}/webserver/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) add_custom_command( @@ -38,4 +39,11 @@ target_link_libraries(dummyservice ${ODB_LIBRARIES} dummythrift) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # dummyservice references headers from the webserver without implementation + set_target_properties(dummyservice PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS dummyservice DESTINATION ${INSTALL_SERVICE_DIR}) diff --git a/plugins/git/parser/CMakeLists.txt b/plugins/git/parser/CMakeLists.txt index ffb924eb6..0b0d67f81 100644 --- a/plugins/git/parser/CMakeLists.txt +++ b/plugins/git/parser/CMakeLists.txt @@ -10,7 +10,7 @@ target_compile_options(gitparser PUBLIC -Wno-unknown-pragmas) target_link_libraries(gitparser util - git2 - ssl) + ${LIBGIT2_LIBRARIES} + ${OPENSSL_SSL_LIBRARY}) install(TARGETS gitparser DESTINATION ${INSTALL_PARSER_DIR}) diff --git a/plugins/git/service/CMakeLists.txt b/plugins/git/service/CMakeLists.txt index bba6dd046..0a09577ec 100644 --- a/plugins/git/service/CMakeLists.txt +++ b/plugins/git/service/CMakeLists.txt @@ -9,6 +9,7 @@ include_directories( ${PLUGIN_DIR}/model/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) add_custom_command( @@ -46,7 +47,14 @@ target_link_libraries(gitservice ${THRIFT_LIBTHRIFT_LIBRARIES} ${ODB_LIBRARIES} gitthrift - git2) + ${LIBGIT2_LIBRARIES}) + +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # gitservice references headers from the webserver without implementation + set_target_properties(gitservice PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) install(TARGETS gitservice DESTINATION ${INSTALL_SERVICE_DIR}) install_js_thrift() diff --git a/plugins/metrics/parser/CMakeLists.txt b/plugins/metrics/parser/CMakeLists.txt index 80485ce0f..b340c1519 100644 --- a/plugins/metrics/parser/CMakeLists.txt +++ b/plugins/metrics/parser/CMakeLists.txt @@ -13,6 +13,13 @@ target_link_libraries(metricsparser util ${Boost_LIBRARIES}) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # metricsparser references headers from the parser without implementation + set_target_properties(metricsparser PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS metricsparser LIBRARY DESTINATION ${INSTALL_LIB_DIR} DESTINATION ${INSTALL_PARSER_DIR}) diff --git a/plugins/metrics/service/CMakeLists.txt b/plugins/metrics/service/CMakeLists.txt index 977485b01..665cb8a26 100644 --- a/plugins/metrics/service/CMakeLists.txt +++ b/plugins/metrics/service/CMakeLists.txt @@ -8,6 +8,7 @@ include_directories( ${PROJECT_SOURCE_DIR}/webserver/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) add_custom_command( @@ -49,5 +50,12 @@ target_link_libraries(metricsservice commonthrift metricsthrift) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # metricsservice references headers from the webserver without implementation + set_target_properties(metricsservice PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS metricsservice DESTINATION ${INSTALL_SERVICE_DIR}) install_js_thrift() diff --git a/plugins/search/indexer/CMakeLists.txt b/plugins/search/indexer/CMakeLists.txt index a1f002c40..c531551ef 100644 --- a/plugins/search/indexer/CMakeLists.txt +++ b/plugins/search/indexer/CMakeLists.txt @@ -4,6 +4,7 @@ include_directories( ${PROJECT_SOURCE_DIR}/util/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) add_custom_command( diff --git a/plugins/search/parser/CMakeLists.txt b/plugins/search/parser/CMakeLists.txt index 28e125888..52f2a2308 100644 --- a/plugins/search/parser/CMakeLists.txt +++ b/plugins/search/parser/CMakeLists.txt @@ -8,14 +8,22 @@ include_directories( ${PLUGIN_DIR}/indexer/include) include_directories(SYSTEM - ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) + ${THRIFT_LIBTHRIFT_INCLUDE_DIRS} + ${LIBMAGIC_INCLUDES}) add_library(searchparser SHARED src/searchparser.cpp) target_link_libraries(searchparser util - magic + ${LIBMAGIC_LIBRARIES} indexerservice) target_compile_options(searchparser PUBLIC -Wno-unknown-pragmas) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # searchparser references headers from the parser without implementation + set_target_properties(searchparser PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS searchparser DESTINATION ${INSTALL_PARSER_DIR}) diff --git a/plugins/search/service/CMakeLists.txt b/plugins/search/service/CMakeLists.txt index 955c5fea1..58f813893 100644 --- a/plugins/search/service/CMakeLists.txt +++ b/plugins/search/service/CMakeLists.txt @@ -9,6 +9,7 @@ include_directories( ${PLUGIN_DIR}/model/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) # Generate thrift files diff --git a/service/authentication/CMakeLists.txt b/service/authentication/CMakeLists.txt index 50b9f483c..16fe0f2b6 100644 --- a/service/authentication/CMakeLists.txt +++ b/service/authentication/CMakeLists.txt @@ -5,6 +5,7 @@ include_directories( ${PROJECT_SOURCE_DIR}/webserver/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) add_custom_command( @@ -41,5 +42,12 @@ target_link_libraries(authenticationservice ${THRIFT_LIBTHRIFT_LIBRARIES} authenticationthrift) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # authenticationservice references headers from the webserver without implementation + set_target_properties(authenticationservice PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS authenticationservice DESTINATION ${INSTALL_SERVICE_DIR}) install_js_thrift() diff --git a/service/language/CMakeLists.txt b/service/language/CMakeLists.txt index 522038ec6..41e57edbd 100644 --- a/service/language/CMakeLists.txt +++ b/service/language/CMakeLists.txt @@ -2,6 +2,7 @@ include_directories( ${PROJECT_BINARY_DIR}/service/project/gen-cpp) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) add_custom_command( diff --git a/service/plugin/CMakeLists.txt b/service/plugin/CMakeLists.txt index a9e387fb2..1044b16c1 100644 --- a/service/plugin/CMakeLists.txt +++ b/service/plugin/CMakeLists.txt @@ -5,6 +5,7 @@ include_directories( ${PROJECT_SOURCE_DIR}/util/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) add_custom_command( @@ -36,5 +37,12 @@ target_link_libraries(pluginservice ${THRIFT_LIBTHRIFT_LIBRARIES} pluginthrift) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # pluginservice references headers from the webserver without implementation + set_target_properties(pluginservice PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS pluginservice DESTINATION ${INSTALL_SERVICE_DIR}) install_js_thrift() diff --git a/service/project/CMakeLists.txt b/service/project/CMakeLists.txt index 974720905..0f60ba9e9 100644 --- a/service/project/CMakeLists.txt +++ b/service/project/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories( ${PROJECT_SOURCE_DIR}/webserver/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS} ${ODB_INCLUDE_DIRS}) @@ -84,6 +85,13 @@ target_link_libraries(projectservice projectthrift commonthrift) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # projectservice references headers from the webserver without implementation + set_target_properties(projectservice PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS projectservice DESTINATION ${INSTALL_SERVICE_DIR}) install_jar(corethriftjava "${INSTALL_JAVA_LIB_DIR}") install_js_thrift() diff --git a/service/workspace/CMakeLists.txt b/service/workspace/CMakeLists.txt index 702bd1c7b..62b9dea8d 100644 --- a/service/workspace/CMakeLists.txt +++ b/service/workspace/CMakeLists.txt @@ -5,6 +5,7 @@ include_directories( ${PROJECT_SOURCE_DIR}/webserver/include) include_directories(SYSTEM + ${Boost_INCLUDE_DIRS} ${THRIFT_LIBTHRIFT_INCLUDE_DIRS}) add_custom_command( @@ -39,5 +40,12 @@ target_link_libraries(workspaceservice ${THRIFT_LIBTHRIFT_LIBRARIES} workspacethrift) +if(APPLE) + # Use Linux-like linking behaviour, dynamic libraries may contain references without implementation. + # workspaceservice references headers from the webserver without implementation + set_target_properties(workspaceservice PROPERTIES LINK_FLAGS + "-undefined dynamic_lookup") +endif(APPLE) + install(TARGETS workspaceservice DESTINATION ${INSTALL_SERVICE_DIR}) install_js_thrift() diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index b8cbabe2e..64ace7dfd 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -1,10 +1,11 @@ include_directories( ${PROJECT_SOURCE_DIR}/util/include - ${PROJECT_SOURCE_DIR}/model/include - ${BOOST_INCLUDE_DIRS}) + ${PROJECT_SOURCE_DIR}/model/include) include_directories(SYSTEM - ${ODB_INCLUDE_DIRS}) + ${Boost_INCLUDE_DIRS} + ${ODB_INCLUDE_DIRS} + ${GRAPHVIZ_INCLUDE_DIRS}) add_library(util SHARED src/dbutil.cpp @@ -19,13 +20,16 @@ add_library(util SHARED target_link_libraries(util model - gvc - ${Boost_LIBRARIES}) + ${Boost_LIBRARIES} + ${ODB_LIBRARIES} + ${GRAPHVIZ_GVC_LIBRARY} + ${GRAPHVIZ_CGRAPH_LIBRARY}) string(TOLOWER "${DATABASE}" _database) if (${_database} STREQUAL "sqlite") + find_package(SQLite3) target_link_libraries(util - sqlite3) + ${SQLite3_LIBRARIES}) endif() install(TARGETS util DESTINATION ${INSTALL_LIB_DIR}) diff --git a/util/src/dynamiclibrary.cpp b/util/src/dynamiclibrary.cpp index 251af2268..33171b443 100644 --- a/util/src/dynamiclibrary.cpp +++ b/util/src/dynamiclibrary.cpp @@ -9,6 +9,8 @@ std::string DynamicLibrary::extension() { #ifdef WIN32 return ".dll"; +#elif __APPLE__ + return ".dylib"; #else return ".so"; #endif diff --git a/util/src/pipedprocess.cpp b/util/src/pipedprocess.cpp index 9c9046f57..31c01c96d 100644 --- a/util/src/pipedprocess.cpp +++ b/util/src/pipedprocess.cpp @@ -3,7 +3,10 @@ #include #include #include + +#if __linux__ #include +#endif namespace cc { @@ -75,10 +78,13 @@ int PipedProcess::startProcess(bool dieWithMe_) throw Failure("fork failed!"); } +#if __linux__ + // prctl.h is not available on macOS if (_childPid == 0 && dieWithMe_) { ::prctl(PR_SET_PDEATHSIG, SIGTERM); } +#endif return _childPid; } diff --git a/webserver/CMakeLists.txt b/webserver/CMakeLists.txt index 534f4a341..ac075eac8 100644 --- a/webserver/CMakeLists.txt +++ b/webserver/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(OpenSSL) + add_subdirectory(authenticators) add_executable(CodeCompass_webserver @@ -11,11 +13,13 @@ add_executable(CodeCompass_webserver set_target_properties(CodeCompass_webserver PROPERTIES ENABLE_EXPORTS 1) -add_library(mongoose STATIC src/mongoose.c ) +add_library(mongoose STATIC src/mongoose.c) target_compile_definitions(mongoose PRIVATE -DNS_ENABLE_SSL) -target_include_directories(mongoose PUBLIC include) +target_include_directories(mongoose PUBLIC + include + ${OPENSSL_INCLUDE_DIR}) target_compile_options(mongoose PUBLIC -fPIC) -target_link_libraries(mongoose PRIVATE ssl) +target_link_libraries(mongoose PRIVATE ${OPENSSL_SSL_LIBRARY}) target_include_directories(CodeCompass_webserver PUBLIC include @@ -27,8 +31,8 @@ target_link_libraries(CodeCompass_webserver mongoose ${Boost_LIBRARIES} ${ODB_LIBRARIES} - pthread - dl) + ${LIBMAGIC_LIBRARIES} + pthread) install(TARGETS CodeCompass_webserver RUNTIME DESTINATION ${INSTALL_BIN_DIR} diff --git a/webserver/src/threadedmongoose.h b/webserver/src/threadedmongoose.h index 810b55fcd..f64e0920b 100644 --- a/webserver/src/threadedmongoose.h +++ b/webserver/src/threadedmongoose.h @@ -12,6 +12,11 @@ #include +#if __APPLE__ +// Not included in signal.h for macOS, as it is a GNU extension +typedef void (* sighandler_t)(int); +#endif + namespace cc { namespace webserver From 5164845e3900bb298d73d3ed0678bf95d9a5632c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Cser=C3=A9p?= Date: Tue, 9 Apr 2024 05:43:46 +0200 Subject: [PATCH 2/4] Disable macro expansion in C++ plugin. --- plugins/cpp/parser/src/ppmacrocallback.cpp | 8 ++++---- plugins/cpp/parser/src/ppmacrocallback.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/cpp/parser/src/ppmacrocallback.cpp b/plugins/cpp/parser/src/ppmacrocallback.cpp index d86532e32..2089d6bfd 100644 --- a/plugins/cpp/parser/src/ppmacrocallback.cpp +++ b/plugins/cpp/parser/src/ppmacrocallback.cpp @@ -35,7 +35,7 @@ PPMacroCallback::~PPMacroCallback() }); } -void PPMacroCallback::MacroExpands( +/*void PPMacroCallback::MacroExpands( const clang::Token& macroNameTok_, const clang::MacroDefinition& md_, clang::SourceRange range_, @@ -121,9 +121,9 @@ void PPMacroCallback::MacroExpands( expansion += _pp.getSpelling(tok); else { - expansion += "/*< FIXME: "; + expansion += "/ *< FIXME: "; expansion += tok.getName(); - expansion += " token not expanded. >*/"; + expansion += " token not expanded. >* /"; } _pp.Lex(tok); } @@ -146,7 +146,7 @@ void PPMacroCallback::MacroExpands( _macrosExpansion.push_back(mExp); } -} +}*/ void PPMacroCallback::MacroDefined( const clang::Token& macroNameTok_, diff --git a/plugins/cpp/parser/src/ppmacrocallback.h b/plugins/cpp/parser/src/ppmacrocallback.h index 224cfe27b..2bb4e8fb8 100644 --- a/plugins/cpp/parser/src/ppmacrocallback.h +++ b/plugins/cpp/parser/src/ppmacrocallback.h @@ -34,11 +34,11 @@ class PPMacroCallback : public clang::PPCallbacks ~PPMacroCallback(); - virtual void MacroExpands( + /*virtual void MacroExpands( const clang::Token& macroNameTok_, const clang::MacroDefinition& md_, clang::SourceRange range_, - const clang::MacroArgs* args_) override; + const clang::MacroArgs* args_) override;*/ virtual void MacroDefined( const clang::Token& macroNameTok_, From 48454ba94d31feeec50c2a461050cd302ce17744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Cser=C3=A9p?= Date: Tue, 9 Apr 2024 06:36:13 +0200 Subject: [PATCH 3/4] Skip parsing Objective-C++ files as standard C++. --- plugins/cpp/parser/include/cppparser/cppparser.h | 1 + plugins/cpp/parser/src/cppparser.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/cpp/parser/include/cppparser/cppparser.h b/plugins/cpp/parser/include/cppparser/cppparser.h index fa6d10d29..db43ba2fa 100644 --- a/plugins/cpp/parser/include/cppparser/cppparser.h +++ b/plugins/cpp/parser/include/cppparser/cppparser.h @@ -103,6 +103,7 @@ class CppParser : public AbstractParser bool isParsed(const clang::tooling::CompileCommand& command_); bool isSourceFile(const std::string& file_) const; bool isNonSourceFlag(const std::string& arg_) const; + bool isObjectiveCpp(const clang::tooling::CompileCommand& command_) const; bool parseByJson(const std::string& jsonFile_, std::size_t threadNum_); int parseWorker(const clang::tooling::CompileCommand& command_); diff --git a/plugins/cpp/parser/src/cppparser.cpp b/plugins/cpp/parser/src/cppparser.cpp index 9af9704b8..34dbdc745 100644 --- a/plugins/cpp/parser/src/cppparser.cpp +++ b/plugins/cpp/parser/src/cppparser.cpp @@ -170,6 +170,16 @@ bool CppParser::isNonSourceFlag(const std::string& arg_) const return arg_.find("-Wl,") == 0; } +bool CppParser::isObjectiveCpp(const clang::tooling::CompileCommand& command_) const +{ + for (std::size_t i = 1; i < command_.CommandLine.size(); ++i) + { + if (command_.CommandLine[i - 1] == "-x" && command_.CommandLine[i] == "objective-c++") + return true; + } + return false; +} + std::map CppParser::extractInputOutputs( const clang::tooling::CompileCommand& command_) const { @@ -755,7 +765,7 @@ bool CppParser::parseByJson( std::remove_if(compileCommands.begin(), compileCommands.end(), [&](const clang::tooling::CompileCommand& c) { - return !isSourceFile(c.Filename); + return !isSourceFile(c.Filename) || isObjectiveCpp(c); }), compileCommands.end()); From 3a49dcc659c9e454108fbf7f791993a35b9b154c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Cser=C3=A9p?= Date: Mon, 26 May 2025 12:58:55 +0200 Subject: [PATCH 4/4] Make the codebase compatible with Boost 1.86. --- util/include/util/hash.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/util/include/util/hash.h b/util/include/util/hash.h index f7f308ada..3856cd28d 100644 --- a/util/include/util/hash.h +++ b/util/include/util/hash.h @@ -36,7 +36,7 @@ inline std::string sha1Hash(const std::string& data_) using namespace boost::uuids::detail; sha1 hasher; - unsigned int digest[5]; + boost::uuids::detail::sha1::digest_type digest; hasher.process_bytes(data_.c_str(), data_.size()); hasher.get_digest(digest); @@ -46,8 +46,23 @@ inline std::string sha1Hash(const std::string& data_) ss.width(8); ss.fill('0'); + // To ensure correct output, especially for newer Boost versions where digest might be treated as 20 bytes, + // we explicitly cast the relevant 4 bytes into a uint32_t. + // For older Boost, digest[i] is already a uint32_t. + // For newer Boost, digest is a uint8_t[20]. We need to reconstruct the 32-bit values. +#if BOOST_VERSION >= 108600 /* 1.86.0 */ + for (int i = 0; i < 5; ++i) + { + uint32_t part = (static_cast(digest[i * 4]) << 24) | + (static_cast(digest[i * 4 + 1]) << 16) | + (static_cast(digest[i * 4 + 2]) << 8) | + static_cast(digest[i * 4 + 3]); + ss << part; + } +#else for (int i = 0; i < 5; ++i) ss << digest[i]; +#endif return ss.str(); }