diff --git a/.github/scripts/macos-12/compile_build.sh b/.github/scripts/macos-12/compile_build.sh new file mode 100644 index 000000000..9d80b6180 --- /dev/null +++ b/.github/scripts/macos-12/compile_build.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# Compile dependencies that cannot be acquired via the official repositories + +mkdir -p ${INSTALL_PATH} + +## Compile Thrift +CXXFLAGS_OLD=$CXXFLAGS +LDFLAGS_OLD=$LDFLAGS +export CXXFLAGS="$CXXFLAGS -I/opt/homebrew/include" +export LDFLAGS="$LDFLAGS -L/opt/homebrew/lib" +export CXXFLAGS="$CXXFLAGS -Wno-error" + +tar -xvf ${DOWNLOAD_PATH}/thrift-0.16.0.tar.gz +cd thrift-0.16.0 +./configure --prefix=${INSTALL_PATH}/thrift --silent --without-python \ + --enable-libtool-lock --enable-tutorial=no --enable-tests=no \ + --with-libevent --with-zlib --without-nodejs --without-lua \ + --without-ruby --without-csharp --without-erlang --without-perl \ + --without-php --without-php_extension --without-dart \ + --without-haskell --without-go --without-rs --without-haxe \ + --without-dotnetcore --without-d --without-qt4 --without-qt5 \ + --without-java --without-swift \ + --with-openssl=/opt/homebrew/opt/openssl + +make install -j $(nproc) + +export CXXFLAGS=$CXXFLAGS_OLD +export LDFLAGS=$LDFLAGS_OLD + +## Compile build2 + +sh "${DOWNLOAD_PATH}/install_latest_build2.sh" ${INSTALL_PATH}/build2 + +## Compile libodb runtime libraries +mkdir -p ${DOWNLOAD_PATH}/libodb +cd ${DOWNLOAD_PATH}/libodb +${INSTALL_PATH}/build2/bin/bpkg create --quiet --jobs $(nproc) cc \ + config.cxx=g++ \ + config.cc.coptions=-O3 \ + config.bin.rpath=${INSTALL_PATH}/odb/lib \ + config.install.root=${INSTALL_PATH}/odb + +### Getting the source +${INSTALL_PATH}/build2/bin/bpkg add https://pkg.cppget.org/1/beta --trust-yes +${INSTALL_PATH}/build2/bin/bpkg fetch --trust-yes + +### Building ODB runtime library +${INSTALL_PATH}/build2/bin/bpkg build libodb --yes +${INSTALL_PATH}/build2/bin/bpkg build libodb-sqlite --yes +${INSTALL_PATH}/build2/bin/bpkg build libodb-pgsql --yes +${INSTALL_PATH}/build2/bin/bpkg install --all --recursive + +## Compile odb compiler +mkdir -p ${DOWNLOAD_PATH}/odb +cd ${DOWNLOAD_PATH}/odb +bpkg create --quiet --jobs $(nproc) cc \ + config.cxx=g++-13 \ + config.cc.poptions=-I/opt/homebrew/include \ + config.cc.coptions=-O3 \ + config.bin.rpath=${INSTALL_PATH}/odb/lib \ + config.install.root=${INSTALL_PATH}/odb + +### Getting the source +bpkg add https://pkg.cppget.org/1/beta --trust-yes +bpkg fetch --trust-yes + +### Building ODB Compiler +bpkg build odb --yes +bpkg install odb \ No newline at end of file diff --git a/.github/scripts/macos-12/download_build.sh b/.github/scripts/macos-12/download_build.sh new file mode 100644 index 000000000..6147ca878 --- /dev/null +++ b/.github/scripts/macos-12/download_build.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Download installers for compiled dependencies + +mkdir -p "${DOWNLOAD_PATH}" + +## Thrift 0.16 + +wget -O ${DOWNLOAD_PATH}/thrift-0.16.0.tar.gz "http://archive.apache.org/dist/thrift/0.16.0/thrift-0.16.0.tar.gz" + +## ODB + +wget -O "${DOWNLOAD_PATH}/install_latest_build2.sh" "https://github.com/Ericsson/CodeCompass/raw/master/scripts/install_latest_build2.sh" +build2_version=$(sh "${DOWNLOAD_PATH}/install_latest_build2.sh" --version) +odb_signature=$(wget -qO- https://pkg.cppget.org/1/beta/signature.manifest) + +# Calculate hash of dependencies for Github Cache Action + +dependencies_to_hash=("thrift-0.16.0.tar.gz") + +concatenated_hashes="" +for file in "${dependencies_to_hash[@]}"; do + file_hash=$(md5sum "${DOWNLOAD_PATH}/${file}" | awk '{print $1}') + concatenated_hashes="${concatenated_hashes}${file_hash}" +done +concatenated_hashes="${concatenated_hashes}${build2_version}${odb_signature}" + +hash_value=$(echo -n "$concatenated_hashes" | md5sum | awk '{print $1}') + +## Save said hash + +### Restore action +echo "macos-12-compile-hash-key=${hash_value}" >> "$GITHUB_OUTPUT" + +### Save action +echo "CACHE_KEY=${hash_value}" >> "$GITHUB_ENV" \ No newline at end of file diff --git a/.github/scripts/macos-12/postcompile_build.sh b/.github/scripts/macos-12/postcompile_build.sh new file mode 100644 index 000000000..48515d214 --- /dev/null +++ b/.github/scripts/macos-12/postcompile_build.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Post compilation configuration for building (environmental variables, library location settings etc..) + +echo "${INSTALL_PATH}/odb/bin" >> $GITHUB_PATH +echo "CMAKE_PREFIX_PATH=${INSTALL_PATH}/odb:$CMAKE_PREFIX_PATH" >> $GITHUB_ENV diff --git a/.github/scripts/macos-12/setup_build.sh b/.github/scripts/macos-12/setup_build.sh new file mode 100644 index 000000000..842a263f6 --- /dev/null +++ b/.github/scripts/macos-12/setup_build.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Install available dependencies from HomeBrew +brew install wget +brew install node +brew install sqlite +brew install cmake +brew install llvm@15 +brew install gcc +brew install boost +brew install bison +brew install graphviz +brew install googletest +brew install libgit2 +brew install libmagic +brew install openssl@3 +brew install gnu-sed +brew install coreutils + +# Place Bison on the PATH +echo "/opt/homebrew/opt/bison/bin" >> $GITHUB_PATH \ No newline at end of file diff --git a/.github/scripts/macos-12/setup_postgresql.sh b/.github/scripts/macos-12/setup_postgresql.sh new file mode 100644 index 000000000..406ba58e7 --- /dev/null +++ b/.github/scripts/macos-12/setup_postgresql.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Install PostgreSQL +brew install postgresql@14 \ No newline at end of file diff --git a/.github/scripts/macos-12/setup_sqlite3.sh b/.github/scripts/macos-12/setup_sqlite3.sh new file mode 100644 index 000000000..e881585eb --- /dev/null +++ b/.github/scripts/macos-12/setup_sqlite3.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Install SQLite3 +brew install sqlite \ No newline at end of file diff --git a/.github/scripts/ubuntu-22.04/postcompile_build.sh b/.github/scripts/ubuntu-22.04/postcompile_build.sh index c33212c69..48515d214 100755 --- a/.github/scripts/ubuntu-22.04/postcompile_build.sh +++ b/.github/scripts/ubuntu-22.04/postcompile_build.sh @@ -4,6 +4,3 @@ echo "${INSTALL_PATH}/odb/bin" >> $GITHUB_PATH echo "CMAKE_PREFIX_PATH=${INSTALL_PATH}/odb:$CMAKE_PREFIX_PATH" >> $GITHUB_ENV - -# Clean up dependency sources and intermediate binaries to save space -rm -rf ${DOWNLOAD_PATH}/odb \ No newline at end of file diff --git a/.github/scripts/ubuntu-22.04/setup_build.sh b/.github/scripts/ubuntu-22.04/setup_build.sh index 99627a015..3545d3bcf 100755 --- a/.github/scripts/ubuntu-22.04/setup_build.sh +++ b/.github/scripts/ubuntu-22.04/setup_build.sh @@ -1,5 +1,8 @@ #!/bin/bash +# Update package repository +sudo apt-get update + # Install required packages for CodeCompass build sudo apt install git cmake make g++ libboost-all-dev \ llvm-15-dev clang-15 libclang-15-dev \ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48364ba96..ac508bfe6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ env: BUILD_TYPE: RelWithDebInfo ## For locally compiled dependencies INSTALL_PATH: ${{github.workspace}}/dependencies/install - ## Temp directory for installers of the downloaded dependencies + # Temp directory for installers of the downloaded dependencies DOWNLOAD_PATH: ${{github.workspace}}/dependencies/download permissions: read-all @@ -17,7 +17,7 @@ jobs: strategy: matrix: db: [postgresql, sqlite3] - os: [ubuntu-22.04] + os: [ubuntu-22.04, macos-13] fail-fast: false runs-on: ${{ matrix.os }} @@ -45,9 +45,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Update apt-get - run: sudo apt-get update - - name: Install required packages for build run: ./.github/scripts/${{ matrix.os }}/setup_build.sh @@ -209,9 +206,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Update apt-get - run: sudo apt-get update - # We need build dependencies for CodeCompass, as it will parsed as well - name: Install required packages for build run: ./.github/scripts/${{ matrix.os }}/setup_build.sh 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/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()); 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_, 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