diff --git a/.travis.yml b/.travis.yml index 14ebafe..b488c98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index ad88f39..8d8a215 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/compatibility.h b/include/compatibility.h index 63eafc2..c60d97b 100644 --- a/include/compatibility.h +++ b/include/compatibility.h @@ -6,11 +6,7 @@ #ifndef COMPATIBILITY_H #define COMPATIBILITY_H -#if __has_include() && !defined(USE_BOOST_CONTAINERS) -#include -#else #include -#endif #include #if __has_include() && !defined(USE_BOOST_CONTAINERS) #include @@ -19,20 +15,13 @@ #endif #if __has_include() && !defined(USE_BOOST_CONTAINERS) #include +#elif __has_include() && !defined(USE_BOOST_CONTAINERS) +#include #else #include #endif namespace wyrm { -#if __has_include() && !defined(USE_BOOST_CONTAINERS) -template using variant = std::variant; -template inline auto visit(ArgTys &&... Args) { - return std::visit(std::forward(Args)...); -}; -template inline auto get(ArgTys &&... Args) { - return std::get(std::forward(Args)...); -}; -#else template using variant = boost::variant; template inline auto visit(ArgTys &&... Args) { return boost::apply_visitor(std::forward(Args)...); @@ -40,7 +29,6 @@ template inline auto visit(ArgTys &&... Args) { template inline auto get(ArgTys &&... Args) { return boost::get(std::forward(Args)...); }; -#endif #if __has_include() && !defined(USE_BOOST_CONTAINERS) template using optional = std::optional; @@ -50,6 +38,8 @@ template using optional = boost::optional; #if __has_include() && !defined(USE_BOOST_CONTAINERS) using string_view = std::string_view; +#elif __has_include() && !defined(USE_BOOST_CONTAINERS) +using string_view = std::experimental::string_view; #else using string_view = boost::string_view; #endif diff --git a/include/context.h b/include/context.h index eb6d52b..cc057fd 100644 --- a/include/context.h +++ b/include/context.h @@ -44,7 +44,7 @@ class WyrmContext { FunctionSymbolsT FunctionSymbols{}; }; -inline WyrmContext GlobalContext{}; +extern WyrmContext GlobalContext; string_view internedName(std::string &&name); } // namespace wyrm diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 532d0fd..2e14c27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/context.cpp b/src/context.cpp index 58fa601..f7d0116 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -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))); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2f34c79..decf8d5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 @@ -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) diff --git a/ubuntu_install_build_deps.sh b/ubuntu_install_build_deps.sh new file mode 100755 index 0000000..40ed7da --- /dev/null +++ b/ubuntu_install_build_deps.sh @@ -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 ..