Skip to content

Commit 4a6ba76

Browse files
committed
Test: Fix build for linux
1 parent 61e0fc7 commit 4a6ba76

File tree

3 files changed

+170
-28
lines changed

3 files changed

+170
-28
lines changed

CMakeLists.txt

Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,88 @@ elseif(UNIX AND NOT APPLE)
1919
set(IS_LINUX TRUE)
2020
endif()
2121

22+
# Option to automatically install dependencies
23+
option(AUTO_INSTALL_DEPENDENCIES "Automatically install missing dependencies" OFF)
24+
25+
# Make Boost optional with a warning if not found
26+
option(REQUIRE_BOOST "Require Boost libraries (fail if not found)" OFF)
27+
2228
# Set Boost search paths for common locations
2329
set(BOOST_ROOT "" CACHE PATH "Boost root directory")
2430
set(BOOST_INCLUDEDIR "" CACHE PATH "Boost include directory")
2531
set(BOOST_LIBRARYDIR "" CACHE PATH "Boost library directory")
2632

33+
# Add common Linux Boost installation paths
34+
if(IS_LINUX)
35+
list(APPEND CMAKE_PREFIX_PATH
36+
"/usr"
37+
"/usr/local"
38+
"/usr/lib/x86_64-linux-gnu"
39+
"/usr/include/boost"
40+
"/usr/lib/boost"
41+
)
42+
endif()
43+
2744
# For newer CMake, try to accommodate both old and new ways
28-
if(IS_LINUX OR IS_MACOS)
29-
# First attempt with required components
30-
find_package(Boost COMPONENTS filesystem system program_options)
31-
32-
if(NOT Boost_FOUND)
33-
# Try to find Boost using pkg-config as fallback
34-
find_package(PkgConfig QUIET)
35-
if(PkgConfig_FOUND)
36-
pkg_check_modules(BOOST QUIET boost_system boost_filesystem boost_program_options)
37-
if(BOOST_FOUND)
38-
set(Boost_INCLUDE_DIRS ${BOOST_INCLUDE_DIRS})
39-
set(Boost_LIBRARIES ${BOOST_LIBRARIES})
40-
set(Boost_FOUND TRUE)
41-
endif()
45+
set(Boost_USE_STATIC_LIBS OFF)
46+
set(Boost_USE_MULTITHREADED ON)
47+
set(Boost_NO_BOOST_CMAKE OFF)
48+
49+
# First attempt with required components
50+
find_package(Boost COMPONENTS filesystem system program_options QUIET)
51+
52+
# If not found, try without components
53+
if(NOT Boost_FOUND)
54+
find_package(Boost QUIET)
55+
endif()
56+
57+
# Try to find Boost using pkg-config as last fallback
58+
if(NOT Boost_FOUND)
59+
find_package(PkgConfig QUIET)
60+
if(PkgConfig_FOUND)
61+
pkg_check_modules(BOOST QUIET boost boost_system boost_filesystem boost_program_options)
62+
if(BOOST_FOUND)
63+
set(Boost_INCLUDE_DIRS ${BOOST_INCLUDE_DIRS})
64+
set(Boost_LIBRARIES ${BOOST_LIBRARIES})
65+
set(Boost_FOUND TRUE)
4266
endif()
4367
endif()
68+
endif()
4469

45-
# If still not found, provide a useful error message
46-
if(NOT Boost_FOUND)
70+
# Handle the case when Boost is not found
71+
if(NOT Boost_FOUND)
72+
if(IS_LINUX AND AUTO_INSTALL_DEPENDENCIES)
73+
# Try to automatically install Boost
74+
message(STATUS "Boost not found. Attempting to install dependencies...")
75+
76+
# Make the script executable
77+
execute_process(
78+
COMMAND chmod +x ${CMAKE_SOURCE_DIR}/cmake/install_dependencies.sh
79+
RESULT_VARIABLE CHMOD_RESULT
80+
)
81+
82+
if(CHMOD_RESULT EQUAL 0)
83+
# Run the dependency installation script
84+
execute_process(
85+
COMMAND ${CMAKE_SOURCE_DIR}/cmake/install_dependencies.sh
86+
RESULT_VARIABLE SCRIPT_RESULT
87+
OUTPUT_VARIABLE SCRIPT_OUTPUT
88+
ERROR_VARIABLE SCRIPT_ERROR
89+
)
90+
91+
if(SCRIPT_RESULT EQUAL 0)
92+
message(STATUS "Dependencies installed successfully. Re-run CMake to continue.")
93+
message(FATAL_ERROR "Please run CMake again after dependencies installation.")
94+
else()
95+
message(STATUS "Script output: ${SCRIPT_OUTPUT}")
96+
message(STATUS "Script error: ${SCRIPT_ERROR}")
97+
message(FATAL_ERROR "Failed to install dependencies automatically. Please install them manually or run with elevated privileges.")
98+
endif()
99+
else()
100+
message(FATAL_ERROR "Failed to make dependency script executable. Please install dependencies manually.")
101+
endif()
102+
elseif(REQUIRE_BOOST)
103+
# Only show error if Boost is required
47104
if(IS_LINUX)
48105
message(FATAL_ERROR
49106
"Boost libraries not found. Install them with:\n"
@@ -53,24 +110,31 @@ if(IS_LINUX OR IS_MACOS)
53110
"Then, if needed, specify the location using:\n"
54111
" -DBOOST_ROOT=/path/to/boost\n"
55112
" -DBOOST_INCLUDEDIR=/path/to/boost/include\n"
56-
" -DBOOST_LIBRARYDIR=/path/to/boost/lib"
113+
" -DBOOST_LIBRARYDIR=/path/to/boost/lib\n\n"
114+
"Alternatively:\n"
115+
" - Run cmake with -DREQUIRE_BOOST=OFF to build without Boost support\n"
116+
" - Run cmake with -DAUTO_INSTALL_DEPENDENCIES=ON to attempt automatic installation"
57117
)
58118
elseif(IS_MACOS)
59119
message(FATAL_ERROR
60120
"Boost not found. Install it with:\n"
61-
" brew install boost"
121+
" brew install boost\n\n"
122+
"Alternatively, run cmake with -DREQUIRE_BOOST=OFF to build without Boost support."
62123
)
63124
endif()
125+
else
126+
# Just a warning if Boost is optional
127+
message(STATUS "Boost not found. Building without Boost support.")
128+
# Define a flag to indicate Boost is not available
129+
add_definitions(-DNO_BOOST_AVAILABLE)
64130
endif()
65-
elseif(IS_WINDOWS)
66-
# On Windows, make Boost optional
67-
find_package(Boost COMPONENTS filesystem system program_options)
68131
endif()
69132

70133
include_directories(${CMAKE_SOURCE_DIR}/include)
71134
include_directories(${CMAKE_SOURCE_DIR}/external)
72135
if(Boost_FOUND)
73136
include_directories(${Boost_INCLUDE_DIRS})
137+
add_definitions(-DHAS_BOOST)
74138
endif()
75139

76140
set(PARSER_TYPE "CLI11" CACHE STRING "Type of parser to use (Getopt or CLI11)")

cmake/ikos.cmake

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ find_library(GMP_LIBRARY NAMES gmp)
55
find_path(GMP_INCLUDE_DIR NAMES gmp.h)
66

77
if(NOT GMP_LIBRARY OR NOT GMP_INCLUDE_DIR)
8-
if(IS_MACOS)
9-
message(WARNING "GMP not found. Install it with 'brew install gmp' on macOS. IKOS analysis will be disabled.")
10-
elseif(IS_LINUX)
11-
message(WARNING "GMP not found. Install it with 'apt-get install libgmp-dev' on Linux. IKOS analysis will be disabled.")
12-
else()
13-
message(WARNING "GMP not found. IKOS analysis will be disabled.")
8+
if(IS_LINUX AND AUTO_INSTALL_DEPENDENCIES)
9+
message(STATUS "GMP not found. It will be installed by the dependency script if AUTO_INSTALL_DEPENDENCIES is enabled.")
10+
else
11+
if(IS_MACOS)
12+
message(WARNING "GMP not found. Install it with 'brew install gmp' on macOS. IKOS analysis will be disabled.")
13+
elseif(IS_LINUX)
14+
message(WARNING "GMP not found. Install it with 'apt-get install libgmp-dev' on Linux or run CMake with -DAUTO_INSTALL_DEPENDENCIES=ON. IKOS analysis will be disabled.")
15+
else()
16+
message(WARNING "GMP not found. IKOS analysis will be disabled.")
17+
endif()
18+
return()
1419
endif()
15-
return()
1620
endif()
1721

1822
# Boost - use same approach as main CMakeLists to ensure compatibility

cmake/install_dependencies.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
# Script to install dependencies for CoreTrace project
4+
set -e
5+
6+
echo "Installing dependencies for CoreTrace..."
7+
8+
# Detect distribution
9+
if [ -f /etc/debian_version ]; then
10+
# Debian/Ubuntu
11+
echo "Detected Debian/Ubuntu system"
12+
13+
# Check if running as root, if not use sudo
14+
if [ $(id -u) -ne 0 ]; then
15+
SUDO="sudo"
16+
else
17+
SUDO=""
18+
fi
19+
20+
echo "Updating package lists..."
21+
$SUDO apt-get update
22+
23+
echo "Installing Boost..."
24+
$SUDO apt-get install -y libboost-all-dev
25+
26+
# Install other dependencies needed for IKOS
27+
echo "Installing other dependencies..."
28+
$SUDO apt-get install -y libgmp-dev libtbb-dev libsqlite3-dev python3-dev
29+
30+
# LLVM 14 might need a specific repository
31+
if ! dpkg -l | grep -q "llvm-14"; then
32+
echo "LLVM 14 not found, adding LLVM repository..."
33+
$SUDO apt-get install -y software-properties-common wget
34+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | $SUDO apt-key add -
35+
$SUDO add-apt-repository "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-14 main"
36+
$SUDO apt-get update
37+
$SUDO apt-get install -y llvm-14 llvm-14-dev
38+
fi
39+
40+
elif [ -f /etc/redhat-release ]; then
41+
# RHEL/CentOS/Fedora
42+
echo "Detected RHEL/CentOS/Fedora system"
43+
44+
if [ $(id -u) -ne 0 ]; then
45+
SUDO="sudo"
46+
else
47+
SUDO=""
48+
fi
49+
50+
echo "Installing Boost..."
51+
$SUDO dnf install -y boost-devel
52+
53+
# Install other dependencies
54+
echo "Installing other dependencies..."
55+
$SUDO dnf install -y gmp-devel tbb-devel sqlite-devel python3-devel
56+
57+
# LLVM 14 might need special handling
58+
if ! rpm -qa | grep -q "llvm14"; then
59+
echo "LLVM 14 installation may require manual steps. Please visit https://releases.llvm.org/download.html"
60+
fi
61+
62+
else
63+
echo "Unsupported Linux distribution. Please install dependencies manually:"
64+
echo "- Boost (libboost-all-dev)"
65+
echo "- GMP (libgmp-dev)"
66+
echo "- TBB (libtbb-dev)"
67+
echo "- SQLite (libsqlite3-dev)"
68+
echo "- Python3 (python3-dev)"
69+
echo "- LLVM 14"
70+
exit 1
71+
fi
72+
73+
echo "Dependencies installation completed!"
74+
exit 0

0 commit comments

Comments
 (0)