Skip to content

Commit

Permalink
cmake: Add option to build static binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-larraz committed Feb 4, 2025
1 parent 0d49e89 commit 33a0346
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ 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_SHARED_LIBS "Build shared libraries and binary")
option(ENABLE_ORACLES "Enable support for Oracles" ON)

if(NOT BUILD_SHARED_LIBS)
if(NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-static")
endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
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_shared=ON

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

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

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

-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_shared != default ] \
&& cmake_opts="$cmake_opts -DBUILD_SHARED_LIBS=$build_shared"

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

0 comments on commit 33a0346

Please sign in to comment.