Merge pull request #14 from bkryza/fix-build-on-macos

Fix build on macos
This commit is contained in:
Bartek Kryza
2022-02-13 00:26:04 +01:00
committed by GitHub
10 changed files with 72 additions and 13 deletions

View File

@@ -15,16 +15,33 @@ set(CLANG_UML_INSTALL_BIN_DIR ${PROJECT_SOURCE_DIR}/bin)
set(UML_HEADERS_DIR ${PROJECT_SOURCE_DIR}/src/uml) set(UML_HEADERS_DIR ${PROJECT_SOURCE_DIR}/src/uml)
set(LLVM_PREFERRED_VERSION 12.0.0) option(LLVM_CONFIG_PATH "Path to custom llvm-config executable")
if(LLVM_CONFIG_PATH)
set(LIBCLANG_LLVM_CONFIG_EXECUTABLE ${LLVM_CONFIG_PATH})
endif(LLVM_CONFIG_PATH)
message(STATUS "Checking for fmt...")
find_package(fmt REQUIRED)
message(STATUS "Checking for spdlog...") message(STATUS "Checking for spdlog...")
find_package(spdlog REQUIRED) find_package(spdlog REQUIRED)
add_definitions(-DSPDLOG_FMT_EXTERNAL) if(APPLE)
get_target_property(SPDLOG_INCLUDE_DIRS spdlog::spdlog_header_only INTERFACE_INCLUDE_DIRECTORIES)
else(APPLE)
get_target_property(SPDLOG_INCLUDE_DIRS spdlog::spdlog INTERFACE_INCLUDE_DIRECTORIES)
add_definitions(-DSPDLOG_FMT_EXTERNAL)
endif(APPLE)
message(STATUS "Checking for yaml-cpp...") message(STATUS "Checking for yaml-cpp...")
find_package(yaml-cpp REQUIRED) find_package(yaml-cpp REQUIRED)
message(STATUS "Checking for libclang...") message(STATUS "Checking for libclang...")
set(LLVM_PREFERRED_VERSION 12.0.0)
# Add
# -DLLVM_CONFIG_PATH=/path/to/llvm-config
# to use custom LLVM version
find_package(LibClang REQUIRED) find_package(LibClang REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 ${LIBCLANG_CXXFLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 ${LIBCLANG_CXXFLAGS}")
@@ -47,6 +64,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
endif() endif()
include_directories(${CLANG_UML_INSTALL_INCLUDE_DIR}) include_directories(${CLANG_UML_INSTALL_INCLUDE_DIR})
include_directories(${YAML_CPP_INCLUDE_DIR}) include_directories(${YAML_CPP_INCLUDE_DIR})
include_directories(${SPDLOG_INCLUDE_DIRS})
include_directories(${UML_HEADERS_DIR}) include_directories(${UML_HEADERS_DIR})
include_directories(${THIRDPARTY_HEADERS_DIR}) include_directories(${THIRDPARTY_HEADERS_DIR})
include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/include) include_directories(${THIRDPARTY_HEADERS_DIR}/cppast/include)
@@ -62,7 +80,13 @@ add_library(clang-umllib OBJECT ${SOURCES})
add_executable(clang-uml ${MAIN_SOURCE_FILE}) add_executable(clang-uml ${MAIN_SOURCE_FILE})
install(TARGETS clang-uml DESTINATION ${CLANG_UML_INSTALL_BIN_DIR}) install(TARGETS clang-uml DESTINATION ${CLANG_UML_INSTALL_BIN_DIR})
target_link_libraries(clang-uml ${LIBCLANG_LIBRARIES} ${YAML_CPP_LIBRARIES} spdlog::spdlog cppast clang-umllib) target_link_libraries(clang-uml ${LIBCLANG_LIBRARIES} ${YAML_CPP_LIBRARIES} fmt::fmt cppast clang-umllib)
if(APPLE)
target_link_libraries(clang-uml spdlog::spdlog_header_only)
else(APPLE)
target_link_libraries(clang-uml spdlog::spdlog)
endif(APPLE)
target_compile_features(clang-uml PRIVATE cxx_std_17) target_compile_features(clang-uml PRIVATE cxx_std_17)
install( install(

View File

@@ -22,6 +22,8 @@
NUMPROC ?= $(shell nproc) NUMPROC ?= $(shell nproc)
LLVM_CONFIG_PATH ?=
.PHONY: clean .PHONY: clean
clean: clean:
rm -rf debug release rm -rf debug release
@@ -29,12 +31,14 @@ clean:
debug/CMakeLists.txt: debug/CMakeLists.txt:
cmake -S . -B debug \ cmake -S . -B debug \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_TYPE=Debug \
-DLLVM_CONFIG_PATH=$(LLVM_CONFIG_PATH)
release/CMakeLists.txt: release/CMakeLists.txt:
cmake -S . -B release \ cmake -S . -B release \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_TYPE=Release \
-DLLVM_CONFIG_PATH=$(LLVM_CONFIG_PATH)
debug: debug/CMakeLists.txt debug: debug/CMakeLists.txt
echo "Using ${NUMPROC} cores" echo "Using ${NUMPROC} cores"

View File

@@ -26,10 +26,14 @@ Main features supported so far include:
### Building from source ### Building from source
Currently the only method to install `clang-uml` is from source. First make sure Currently the only method to install `clang-uml` is from source. First make sure
that you have the following dependencies installed (example for Ubuntu): that you have the following dependencies installed:
```bash ```bash
# Ubuntu
apt install ccache cmake libyaml-cpp-dev libfmt-dev libspdlog-dev clang-12 libclang-12-dev libclang-cpp12-dev apt install ccache cmake libyaml-cpp-dev libfmt-dev libspdlog-dev clang-12 libclang-12-dev libclang-cpp12-dev
# macos
brew install ccache cmake llvm fmt spdlog yaml-cpp
``` ```
Then proceed with building the sources: Then proceed with building the sources:
@@ -42,6 +46,9 @@ make submodules
make release make release
release/clang-uml --help release/clang-uml --help
# To build using a specific installed version of LLVM use:
LLVM_CONFIG_PATH=/usr/bin/llvm-config-13 make release
# Optionally # Optionally
make install make install
# or # or

View File

@@ -57,13 +57,13 @@ if (NOT LIBCLANG_LLVM_CONFIG_EXECUTABLE)
find_program(LIBCLANG_LLVM_CONFIG_EXECUTABLE NAMES llvm-config PATHS "${BREW_LLVM_PATH}/bin") find_program(LIBCLANG_LLVM_CONFIG_EXECUTABLE NAMES llvm-config PATHS "${BREW_LLVM_PATH}/bin")
else () else ()
set(llvm_config_names llvm-config) set(llvm_config_names llvm-config)
foreach(major RANGE 12 3) foreach(major RANGE 13 3)
list(APPEND llvm_config_names "llvm-config${major}" "llvm-config-${major}") list(APPEND llvm_config_names "llvm-config${major}" "llvm-config-${major}")
foreach(minor RANGE 9 0) foreach(minor RANGE 9 0)
list(APPEND llvm_config_names "llvm-config${major}${minor}" "llvm-config-${major}.${minor}" "llvm-config-mp-${major}.${minor}") list(APPEND llvm_config_names "llvm-config${major}${minor}" "llvm-config-${major}.${minor}" "llvm-config-mp-${major}.${minor}")
endforeach () endforeach ()
endforeach () endforeach ()
find_program(LIBCLANG_LLVM_CONFIG_EXECUTABLE NAMES ${llvm_config_names}) find_program(LIBCLANG_LLVM_CONFIG_EXECUTABLE NAMES ${llvm_config_names} PATHS /usr/bin)
endif () endif ()
endif () endif ()
if (LIBCLANG_LLVM_CONFIG_EXECUTABLE) if (LIBCLANG_LLVM_CONFIG_EXECUTABLE)

View File

@@ -600,8 +600,10 @@ void translation_unit_visitor::process_field(
auto &tr = cx::util::unreferenced(cppast::remove_cv(mv.type())); auto &tr = cx::util::unreferenced(cppast::remove_cv(mv.type()));
#ifndef __APPLE__
LOG_DBG("Processing field {} with unreferenced type of kind {}", mv.name(), LOG_DBG("Processing field {} with unreferenced type of kind {}", mv.name(),
tr.kind()); tr.kind());
#endif
if (tr.kind() == cppast::cpp_type_kind::builtin_t) { if (tr.kind() == cppast::cpp_type_kind::builtin_t) {
LOG_DBG("Builtin type found for field: {}", m.name()); LOG_DBG("Builtin type found for field: {}", m.name());
@@ -1076,8 +1078,10 @@ bool translation_unit_visitor::find_relationships(const cppast::cpp_type &t_,
const auto fn = const auto fn =
cx::util::full_name(cppast::remove_cv(t_), ctx.entity_index(), false); cx::util::full_name(cppast::remove_cv(t_), ctx.entity_index(), false);
#ifndef __APPLE__
LOG_DBG("Finding relationships for type {}, {}, {}", cppast::to_string(t_), LOG_DBG("Finding relationships for type {}, {}, {}", cppast::to_string(t_),
t_.kind(), fn); t_.kind(), fn);
#endif
relationship_t relationship_type = relationship_hint; relationship_t relationship_type = relationship_hint;
const auto &t = cppast::remove_cv(cx::util::unreferenced(t_)); const auto &t = cppast::remove_cv(cx::util::unreferenced(t_));

View File

@@ -31,7 +31,7 @@
namespace clanguml::package_diagram::model { namespace clanguml::package_diagram::model {
namespace detail { namespace detail {
template <typename T, template <typename> class Container, template <typename T, template <typename, typename> class Container,
typename Ptr = std::unique_ptr<T>> typename Ptr = std::unique_ptr<T>>
class package_trait { class package_trait {
public: public:
@@ -104,8 +104,9 @@ public:
packages_.end(); packages_.end();
} }
typedef typename Container<Ptr>::iterator iterator; typedef typename Container<Ptr, std::allocator<Ptr>>::iterator iterator;
typedef typename Container<Ptr>::const_iterator const_iterator; typedef typename Container<Ptr, std::allocator<Ptr>>::const_iterator
const_iterator;
inline iterator begin() noexcept { return packages_.begin(); } inline iterator begin() noexcept { return packages_.begin(); }
inline const_iterator cbegin() const noexcept { return packages_.cbegin(); } inline const_iterator cbegin() const noexcept { return packages_.cbegin(); }
@@ -113,7 +114,7 @@ public:
inline const_iterator cend() const noexcept { return packages_.cend(); } inline const_iterator cend() const noexcept { return packages_.cend(); }
protected: protected:
Container<std::unique_ptr<T>> packages_; Container<Ptr, std::allocator<Ptr>> packages_;
}; };
} }

View File

@@ -381,8 +381,10 @@ bool translation_unit_visitor::find_relationships(const cppast::cpp_type &t_,
const auto fn_ns = cx::util::ns(cppast::remove_cv(t_), ctx.entity_index()); const auto fn_ns = cx::util::ns(cppast::remove_cv(t_), ctx.entity_index());
#ifndef __APPLE__
LOG_DBG("Finding relationships for type {}, {}, {}", cppast::to_string(t_), LOG_DBG("Finding relationships for type {}, {}, {}", cppast::to_string(t_),
t_.kind(), fn); t_.kind(), fn);
#endif
relationship_t relationship_type = relationship_hint; relationship_t relationship_type = relationship_hint;
const auto &t = cppast::remove_cv(cx::util::unreferenced(t_)); const auto &t = cppast::remove_cv(cx::util::unreferenced(t_));

View File

@@ -1,3 +1,4 @@
#include <array>
#include <map> #include <map>
#include <vector> #include <vector>

View File

@@ -1,3 +1,5 @@
#include <utility>
namespace clanguml { namespace clanguml {
namespace t00017 { namespace t00017 {
class A { class A {
@@ -34,6 +36,15 @@ class K {
}; };
class R { class R {
explicit R(int &some_int, C &cc, const E &ee, F &&ff, I *&ii)
: some_int_reference{some_int}
, c{cc}
, e{ee}
, f{std::move(ff)}
, i{ii}
{
}
private: private:
int some_int; int some_int;
int *some_int_pointer; int *some_int_pointer;
@@ -43,7 +54,7 @@ private:
B *b; B *b;
C &c; C &c;
const D *d; const D *d;
const E &e{}; const E &e;
F &&f; F &&f;
G **g; G **g;
H ***h; H ***h;

View File

@@ -39,6 +39,11 @@ enum class F { one, two, three };
/// \uml{note[right] R class note.} /// \uml{note[right] R class note.}
class R { class R {
explicit R(C &c)
: ccc(c)
{
}
A aaa; A aaa;
B *bbb; B *bbb;