Skip to content

Commit

Permalink
Making the codebase compatible with macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcserep committed Nov 14, 2023
1 parent e23b1dc commit 369ccf1
Show file tree
Hide file tree
Showing 32 changed files with 342 additions and 27 deletions.
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
83 changes: 83 additions & 0 deletions FindGraphviz.cmake
Original file line number Diff line number Diff line change
@@ -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, <madcat@mymadcat.com>
# Copyright (c) 2013-2014 Kevin Funk <kevin.funk@kdab.com>

# Version computation and some cleanups by Allen Winter <allen.winter@kdab.com>
# Copyright (c) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>

# Simplified script by Dogan Can <dogancan@usc.edu>
# 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 <graphviz/graphviz_version.h>\n#include <stdio.h>\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()
99 changes: 99 additions & 0 deletions FindLibMagic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2013-2013, Lars Baehren <lbaehren@gmail.com>
# 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)
2 changes: 2 additions & 0 deletions Functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/deps.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,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)
```
Expand Down
2 changes: 2 additions & 0 deletions logger/src/ldlogger-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#define CC_LOGGER_UTIL_H

#include <limits.h>
#ifdef __linux__
#include <linux/limits.h>
#endif
#include <string.h>

/**
Expand Down
1 change: 1 addition & 0 deletions model/include/model/buildaction.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef CC_MODEL_BUILDACTION_H
#define CC_MODEL_BUILDACTION_H

#include <cstdint>
#include <string>
#include <memory>
#include <vector>
Expand Down
5 changes: 3 additions & 2 deletions parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +22,7 @@ target_link_libraries(CodeCompass_parser
${Boost_LIBRARIES}
${ODB_LIBRARIES}
${CMAKE_DL_LIBS}
magic
${LIBMAGIC_LIBRARIES}
pthread)

install(TARGETS CodeCompass_parser
Expand Down
2 changes: 2 additions & 0 deletions plugins/cpp/model/include/model/cppinheritance.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define CC_MODEL_CPPINHERITANCE_H

#include <memory>
#include <cstdint>

#include "common.h"

namespace cc
Expand Down
7 changes: 7 additions & 0 deletions plugins/cpp/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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
Expand Down
9 changes: 8 additions & 1 deletion plugins/cpp/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
8 changes: 8 additions & 0 deletions plugins/cpp_metrics/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include_directories(
${PROJECT_SOURCE_DIR}/webserver/include)

include_directories(SYSTEM
${Boost_INCLUDE_DIRS}
${THRIFT_LIBTHRIFT_INCLUDE_DIRS})

add_custom_command(
Expand Down Expand Up @@ -40,4 +41,11 @@ target_link_libraries(cppmetricsservice
${ODB_LIBRARIES}
cppmetricsthrift)

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(cppmetricsservice PROPERTIES LINK_FLAGS
"-undefined dynamic_lookup")
endif(APPLE)

install(TARGETS cppmetricsservice DESTINATION ${INSTALL_SERVICE_DIR})
4 changes: 2 additions & 2 deletions plugins/cpp_reparse/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -69,8 +70,7 @@ target_link_libraries(cppreparseservice
clangFrontend
clangBasic
clangAST
clang
)
clang)

install(TARGETS cppreparseservice DESTINATION ${INSTALL_SERVICE_DIR})
install_js_thrift()
6 changes: 6 additions & 0 deletions plugins/dummy/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
8 changes: 8 additions & 0 deletions plugins/dummy/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include_directories(
${PROJECT_SOURCE_DIR}/webserver/include)

include_directories(SYSTEM
${Boost_INCLUDE_DIRS}
${THRIFT_LIBTHRIFT_INCLUDE_DIRS})

add_custom_command(
Expand Down Expand Up @@ -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})
4 changes: 2 additions & 2 deletions plugins/git/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Loading

0 comments on commit 369ccf1

Please sign in to comment.