Skip to content

Commit

Permalink
Add Linux/GCC-6 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kopyl authored and akiramenai committed Jan 8, 2018
1 parent 98d55ad commit 3e4a870
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 50 deletions.
29 changes: 19 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
language: cpp
compiler: clang
os: osx
osx_image: xcode9.1

before_install:
- brew install ninja || true
- brew install boost || true
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install ninja boost || true ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
sudo cmake_ver='3.10.1' boost_ver='1.66.0' ./ubuntu_install_build_deps.sh;
fi

matrix:
include:
- os: linux
dist: trusty
sudo: false
- os: osx
compiler: clang
osx_image: xcode9.1

script:
- mkdir build
- cd build
- cmake ..
- make
- test/unittest
- mkdir build
- cd build
- cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON
- make
- test/unittest
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
cmake_minimum_required(VERSION 3.9.3)
cmake_minimum_required(VERSION 2.8.12)
project(compiler_algo CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Werror -Wextra -g")

find_package(Boost)

include_directories(include)

add_subdirectory(src)
Expand Down
18 changes: 4 additions & 14 deletions include/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
#ifndef COMPATIBILITY_H
#define COMPATIBILITY_H

#if __has_include(<variant>) && !defined(USE_BOOST_CONTAINERS)
#include <variant>
#else
#include <boost/variant.hpp>
#endif
#include <iostream>
#if __has_include(<optional>) && !defined(USE_BOOST_CONTAINERS)
#include <optional>
Expand All @@ -19,28 +15,20 @@
#endif
#if __has_include(<string_view>) && !defined(USE_BOOST_CONTAINERS)
#include <string_view>
#elif __has_include(<experimental/string_view>) && !defined(USE_BOOST_CONTAINERS)
#include <experimental/string_view>
#else
#include <boost/utility/string_view.hpp>
#endif

namespace wyrm {
#if __has_include(<variant>) && !defined(USE_BOOST_CONTAINERS)
template <typename... Args> using variant = std::variant<Args...>;
template <typename... ArgTys> inline auto visit(ArgTys &&... Args) {
return std::visit(std::forward<ArgTys>(Args)...);
};
template <typename T, typename... ArgTys> inline auto get(ArgTys &&... Args) {
return std::get<T>(std::forward<ArgTys>(Args)...);
};
#else
template <typename... Args> using variant = boost::variant<Args...>;
template <typename... ArgTys> inline auto visit(ArgTys &&... Args) {
return boost::apply_visitor(std::forward<ArgTys>(Args)...);
};
template <typename T, typename... ArgTys> inline auto get(ArgTys &&... Args) {
return boost::get<T>(std::forward<ArgTys>(Args)...);
};
#endif

#if __has_include(<optional>) && !defined(USE_BOOST_CONTAINERS)
template <typename ValueT> using optional = std::optional<ValueT>;
Expand All @@ -50,6 +38,8 @@ template <typename ValueT> using optional = boost::optional<ValueT>;

#if __has_include(<string_view>) && !defined(USE_BOOST_CONTAINERS)
using string_view = std::string_view;
#elif __has_include(<experimental/string_view>) && !defined(USE_BOOST_CONTAINERS)
using string_view = std::experimental::string_view;
#else
using string_view = boost::string_view;
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class WyrmContext {
FunctionSymbolsT FunctionSymbols{};
};

inline WyrmContext GlobalContext{};
extern WyrmContext GlobalContext;
string_view internedName(std::string &&name);

} // namespace wyrm
Expand Down
8 changes: 3 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
find_package(Boost)

add_library(graph
graph.cpp)
add_executable(gviz
main.cpp)
target_include_directories(gviz
PUBLIC
include_directories(
${Boost_INCLUDE_DIRS})

target_link_libraries(gviz
${Boost_LIBRARY_DIRS})
boost_graph)

add_subdirectory(Analysis)
2 changes: 2 additions & 0 deletions src/context.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "context.h"

namespace wyrm {
WyrmContext GlobalContext{};

string_view internedName(std::string &&name) {
auto NameIt =
std::get<0>(GlobalContext.StringStorage.insert(std::move(name)));
Expand Down
28 changes: 9 additions & 19 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
include(ExternalProject)

set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/external)
include_directories(
${Boost_INCLUDE_DIRS})

set(GTEST_INSTALL_DIR ${CMAKE_BINARY_DIR}/external)

ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GTEST_INSTALL_DIR} -DCMAKE_INSTALL_LIBDIR=${GTEST_INSTALL_DIR}/lib -DCMAKE_INSTALL_INCLUDEDIR=${GTEST_INSTALL_DIR}/include
)

link_directories(${GTEST_INSTALL_DIR}/lib)

add_executable(unittest
../src/context.cpp
../src/MIR.cpp
Expand All @@ -15,23 +20,8 @@ add_executable(unittest

add_dependencies(unittest googletest)

set(GTEST_LIB_DIR ${EXTERNAL_INSTALL_LOCATION}/lib)

target_include_directories(unittest
PUBLIC
${EXTERNAL_INSTALL_LOCATION}/include)

add_library(GTEST_LIB IMPORTED STATIC)
add_library(GTEST_MAIN_LIB IMPORTED STATIC)

add_dependencies(GTEST_LIB googletest)
add_dependencies(GTEST_MAIN_LIB googletest)

if (APPLE)
set_target_properties(GTEST_LIB PROPERTIES IMPORTED_LOCATION ${EXTERNAL_INSTALL_LOCATION}/lib/libgtest.a)
set_target_properties(GTEST_MAIN_LIB PROPERTIES IMPORTED_LOCATION ${EXTERNAL_INSTALL_LOCATION}/lib/libgtest_main.a)
endif (APPLE)
${GTEST_INSTALL_DIR}/include)

add_dependencies(unittest GTEST_LIB)
add_dependencies(unittest GTEST_MAIN_LIB)
target_link_libraries(unittest GTEST_LIB GTEST_MAIN_LIB pthread graph dominators)
target_link_libraries(unittest gtest gtest_main pthread graph dominators)
37 changes: 37 additions & 0 deletions ubuntu_install_build_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -xeu

apt-get update -q;
apt-get install \
software-properties-common \
python-software-properties -y;

add-apt-repository ppa:ubuntu-toolchain-r/test -y;
apt-get update -q;
apt-get install \
build-essential \
git \
wget \
gcc-7 \
g++-7 -y;
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 50;
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-7 50;
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 50;
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-7 50;


wget "https://cmake.org/files/v3.10/cmake-${cmake_ver}.tar.gz"
tar -xf cmake-${cmake_ver}.tar.gz
cd cmake-${cmake_ver}
./bootstrap --prefix=/usr/local > /dev/null
make install -j$(nproc) > /dev/null
cd ..

boost_ver2="${boost_ver//./_}"
wget "https://dl.bintray.com/boostorg/release/${boost_ver}/source/boost_${boost_ver2}.tar.gz"
tar -xf boost_${boost_ver2}.tar.gz
cd boost_${boost_ver2}
./bootstrap.sh --prefix=/usr --with-libraries=graph > /dev/null
./bjam install -j$(nproc) > /dev/null
cd ..

0 comments on commit 3e4a870

Please sign in to comment.