Skip to content

Making codebase macOS compatible #637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, <[email protected]>
# Copyright (c) 2013-2014 Kevin Funk <[email protected]>

# Version computation and some cleanups by Allen Winter <[email protected]>
# Copyright (c) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>

# Simplified script by Dogan Can <[email protected]>
# 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 <[email protected]>
# 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: 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 @@ -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
Expand Down
1 change: 1 addition & 0 deletions plugins/cpp/parser/include/cppparser/cppparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_);

Expand Down
12 changes: 11 additions & 1 deletion plugins/cpp/parser/src/cppparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string> CppParser::extractInputOutputs(
const clang::tooling::CompileCommand& command_) const
{
Expand Down Expand Up @@ -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());

Expand Down
8 changes: 4 additions & 4 deletions plugins/cpp/parser/src/ppmacrocallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PPMacroCallback::~PPMacroCallback()
});
}

void PPMacroCallback::MacroExpands(
/*void PPMacroCallback::MacroExpands(
const clang::Token& macroNameTok_,
const clang::MacroDefinition& md_,
clang::SourceRange range_,
Expand Down Expand Up @@ -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);
}
Expand All @@ -146,7 +146,7 @@ void PPMacroCallback::MacroExpands(

_macrosExpansion.push_back(mExp);
}
}
}*/

void PPMacroCallback::MacroDefined(
const clang::Token& macroNameTok_,
Expand Down
4 changes: 2 additions & 2 deletions plugins/cpp/parser/src/ppmacrocallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_,
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 @@ -10,6 +10,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 @@ -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()
Loading