@@ -197,6 +197,25 @@ if(HIPO)
197197 include (FindHipoDeps)
198198endif ()
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+
200219if (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 )
411430endif ()
412431
432+ # In your CMakeLists.txt
433+ set (CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "cli;libs" )
434+
435+
413436if (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
843866endif ()
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+
845914if (NOT CPack_CMake_INCLUDED)
846915 include (CPack)
847916endif ()
@@ -856,3 +925,7 @@ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "\
856925Open source serial and parallel solvers for large-scale sparse \
857926linear programming (LP), mixed-integer programming (MIP), and \
858927quadratic 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" )
0 commit comments