Skip to content

Commit 4d23ead

Browse files
committed
static cpack
1 parent cd1c63e commit 4d23ead

File tree

6 files changed

+197
-24
lines changed

6 files changed

+197
-24
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# !!! note
2+
# This file is a version of the file we use to package HiGHS for the Julia
3+
# ecosystem. If you make changes to this file during the development of
4+
# HiGHS, please tag `@odow` so we can make the correponding changes to:
5+
# https://github.com/JuliaPackaging/Yggdrasil/blob/master/H/HiGHS
6+
7+
using BinaryBuilder, Pkg
8+
9+
name = "HiGHS"
10+
version = VersionNumber(ENV["HIGHS_RELEASE"])
11+
12+
sources = [GitSource(ENV["HIGHS_URL"], ENV["HIGHS_COMMIT"])]
13+
14+
script = raw"""
15+
export BUILD_SHARED="OFF"
16+
export BUILD_STATIC="ON"
17+
18+
cd $WORKSPACE/srcdir/HiGHS
19+
20+
# Remove system CMake to use the jll version
21+
apk del cmake
22+
23+
mkdir -p build
24+
cd build
25+
26+
# Do fully static build only on Windows
27+
if [[ "${BUILD_SHARED}" == "OFF" ]] && [[ "${target}" == *-mingw* ]]; then
28+
export CXXFLAGS="-static"
29+
fi
30+
31+
cmake -DCMAKE_INSTALL_PREFIX=${prefix} \
32+
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
33+
-DCMAKE_BUILD_TYPE=Release \
34+
-DBUILD_SHARED_LIBS=${BUILD_SHARED} \
35+
-DZLIB_USE_STATIC_LIBS=${BUILD_STATIC} \
36+
-DHIPO=ON \
37+
-DBUILD_STATIC_EXE=ON \
38+
-DBLAS_LIBRARIES="${libdir}/libopenblas.${dlext}" \
39+
..
40+
41+
if [[ "${target}" == *-linux-* ]]; then
42+
make -j ${nproc}
43+
else
44+
if [[ "${target}" == *-mingw* ]]; then
45+
cmake --build . --config Release
46+
else
47+
cmake --build . --config Release --parallel
48+
fi
49+
fi
50+
make install
51+
52+
install_license ../LICENSE.txt
53+
"""
54+
55+
products = [
56+
LibraryProduct("libhighs", :libhighs),
57+
ExecutableProduct("highs", :highs),
58+
]
59+
60+
platforms = supported_platforms()
61+
platforms = expand_cxxstring_abis(platforms)
62+
63+
dependencies = [
64+
Dependency("CompilerSupportLibraries_jll"),
65+
Dependency("Zlib_jll"),
66+
Dependency("OpenBLAS32_jll"),
67+
HostBuildDependency(PackageSpec(; name="CMake_jll")),
68+
]
69+
70+
build_tarballs(
71+
ARGS,
72+
name,
73+
version,
74+
sources,
75+
script,
76+
platforms,
77+
products,
78+
dependencies;
79+
preferred_gcc_version = v"6",
80+
julia_compat = "1.6",
81+
)

.github/workflows/release-cpack.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ jobs:
1919
cmake --build build -j2
2020
cd build && cpack
2121
22+
# cmake -B build \
23+
# -DCMAKE_BUILD_TYPE=Release \
24+
# -DBUILD_SHARED_LIBS=OFF \
25+
# -DCMAKE_EXE_LINKER_FLAGS="-static -static-libgcc -static-libstdc++" \
26+
# .
27+
2228
- name: Upload artifacts
2329
uses: actions/upload-artifact@v4
2430
with:

.github/workflows/release.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Cross-compilation of HiGHS -- x86_64-linux-gnu-cxx11
3434
run: |
3535
julia --color=yes -e 'using Pkg; Pkg.add("BinaryBuilder")'
36-
julia --color=yes .github/julia/build_tarballs.jl x86_64-linux-gnu-cxx11 --verbose
36+
julia --color=yes .github/julia/build_tarballs_release.jl x86_64-linux-gnu-cxx11 --verbose
3737
3838
- name: Archive artifact
3939
run: julia --color=yes .github/julia/generate_binaries.jl
@@ -69,7 +69,7 @@ jobs:
6969
- name: Cross-compilation of HiGHS -- aarch64-linux-gnu-cxx11
7070
run: |
7171
julia --color=yes -e 'using Pkg; Pkg.add("BinaryBuilder")'
72-
julia --color=yes .github/julia/build_tarballs.jl aarch64-linux-gnu-cxx11 --verbose
72+
julia --color=yes .github/julia/build_tarballs_release.jl aarch64-linux-gnu-cxx11 --verbose
7373
7474
- name: Archive artifact
7575
run: julia --color=yes .github/julia/generate_binaries.jl
@@ -105,7 +105,7 @@ jobs:
105105
- name: Cross-compilation of HiGHS -- x86_64-w64-mingw32-cxx11
106106
run: |
107107
julia --color=yes -e 'using Pkg; Pkg.add("BinaryBuilder")'
108-
julia --color=yes .github/julia/build_tarballs.jl x86_64-w64-mingw32-cxx11 --verbose
108+
julia --color=yes .github/julia/build_tarballs_release.jl x86_64-w64-mingw32-cxx11 --verbose
109109
- name: Archive artifact
110110
run: julia --color=yes .github/julia/generate_binaries.jl
111111

@@ -139,7 +139,7 @@ jobs:
139139
- name: Cross-compilation of HiGHS -- x86_64-apple-darwin-cxx11
140140
run: |
141141
julia --color=yes -e 'using Pkg; Pkg.add("BinaryBuilder")'
142-
julia --color=yes .github/julia/build_tarballs.jl x86_64-apple-darwin-cxx11 --verbose
142+
julia --color=yes .github/julia/build_tarballs_release.jl x86_64-apple-darwin-cxx11 --verbose
143143
144144
- name: Archive artifact
145145
run: julia --color=yes .github/julia/generate_binaries.jl
@@ -174,7 +174,7 @@ jobs:
174174
- name: Cross-compilation of HiGHS -- aarch64-apple-darwin-cxx11
175175
run: |
176176
julia --color=yes -e 'using Pkg; Pkg.add("BinaryBuilder")'
177-
julia --color=yes .github/julia/build_tarballs.jl aarch64-apple-darwin-cxx11 --verbose
177+
julia --color=yes .github/julia/build_tarballs_release.jl aarch64-apple-darwin-cxx11 --verbose
178178
179179
- name: Archive artifact
180180
run: julia --color=yes .github/julia/generate_binaries.jl

CMakeLists.txt

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,25 @@ if(HIPO)
197197
include(FindHipoDeps)
198198
endif()
199199

200+
# Option to build static
201+
option(BUILD_STATIC_EXE "Build static executable" OFF)
202+
203+
if(BUILD_STATIC_EXE)
204+
set(BUILD_SHARED_LIBS OFF)
205+
206+
# Link statically on Linux
207+
if(UNIX AND NOT APPLE)
208+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
209+
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
210+
endif()
211+
212+
# Windows: link runtime statically
213+
if(MSVC)
214+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
215+
endif()
216+
endif()
217+
218+
200219
if (BUILD_CXX)
201220
# Default Build Type to be Release
202221
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
@@ -410,6 +429,10 @@ else()
410429
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
411430
endif()
412431

432+
# In your CMakeLists.txt
433+
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "cli;libs")
434+
435+
413436
if(NOT FAST_BUILD)
414437
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${HIGHS_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
415438
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${HIGHS_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
@@ -842,6 +865,52 @@ else(FAST_BUILD)
842865

843866
endif()
844867

868+
# Detect system information
869+
if(UNIX AND NOT APPLE)
870+
set(OS_NAME "linux")
871+
elseif(APPLE)
872+
set(OS_NAME "apple")
873+
elseif(WIN32)
874+
set(OS_NAME "windows")
875+
else()
876+
set(OS_NAME "unknown")
877+
endif()
878+
879+
# Get architecture
880+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
881+
set(ARCH "x86_64")
882+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64")
883+
set(ARCH "aarch64")
884+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
885+
set(ARCH "arm")
886+
else()
887+
set(ARCH ${CMAKE_SYSTEM_PROCESSOR})
888+
endif()
889+
890+
# Get libc info (for Linux)
891+
if(UNIX AND NOT APPLE)
892+
execute_process(
893+
COMMAND ldd --version
894+
OUTPUT_VARIABLE LDD_OUTPUT
895+
ERROR_VARIABLE LDD_OUTPUT
896+
)
897+
if(LDD_OUTPUT MATCHES "musl")
898+
set(LIBC "musl")
899+
else()
900+
set(LIBC "gnu")
901+
endif()
902+
set(PLATFORM "${ARCH}-${OS_NAME}-${LIBC}")
903+
else()
904+
set(PLATFORM "${ARCH}-${OS_NAME}")
905+
endif()
906+
907+
# Set CPack filename
908+
if(BUILD_STATIC_EXE)
909+
set(CPACK_PACKAGE_FILE_NAME "highs-${VERSION}-${PLATFORM}-static")
910+
else()
911+
set(CPACK_PACKAGE_FILE_NAME "highs-${VERSION}-${PLATFORM}")
912+
endif()
913+
845914
if(NOT CPack_CMake_INCLUDED)
846915
include(CPack)
847916
endif()
@@ -856,3 +925,7 @@ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "\
856925
Open source serial and parallel solvers for large-scale sparse \
857926
linear programming (LP), mixed-integer programming (MIP), and \
858927
quadratic programming (QP) models")
928+
929+
set(CPACK_COMPONENTS_ALL cli libs)
930+
set(CPACK_COMPONENT_CLI_DISPLAY_NAME "HiGHS CLI (static)")
931+
set(CPACK_COMPONENT_LIBS_DISPLAY_NAME "HiGHS Libraries")

app/CMakeLists.txt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,35 @@ if(FAST_BUILD)
3232

3333
include(GNUInstallDirs)
3434

35-
if(APPLE)
36-
set_target_properties(highs-bin PROPERTIES INSTALL_RPATH
37-
"@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path")
38-
elseif (UNIX)
39-
set_target_properties(highs-bin PROPERTIES INSTALL_RPATH
40-
"$ORIGIN:$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
41-
42-
# cmake_path is 3.20, leave for later.
43-
# cmake_path(RELATIVE_PATH CMAKE_INSTALL_FULL_LIBDIR
44-
# BASE_DIRECTORY ${CMAKE_INSTALL_FULL_BINDIR}
45-
# OUTPUT_VARIABLE libdir_relative_path)
46-
# set_target_properties(highs-bin PROPERTIES INSTALL_RPATH
47-
# "$ORIGIN/${libdir_relative_path}")
35+
if (NOT BUILD_STATIC_EXE)
36+
if(APPLE)
37+
set_target_properties(highs-bin PROPERTIES INSTALL_RPATH
38+
"@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path")
39+
elseif (UNIX)
40+
set_target_properties(highs-bin PROPERTIES INSTALL_RPATH
41+
"$ORIGIN:$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
42+
43+
# cmake_path is 3.20, leave for later.
44+
# cmake_path(RELATIVE_PATH CMAKE_INSTALL_FULL_LIBDIR
45+
# BASE_DIRECTORY ${CMAKE_INSTALL_FULL_BINDIR}
46+
# OUTPUT_VARIABLE libdir_relative_path)
47+
# set_target_properties(highs-bin PROPERTIES INSTALL_RPATH
48+
# "$ORIGIN/${libdir_relative_path}")
49+
endif()
50+
else()
51+
# Remove or disable any SET_TARGET_PROPERTIES for RPATH on the static binary
52+
# Or add this after the install command:
53+
set_target_properties(highs-bin PROPERTIES
54+
SKIP_BUILD_RPATH TRUE
55+
SKIP_INSTALL_RPATH TRUE
56+
)
4857
endif()
4958

5059
# install the binary
51-
install(TARGETS highs-bin
52-
EXPORT highs-targets
53-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
60+
install(TARGETS highs-bin
61+
EXPORT highs-target
62+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
63+
COMPONENT cli)
5464

5565
if(BUILD_TESTING)
5666
if (APPLE)

cmake/cpp-highs.cmake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ install(TARGETS highs
5555
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
5656
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
5757
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
58-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
58+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
59+
COMPONENT libs)
5960

6061
if (NOT HIGHS_COVERAGE)
6162
# Add library targets to the build-tree export set
@@ -70,7 +71,8 @@ if (CUPDLP_GPU)
7071
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
7172
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
7273
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
73-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
74+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
75+
COMPONENT libs)
7476

7577
if (NOT HIGHS_COVERAGE)
7678
# Add library targets to the build-tree export set
@@ -86,7 +88,8 @@ if (BUILD_OPENBLAS)
8688
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
8789
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
8890
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
89-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
91+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
92+
COMPONENT libs)
9093

9194
if (NOT HIGHS_COVERAGE)
9295
# Add library targets to the build-tree export set

0 commit comments

Comments
 (0)