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-20.04/postcompile_build.sh b/.github/scripts/ubuntu-20.04/postcompile_build.sh index 8b071bdf8..4769932cb 100644 --- a/.github/scripts/ubuntu-20.04/postcompile_build.sh +++ b/.github/scripts/ubuntu-20.04/postcompile_build.sh @@ -2,7 +2,3 @@ echo "${INSTALL_PATH}/thrift/bin" >> $GITHUB_PATH echo "CMAKE_PREFIX_PATH=${INSTALL_PATH}/thrift:$CMAKE_PREFIX_PATH" >> $GITHUB_ENV - -# Clean up dependency sources and intermediate binaries to save space -rm -f ${DOWNLOAD_PATH}/thrift-0.16.0.tar.gz -rm -rf ${DOWNLOAD_PATH}/thrift-0.16.0/ \ No newline at end of file diff --git a/.github/scripts/ubuntu-20.04/setup_build.sh b/.github/scripts/ubuntu-20.04/setup_build.sh index fcadee4c7..c696d2708 100755 --- a/.github/scripts/ubuntu-20.04/setup_build.sh +++ b/.github/scripts/ubuntu-20.04/setup_build.sh @@ -1,6 +1,16 @@ #!/bin/bash +# Update package repository +sudo apt-get update + +# Add official LLVM repositories +wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - +echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main" | sudo tee /etc/apt/sources.list.d/llvm.list +echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main" | sudo tee -a /etc/apt/sources.list.d/llvm.list +sudo apt-get update + # Install required packages for CodeCompass build -sudo apt-get install -y git cmake make g++ libboost-all-dev llvm-11-dev clang-11 \ - libclang-11-dev odb libodb-dev default-jdk libssl-dev \ +sudo apt-get install -y git cmake make g++ libboost-all-dev \ + llvm-15-dev clang-15 libclang-15-dev odb \ + libodb-dev default-jdk libssl-dev \ libgraphviz-dev libmagic-dev libgit2-dev ctags doxygen libgtest-dev npm libldap2-dev 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 1197d33c1..3545d3bcf 100755 --- a/.github/scripts/ubuntu-22.04/setup_build.sh +++ b/.github/scripts/ubuntu-22.04/setup_build.sh @@ -1,8 +1,11 @@ #!/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-11-dev clang-11 libclang-11-dev \ + llvm-15-dev clang-15 libclang-15-dev \ gcc-11-plugin-dev thrift-compiler libthrift-dev \ default-jdk libssl-dev libgraphviz-dev libmagic-dev libgit2-dev exuberant-ctags doxygen \ libldap2-dev libgtest-dev \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 930fe4b55..ad50f2ea4 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-20.04, ubuntu-22.04] + os: [ubuntu-20.04, ubuntu-22.04, macos-12] fail-fast: false runs-on: ${{ matrix.os }} @@ -45,9 +45,6 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Update apt-get - run: sudo apt-get update - - name: Install required packages for build run: ./.github/scripts/${{ matrix.os }}/setup_build.sh @@ -137,8 +134,8 @@ jobs: -DCMAKE_INSTALL_PREFIX=$HOME/${{ matrix.os }}/${{ matrix.db }}/cc-install -DDATABASE=$DB_TYPE -DCMAKE_BUILD_TYPE=$BUILD_TYPE - -DLLVM_DIR=/usr/lib/llvm-11/cmake - -DClang_DIR=/usr/lib/cmake/clang-11 + -DLLVM_DIR=/usr/lib/llvm-15/cmake + -DClang_DIR=/usr/lib/cmake/clang-15 -DTEST_DB=$DB_CONNSTRING - name: Build @@ -209,9 +206,6 @@ jobs: steps: - uses: actions/checkout@v3 - - 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/.gitlab/build-deps.sh b/.gitlab/build-deps.sh index 09db12e0d..5eda39c88 100644 --- a/.gitlab/build-deps.sh +++ b/.gitlab/build-deps.sh @@ -250,9 +250,9 @@ export PATH=$DEPS_INSTALL_RUNTIME_DIR/python-install/bin:$PATH if [ ! -f $DEPS_INSTALL_RUNTIME_DIR/llvm-install/bin/clang ]; then cd $PACKAGES_DIR - wget --no-verbose --no-clobber https://github.com/llvm/llvm-project/archive/llvmorg-11.1.0.tar.gz - tar -xf llvmorg-11.1.0.tar.gz - mv llvm-project-llvmorg-11.1.0 llvm-project + wget --no-verbose --no-clobber https://github.com/llvm/llvm-project/archive/llvmorg-15.0.7.tar.gz + tar -xf llvmorg-15.0.7.tar.gz + mv llvm-project-llvmorg-15.0.7 llvm-project mkdir llvm-project/build cd llvm-project/build @@ -264,7 +264,7 @@ if [ ! -f $DEPS_INSTALL_RUNTIME_DIR/llvm-install/bin/clang ]; then -DLLVM_ENABLE_RTTI=ON make install --quiet --jobs $(nproc) - rm -f $PACKAGES_DIR/llvmorg-11.1.0.tar.gz + rm -f $PACKAGES_DIR/llvmorg-15.0.7.tar.gz else echo "Found LLVM/Clang in cache." fi 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/doc/deps.md b/doc/deps.md index 221e795fb..b336b5d40 100644 --- a/doc/deps.md +++ b/doc/deps.md @@ -15,7 +15,7 @@ be installed from the official repository of the given Linux distribution. is required. (Alternatively, you can compile with Clang.) - **`gcc-X`, `gcc-X-plugin-dev`**: For building ODB. - **`libboost-all-dev`**: Boost can be used during the development. -- **`llvm-11-dev`**, **`clang-11`**, **`libclang-11-dev`**: C++ parser uses +- **`llvm-15-dev`**, **`clang-15`**, **`libclang-15-dev`**: C++ parser uses LLVM/Clang for parsing the source code. - **`odb`**, **`libodb-dev`**: For persistence ODB can be used which is an Object Relation Mapping (ORM) system. @@ -52,9 +52,18 @@ known issues. #### Ubuntu 20.04 ("Focal Fossa") LTS +The standard Ubuntu Focal package repository contains only LLCM/Clang version 12, +which is not sufficient for CodeCompass, as at least version 15 is required. +Therefore LLVM and Clang should be installed from the official LLVM repositories: + ```bash +wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - +echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main" | sudo tee /etc/apt/sources.list.d/llvm.list +echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main" | sudo -a tee /etc/apt/sources.list.d/llvm.list +sudo apt-get update + sudo apt install git cmake make g++ libboost-all-dev \ - llvm-11-dev clang-11 libclang-11-dev \ + llvm-15-dev clang-15 libclang-15-dev \ odb libodb-dev \ default-jdk libssl-dev libgraphviz-dev libmagic-dev libgit2-dev ctags doxygen \ libldap2-dev libgtest-dev @@ -64,7 +73,7 @@ sudo apt install git cmake make g++ libboost-all-dev \ ```bash sudo apt install git cmake make g++ libboost-all-dev \ - llvm-11-dev clang-11 libclang-11-dev \ + llvm-15-dev clang-15 libclang-15-dev \ gcc-11-plugin-dev thrift-compiler libthrift-dev \ default-jdk libssl-dev libgraphviz-dev libmagic-dev libgit2-dev exuberant-ctags doxygen \ libldap2-dev libgtest-dev @@ -192,7 +201,7 @@ cd thrift-0.16.0 --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-java --without-swift make install -j $(nproc) ``` @@ -269,8 +278,8 @@ cmake .. \ -DCMAKE_INSTALL_PREFIX= \ -DDATABASE= \ -DCMAKE_BUILD_TYPE= \ - -DLLVM_DIR=/usr/lib/llvm-11/cmake \ - -DClang_DIR=/usr/lib/cmake/clang-11 + -DLLVM_DIR=/usr/lib/llvm-15/cmake \ + -DClang_DIR=/usr/lib/cmake/clang-15 # To specify linker for building CodeCompass use # -DCODECOMPASS_LINKER= diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index 10cfdf9a2..1619c9bd5 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -26,7 +26,7 @@ RUN set -x && apt-get update -qq \ libmagic-dev \ libsqlite3-dev \ libssl-dev \ - llvm-11 clang-11 llvm-11-dev libclang-11-dev \ + llvm-15 clang-15 llvm-15-dev libclang-15-dev \ thrift-compiler libthrift-dev \ postgresql-server-dev-14 \ postgresql-14 && \ @@ -70,8 +70,8 @@ ENV DATABASE=sqlite \ TEST_WORKSPACE=/CodeCompass/test_workspace \ TEST_DB="sqlite:database=$TEST_WORKSPACE/cc_test.sqlite" \ WITH_AUTH="plain;ldap" \ - LLVM_DIR=/usr/lib/llvm-11/cmake \ - Clang_DIR=/usr/lib/cmake/clang-11 \ + LLVM_DIR=/usr/lib/llvm-15/cmake \ + Clang_DIR=/usr/lib/cmake/clang-15 \ CMAKE_PREFIX_PATH=/opt/odb ENV PATH="$INSTALL_DIR/bin:/opt/odb/bin:$PATH" diff --git a/docker/runtime/Dockerfile b/docker/runtime/Dockerfile index 8baab0fa4..49b87eb29 100644 --- a/docker/runtime/Dockerfile +++ b/docker/runtime/Dockerfile @@ -55,7 +55,7 @@ RUN set -x && apt-get update -qq && \ apt-get install -qq --yes --no-install-recommends \ curl ca-certificates gnupg \ wget \ - llvm-11 \ + llvm-15 \ libboost-filesystem-dev libboost-log-dev libboost-program-options-dev \ default-jre \ libgit2-dev \ diff --git a/docker/web/Dockerfile b/docker/web/Dockerfile index 004a8a4d4..4780bb7ec 100644 --- a/docker/web/Dockerfile +++ b/docker/web/Dockerfile @@ -17,7 +17,7 @@ ARG DEBIAN_FRONTEND=noninteractive RUN set -x && apt-get update -qq \ && apt-get install -qqy --no-install-recommends \ - llvm-11 \ + llvm-15 \ libboost-filesystem-dev libboost-log-dev libboost-program-options-dev \ libsqlite3-dev \ postgresql-server-dev-14 \ 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/parser/src/pluginhandler.cpp b/parser/src/pluginhandler.cpp index 7fe6c91e1..e656e31de 100644 --- a/parser/src/pluginhandler.cpp +++ b/parser/src/pluginhandler.cpp @@ -44,7 +44,7 @@ void PluginHandler::loadPlugins(std::vector& skipParserList_) ++dirIter) { if (fs::is_regular_file(dirIter->status()) && - fs::extension(*dirIter) == util::DynamicLibrary::extension()) + fs::path(*dirIter).extension() == util::DynamicLibrary::extension()) { std::string filename = getPluginName(dirIter->path()); @@ -85,7 +85,7 @@ std::vector PluginHandler::getPluginNames() const ++dirIter) { if (fs::is_regular_file(dirIter->status()) && - fs::extension(*dirIter) == util::DynamicLibrary::extension()) + fs::path(*dirIter).extension() == util::DynamicLibrary::extension()) { plugins.push_back(getPluginName(dirIter->path())); } 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/clangastvisitor.h b/plugins/cpp/parser/src/clangastvisitor.h index cfcaf8604..10683fd65 100644 --- a/plugins/cpp/parser/src/clangastvisitor.h +++ b/plugins/cpp/parser/src/clangastvisitor.h @@ -1735,7 +1735,7 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor clang::DynTypedNodeList parents = _astContext.getParents(*expr_); - const clang::ast_type_traits::DynTypedNode& parent = parents[0]; + const clang::DynTypedNode& parent = parents[0]; if (const clang::BinaryOperator* op = parent.get()) { diff --git a/plugins/cpp/parser/src/cppparser.cpp b/plugins/cpp/parser/src/cppparser.cpp index 58620801c..0a09dd105 100644 --- a/plugins/cpp/parser/src/cppparser.cpp +++ b/plugins/cpp/parser/src/cppparser.cpp @@ -159,7 +159,7 @@ bool CppParser::isSourceFile(const std::string& file_) const const std::vector cppExts{ ".c", ".cc", ".cpp", ".cxx", ".o", ".so", ".a"}; - std::string ext = fs::extension(file_); + std::string ext = fs::path(file_).extension().string(); std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); return std::find(cppExts.begin(), cppExts.end(), ext) != cppExts.end(); @@ -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 { @@ -209,7 +219,7 @@ std::map CppParser::extractInputOutputs( { for (const std::string& src : sources) { - std::string extension = fs::extension(src); + std::string extension = fs::path(src).extension().string(); inToOut[src] = src.substr(0, src.size() - extension.size() - 1) + ".o"; } } @@ -232,7 +242,7 @@ model::BuildActionPtr CppParser::addBuildAction( model::BuildActionPtr buildAction(new model::BuildAction); - std::string extension = fs::extension(command_.Filename); + auto extension = fs::path(command_.Filename).extension(); buildAction->command = boost::algorithm::join(command_.CommandLine, " "); buildAction->type @@ -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/ppincludecallback.cpp b/plugins/cpp/parser/src/ppincludecallback.cpp index b163732fe..9c8393560 100644 --- a/plugins/cpp/parser/src/ppincludecallback.cpp +++ b/plugins/cpp/parser/src/ppincludecallback.cpp @@ -61,7 +61,7 @@ void PPIncludeCallback::InclusionDirective( clang::StringRef fileName_, bool, clang::CharSourceRange filenameRange_, - const clang::FileEntry*, + clang::Optional, clang::StringRef searchPath_, clang::StringRef, const clang::Module*, diff --git a/plugins/cpp/parser/src/ppincludecallback.h b/plugins/cpp/parser/src/ppincludecallback.h index df3a96676..6d67367f3 100644 --- a/plugins/cpp/parser/src/ppincludecallback.h +++ b/plugins/cpp/parser/src/ppincludecallback.h @@ -38,7 +38,7 @@ class PPIncludeCallback : public clang::PPCallbacks clang::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, - const clang::FileEntry *File, + clang::Optional File, clang::StringRef SearchPath, clang::StringRef RelativePath, const clang::Module *Imported, 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/service/src/filediagram.cpp b/plugins/cpp/service/src/filediagram.cpp index 44c3bf788..47d195c3a 100644 --- a/plugins/cpp/service/src/filediagram.cpp +++ b/plugins/cpp/service/src/filediagram.cpp @@ -711,7 +711,7 @@ util::Graph::Node FileDiagram::addNode( } else if (fileInfo_.type == "CPP") { - std::string ext = boost::filesystem::extension(fileInfo_.path); + std::string ext = boost::filesystem::path(fileInfo_.path).extension().string(); std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); if (ext == ".cpp" || ext == ".cxx" || ext == ".cc" || ext == ".c") diff --git a/plugins/cpp_metrics/service/CMakeLists.txt b/plugins/cpp_metrics/service/CMakeLists.txt index 96b5a1fdf..e200887a6 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( @@ -54,5 +55,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/parser/src/dummyparser.cpp b/plugins/dummy/parser/src/dummyparser.cpp index 9c3f2ff1e..da92f0b62 100644 --- a/plugins/dummy/parser/src/dummyparser.cpp +++ b/plugins/dummy/parser/src/dummyparser.cpp @@ -17,7 +17,7 @@ DummyParser::DummyParser(ParserContext& ctx_): AbstractParser(ctx_) bool DummyParser::accept(const std::string& path_) { - std::string ext = boost::filesystem::extension(path_); + auto ext = boost::filesystem::path(path_).extension(); return ext == ".dummy"; } 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/parser/src/gitparser.cpp b/plugins/git/parser/src/gitparser.cpp index 82c09edce..b33169cbe 100644 --- a/plugins/git/parser/src/gitparser.cpp +++ b/plugins/git/parser/src/gitparser.cpp @@ -164,7 +164,7 @@ util::DirIterCallback GitParser::getParserCallback() boost::property_tree::ptree pt; std::string repoFile(versionDataDir + "/repositories.txt"); - if (boost::filesystem::is_regular(repoFile)) + if (boost::filesystem::is_regular_file(repoFile)) boost::property_tree::read_ini(repoFile, pt); pt.put(repoId + ".name", path.filename().string()); 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/git/service/src/gitservice.cpp b/plugins/git/service/src/gitservice.cpp index 88c8578fb..54f05f161 100644 --- a/plugins/git/service/src/gitservice.cpp +++ b/plugins/git/service/src/gitservice.cpp @@ -151,7 +151,7 @@ void GitServiceHandler::getRepositoryList(std::vector& return_) std::string repoFile(versionDataDir.string() + "/repositories.txt"); boost::property_tree::ptree pt; - if (!fs::is_regular(repoFile)) + if (!fs::is_regular_file(repoFile)) { LOG(warning) << "Repository file not found in data directory: " << repoFile; return; 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/parser/src/searchparser.cpp b/plugins/search/parser/src/searchparser.cpp index 9306e04cd..cc5a97334 100644 --- a/plugins/search/parser/src/searchparser.cpp +++ b/plugins/search/parser/src/searchparser.cpp @@ -173,7 +173,7 @@ bool SearchParser::shouldHandle(const std::string& path_) { //--- The file is not regular. ---// - if (!fs::is_regular(path_)) + if (!fs::is_regular_file(path_)) return false; //--- The file is excluded by suffix. ---// 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 7bf221ae3..e80ce6b68 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 @@ -18,13 +19,16 @@ add_library(util SHARED src/util.cpp) target_link_libraries(util - 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/include/webserver/pluginhandler.h b/webserver/include/webserver/pluginhandler.h index 8d80ce543..84fd09686 100644 --- a/webserver/include/webserver/pluginhandler.h +++ b/webserver/include/webserver/pluginhandler.h @@ -44,7 +44,7 @@ class PluginHandler for (fs::directory_iterator dirIter(path_); dirIter != endIter; ++dirIter) { if (fs::is_regular_file(dirIter->status()) - && fs::extension(*dirIter) == util::DynamicLibrary::extension()) + && fs::path(*dirIter).extension() == util::DynamicLibrary::extension()) { _dynamicLibraries.emplace_back(util::DynamicLibraryPtr( new util::DynamicLibrary(dirIter->path().string()))); 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