Skip to content

Commit 444c928

Browse files
committed
Fix build to allow custom boost, llvm and phasar directories.
The build was assuming that boost was installed to the default system location and accessible, however for using this as a library I want to use a custom installed boost to match the version of boost used by the application. Most of the changes to CMakeLists are to use find_package to locate the desired boost libraries. I believe this is the preferred way to include boost libraries. Also, this changed to allow llvm to be installed to a specified directory. This change allows the developer to work with multiple different versions for different projects. The bootstrap.sh changes include: - This also includes a change to specify the exact directory for phasar to be installed to. This allows the developer to have multiple installations. - The git submodule init / update was required for a fresh install. I'm guessing this was just accidentally commented out. - Removed the package libmysqlcppconn-dev which isn't necessary to copmile. Perhaps there's another dependency somewhere else, but I specifically removed this because it also pulls in a bunch of other dependencies (notably boost, and I specifically do not want the maintaner's version of boost installed). - Added ability to specify the boost install dir to use. - Added ability to run unit tests (I haven't verified this functionality, but it did work prior to the big merge last week).
1 parent 3350ebc commit 444c928

17 files changed

Lines changed: 139 additions & 129 deletions

File tree

CMakeLists.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ include_directories(
9191
# Threads
9292
find_package(Threads)
9393

94+
# Fix boost_thread dependency for MacOS
95+
if(APPLE)
96+
set(BOOST_THREAD thread-mt)
97+
else()
98+
set(BOOST_THREAD thread)
99+
endif()
100+
101+
# Boost
102+
find_package(Boost 1.66.0 COMPONENTS filesystem graph system program_options log ${BOOST_THREAD} REQUIRED)
103+
include_directories(${Boost_INCLUDE_DIRS})
104+
add_definitions(-DBOOST_LOG_DYN_LINK)
105+
94106
# JSON library
95107
option(JSON_BuildTests OFF)
96108
add_subdirectory(external/json EXCLUDE_FROM_ALL)
@@ -111,11 +123,6 @@ endif()
111123
add_subdirectory(external/WALi-OpenNWA)
112124
include_directories(external/WALi-OpenNWA/Source/wali/include)
113125

114-
# Boost
115-
find_package(Boost COMPONENTS filesystem graph system program_options log thread REQUIRED)
116-
include_directories(${BOOST_INCLUDE_DIR})
117-
add_definitions(-DBOOST_LOG_DYN_LINK)
118-
119126
# SQL
120127
find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h)
121128
find_library(SQLITE3_LIBRARY NAMES sqlite3)
@@ -203,13 +210,6 @@ llvm_map_components_to_libnames(llvm_libs
203210
# phasar-based binaries
204211
add_subdirectory(tools)
205212

206-
# Fix boost_thread dependency for MacOS
207-
if(APPLE)
208-
set(BOOST_THREAD boost_thread-mt)
209-
else()
210-
set(BOOST_THREAD boost_thread)
211-
endif()
212-
213213
# Workaround: Remove Plugins for MacOS for now
214214
if(APPLE)
215215
set(PHASAR_PLUGINS_LIB)

bootstrap.sh

Lines changed: 82 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#!/bin/bash
22
set -e
33

4+
readonly PHASAR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5+
readonly PHASAR_INSTALL_DIR="/usr/local/phasar"
6+
readonly LLVM_INSTALL_DIR="/usr/local/llvm-9"
7+
48
NUM_THREADS=$(nproc)
59
LLVM_RELEASE=llvmorg-9.0.0
10+
DO_UNIT_TEST=false
11+
612

713
# Parsing command-line-parameters
814
# See "https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash" as a reference
@@ -18,6 +24,19 @@ case $key in
1824
shift # past argument
1925
shift # past value
2026
;;
27+
-u|--unittest)
28+
DO_UNIT_TEST=true
29+
shift # past argument
30+
;;
31+
-DBOOST_DIR)
32+
DESIRED_BOOST_DIR="$2"
33+
shift # past argument
34+
shift # past value
35+
;;
36+
-DBOOST_DIR=*)
37+
DESIRED_BOOST_DIR="${key#*=}"
38+
shift # past argument=value
39+
;;
2140
-DBOOST_VERSION)
2241
DESIRED_BOOST_VERSION="$2"
2342
shift # past argument
@@ -41,79 +60,87 @@ set -- "${POSITIONAL[@]}" # restore positional parameters
4160
echo "installing phasar dependencies..."
4261

4362
sudo apt-get update
44-
sudo apt-get install zlib1g-dev sqlite3 libsqlite3-dev libmysqlcppconn-dev bear python3 doxygen graphviz python python-dev python3-pip python-pip libxml2 libxml2-dev libncurses5-dev libncursesw5-dev swig build-essential g++ cmake libz3-dev libedit-dev python-sphinx libomp-dev libcurl4-openssl-dev -y
63+
sudo apt-get install zlib1g-dev sqlite3 libsqlite3-dev bear python3 doxygen graphviz python python-dev python3-pip python-pip libxml2 libxml2-dev libncurses5-dev libncursesw5-dev swig build-essential g++ cmake libz3-dev libedit-dev python-sphinx libomp-dev libcurl4-openssl-dev -y
4564
sudo pip install Pygments
4665
sudo pip install pyyaml
47-
# installing boost
48-
#wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
49-
#tar xvf boost_1_66_0.tar.gz
50-
#cd boost_1_66_0/
51-
#./bootstrap.sh
52-
#sudo ./b2 install
53-
#cd ..
5466

67+
if [ ! -z ${DESIRED_BOOST_DIR} ]; then
68+
BOOST_PARAMS="-DBOOST_ROOT=${DESIRED_BOOST_DIR}"
69+
else
5570
# New way of installing boost:
56-
5771
# Check whether we have the required boost packages installed
58-
59-
BOOST_VERSION=$(echo -e '#include <boost/version.hpp>\nBOOST_LIB_VERSION' | gcc -s -x c++ -E - 2>/dev/null| grep "^[^#;]" | tr -d '\"')
60-
61-
if [ -z $BOOST_VERSION ] ;then
62-
if [ -z $DESIRED_BOOST_VERSION ] ;then
63-
sudo apt-get install libboost-all-dev -y
64-
else
65-
# DESIRED_BOOST_VERSION in form d.d, i.e. 1.65 (this is the latest version I found in the apt repo)
66-
sudo apt-get install "libboost${DESIRED_BOOST_VERSION}-all-dev" -y
67-
fi
68-
#verify installation
69-
BOOST_VERSION=$(echo -e '#include <boost/version.hpp>\nBOOST_LIB_VERSION' | gcc -s -x c++ -E - 2>/dev/null| grep "^[^#;]" | tr -d '\"')
70-
if [ -z $BOOST_VERSION ] ;then
71-
echo "Failed installing boost $DESIRED_BOOST_VERSION"
72-
exit 1
73-
else
74-
echo "Successfully installed boost v${BOOST_VERSION//_/.}"
75-
fi
76-
else
77-
echo "Already installed boost version ${BOOST_VERSION//_/.}"
78-
DESIRED_BOOST_VERSION=${BOOST_VERSION//_/.}
79-
# install missing packages if necessary
80-
boostlibnames=("libboost-system" "libboost-filesystem"
81-
"libboost-graph" "libboost-program-options"
82-
"libboost-log" "libboost-thread")
83-
additional_boost_libs=()
84-
85-
for boost_lib in ${boostlibnames[@]}; do
86-
dpkg -s "$boost_lib${DESIRED_BOOST_VERSION}" >/dev/null 2>&1 || additional_boost_libs+=("$boost_lib${DESIRED_BOOST_VERSION}")
87-
done
88-
if [ ${#additional_boost_libs[@]} -gt 0 ] ;then
89-
echo "Installing additional ${#additional_boost_libs[@]} boost packages: ${additional_boost_libs[@]}"
90-
sudo apt-get install ${additional_boost_libs[@]} -y
91-
fi
72+
BOOST_VERSION=$(echo -e '#include <boost/version.hpp>\nBOOST_LIB_VERSION' | gcc -s -x c++ -E - 2>/dev/null| grep "^[^#;]" | tr -d '\"')
73+
74+
if [ -z $BOOST_VERSION ] ;then
75+
if [ -z $DESIRED_BOOST_VERSION ] ;then
76+
sudo apt-get install libboost-all-dev -y
77+
else
78+
# DESIRED_BOOST_VERSION in form d.d, i.e. 1.65 (this is the latest version I found in the apt repo)
79+
sudo apt-get install "libboost${DESIRED_BOOST_VERSION}-all-dev" -y
80+
fi
81+
#verify installation
82+
BOOST_VERSION=$(echo -e '#include <boost/version.hpp>\nBOOST_LIB_VERSION' | gcc -s -x c++ -E - 2>/dev/null| grep "^[^#;]" | tr -d '\"')
83+
if [ -z $BOOST_VERSION ] ;then
84+
echo "Failed installing boost $DESIRED_BOOST_VERSION"
85+
exit 1
86+
else
87+
echo "Successfully installed boost v${BOOST_VERSION//_/.}"
88+
fi
89+
else
90+
echo "Already installed boost version ${BOOST_VERSION//_/.}"
91+
DESIRED_BOOST_VERSION=${BOOST_VERSION//_/.}
92+
# install missing packages if necessary
93+
boostlibnames=("libboost-system" "libboost-filesystem"
94+
"libboost-graph" "libboost-program-options"
95+
"libboost-log" "libboost-thread")
96+
additional_boost_libs=()
97+
98+
for boost_lib in ${boostlibnames[@]}; do
99+
dpkg -s "$boost_lib${DESIRED_BOOST_VERSION}" >/dev/null 2>&1 || additional_boost_libs+=("$boost_lib${DESIRED_BOOST_VERSION}")
100+
done
101+
if [ ${#additional_boost_libs[@]} -gt 0 ] ;then
102+
echo "Installing additional ${#additional_boost_libs[@]} boost packages: ${additional_boost_libs[@]}"
103+
sudo apt-get install ${additional_boost_libs[@]} -y
104+
fi
105+
fi
92106
fi
93107

94108

95109

96110
# installing LLVM
97-
./utils/install-llvm.sh $NUM_THREADS . $LLVM_RELEASE
98-
# installing wllvm
111+
tmp_dir=`mktemp -d "llvm-9_build.XXXXXXXX" --tmpdir`
112+
./utils/install-llvm.sh ${NUM_THREADS} ${tmp_dir} ${LLVM_INSTALL_DIR} ${LLVM_RELEASE}
113+
rm -rf ${tmp_dir}
99114
sudo pip3 install wllvm
100115

101116
echo "dependencies successfully installed"
102-
echo "build phasar..."
117+
echo "Building PhASAR..."
118+
${DO_UNIT_TESTS} && echo "with unit tests."
103119

104-
#git submodule init
105-
#git submodule update
120+
git submodule init
121+
git submodule update
106122

107-
export CC=/usr/local/bin/clang
108-
export CXX=/usr/local/bin/clang++
123+
export CC=${LLVM_INSTALL}/bin/clang
124+
export CXX=${LLVM_INSTALL}/bin/clang++
109125

110-
mkdir -p build
111-
cd build
112-
cmake -DCMAKE_BUILD_TYPE=Release ..
126+
mkdir -p ${PHASAR_DIR}/build
127+
cd ${PHASAR_DIR}/build
128+
cmake -DCMAKE_BUILD_TYPE=Release ${BOOST_PARAMS} -DPHASAR_BUILD_UNITTESTS=${DO_UNIT_TEST} ${PHASAR_DIR}
113129
make -j $NUM_THREADS
130+
131+
if ${DO_UNIT_TEST}; then
132+
echo "Running PhASAR unit tests..."
133+
pushd unittests
134+
for x in `find . -type f -executable -print`; do
135+
pushd ${x%/*} && ./${x##*/} && popd || { echo "Test ${x} failed, aborting."; exit 1; };
136+
done
137+
popd
138+
fi
139+
114140
echo "phasar successfully built"
115141
echo "install phasar..."
116-
sudo make install
142+
sudo cmake -DCMAKE_INSTALL_PREFIX=${PHASAR_INSTALL_DIR} -P cmake_install.cmake
143+
117144
sudo ldconfig
118145
cd ..
119-
echo "phasar successfully installed"
146+
echo "phasar successfully installed to ${PHASAR_INSTALL_DIR}"

lib/Controller/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ else()
3030
)
3131
endif()
3232

33+
find_package(Boost COMPONENTS log REQUIRED)
3334
target_link_libraries(phasar_controller
3435
LINK_PUBLIC
3536
curl
36-
boost_log
37+
${Boost_LIBRARIES}
3738
)
3839

3940
set_target_properties(phasar_controller

lib/PhasarClang/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ else()
1919
)
2020
endif()
2121

22+
find_package(Boost COMPONENTS log REQUIRED)
2223
target_link_libraries(phasar_clang
2324
LINK_PUBLIC
2425
clangTooling
@@ -42,8 +43,7 @@ target_link_libraries(phasar_clang
4243
clangLex
4344
clangBasic
4445

45-
boost_log
46-
boost_system
46+
${Boost_LIBRARIES}
4747
)
4848

4949
set_target_properties(phasar_clang

lib/PhasarLLVM/DataFlowSolver/WPDS/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ else()
2222
)
2323
endif()
2424

25+
find_package(Boost COMPONENTS filesystem REQUIRED)
2526
target_link_libraries(phasar_wpds
2627
LINK_PUBLIC
27-
boost_filesystem
28-
boost_system
28+
${Boost_LIBRARIES}
2929
)
3030

3131
set_target_properties(phasar_wpds

lib/PhasarLLVM/Passes/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ else()
2222
)
2323
endif()
2424

25+
find_package(Boost COMPONENTS log filesystem REQUIRED)
2526
target_link_libraries(phasar_passes
2627
LINK_PUBLIC
27-
boost_log
28-
boost_filesystem
29-
boost_system
28+
${Boost_LIBRARIES}
3029
)
3130

3231
set_target_properties(phasar_passes

lib/PhasarLLVM/Plugins/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ else()
2626
)
2727
endif()
2828

29+
30+
find_package(Boost COMPONENTS log filesystem program_options REQUIRED)
2931
target_link_libraries(phasar_plugins
3032
LINK_PUBLIC
31-
boost_filesystem
32-
boost_log
33-
boost_program_options
34-
boost_system
33+
${Boost_LIBRARIES}
3534
${CMAKE_DL_LIBS}
3635
)
3736

lib/PhasarLLVM/Pointer/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ else()
3636
)
3737
endif()
3838

39+
find_package(Boost COMPONENTS log filesystem graph REQUIRED)
3940
target_link_libraries(phasar_pointer
40-
LINK_PUBLIC
41-
boost_log
42-
boost_filesystem
43-
boost_graph
44-
boost_system
41+
LINK_PUBLIC
42+
${Boost_LIBRARIES}
4543
)
4644

4745
set_target_properties(phasar_pointer

lib/PhasarLLVM/TypeHierarchy/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ else()
2323
)
2424
endif()
2525

26+
find_package(Boost COMPONENTS log filesystem graph REQUIRED)
2627
target_link_libraries(phasar_typehierarchy
2728
LINK_PUBLIC
28-
boost_log
29-
boost_filesystem
30-
boost_graph
29+
${Boost_LIBRARIES}
3130
)
3231

3332
set_target_properties(phasar_typehierarchy

lib/PhasarLLVM/Utils/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ else()
1818
)
1919
endif()
2020

21+
find_package(Boost COMPONENTS filesystem REQUIRED)
2122
target_link_libraries(phasar_phasarllvm_utils
2223
LINK_PUBLIC
23-
boost_filesystem
24-
boost_system
24+
${Boost_LIBRARIES}
2525
)
2626

2727
set_target_properties(phasar_phasarllvm_utils

0 commit comments

Comments
 (0)