Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Add option to build static binaries #113

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ project (ethos_checker)

# >> 2-valued: ON OFF
# > for options where we don't need to detect if set by user (default: OFF)
option(ENABLE_ORACLES "Enable support for Oracles" ON)
option(BUILD_STATIC "Build static binary" OFF)
option(ENABLE_ORACLES "Enable support for Oracles" ON)

if(BUILD_STATIC)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
# Linking system libraries statically is strongly discouraged on macOS.
# See https://developer.apple.com/library/archive/qa/qa1118/_index.html
if(NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-static")
endif()
endif()

set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

Expand Down
13 changes: 13 additions & 0 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ General options;
--prefix=STR install directory
--name=STR use custom build directory name (optionally: +path)


Features:
The following flags enable optional features (disable with --no-<option name>).
--static build static binary [default=no]


CMake Options (Advanced)
-DVAR=VALUE manually add CMake options

Expand Down Expand Up @@ -48,6 +54,8 @@ install_prefix=default

buildtype=default

build_static=default

#--------------------------------------------------------------------------#

cmake_opts=""
Expand All @@ -72,6 +80,9 @@ do
--name) die "missing argument to $1 (try -h)" ;;
--name=*) build_dir=${1##*=} ;;

--static) build_static=ON;;
--no-static) build_static=OFF;;

-D*) cmake_opts="${cmake_opts} $1" ;;

-*) die "invalid option '$1' (try -h)";;
Expand All @@ -92,6 +103,8 @@ done
&& cmake_opts="$cmake_opts -DCMAKE_BUILD_TYPE=$buildtype"
[ "$install_prefix" != default ] \
&& cmake_opts="$cmake_opts -DCMAKE_INSTALL_PREFIX=$install_prefix"
[ $build_static != default ] \
&& cmake_opts="$cmake_opts -DBUILD_STATIC=$build_static"

uname_output=$(uname)
[[ $uname_output =~ ^MSYS || $uname_output =~ ^MINGW ]] \
Expand Down
Loading