Files
ortools-clone/patches/soplex-v7.1.3.patch
Corentin Le Molgat 5587f01a23 dependencies: Fix MACOSX_RPATH usage (#4674)
1. This is a boolean property which must be set to TRUE or FALSE
   If TRUE, the default, cmake will use @rpath as directory portion (aka prefix) of the  install_name (otool LC_ID_DYLIB)
   note: CMP0042 set it to TRUE by default
2. To change this prefix you must use INSTALL_NAME_DIR
3. To change the INSTALL_RPATH (otool LC_RPATH) (e.g. to set it to @loader_path) you must use the INSTALL_RPATH property.

ref:
https://cmake.org/cmake/help/latest/variable/CMAKE_MACOSX_RPATH.html
https://cmake.org/cmake/help/latest/prop_tgt/MACOSX_RPATH.html
https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_RPATH.html
https://cmake.org/cmake/help/latest/policy/CMP0042.html
2025-06-11 17:57:43 +02:00

242 lines
9.1 KiB
Diff

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0b21f5a..6f08341 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,10 @@ set(CPACK_PACKAGE_VERSION_PATCH "${SOPLEX_VERSION_PATCH}")
set(CPACK_PACKAGE_VENDOR "Zuse Institute Berlin")
include(CPack)
+# Disable CTest targets
+set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
+include(CTest)
+
option(ZLIB "Use ZLIB" ON)
option(GMP "Use GMP" ON)
option(EMSCRIPTEN_HTML "Emscripten HTML output" OFF)
@@ -43,11 +47,17 @@ option(SANITIZE_THREAD "should the thread sanitizer be enabled in debug mode if
option(COVERAGE "enable coverage support" OFF)
option(PAPILO "should papilo library be linked" ON)
+option(SOPLEX_EXAMPLE "Build example" OFF)
+option(SOPLEX_SOPLEX "Build soplex program" OFF)
+option(SOPLEX_EXPORT "Enable to use soplex from the current project's build tree, without installation." OFF)
+
SET(COVERAGE_CTEST_ARGS "" CACHE STRING "additional ctest arguments for coverage")
-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+if(CMAKE_PROJECT_NAME EQUAL "SOPLEX")
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+endif()
# for colorized output
if(NOT WIN32)
@@ -65,10 +75,12 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
# set the correct rpath for OS X
-set(CMAKE_MACOSX_RPATH ON)
+set(CMAKE_MACOSX_RPATH TRUE)
# use C++14 standard
set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
# set function visibility default to hidden
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
@@ -123,12 +135,11 @@ if(COVERAGE)
endif()
if(ZLIB)
- find_package(ZLIB)
-endif()
-if(ZLIB_FOUND)
- set(SOPLEX_WITH_ZLIB on)
- set(libs ${libs} ${ZLIB_LIBRARIES})
- include_directories(${ZLIB_INCLUDE_DIRS})
+ if(NOT TARGET ZLIB::ZLIB)
+ find_package(ZLIB REQUIRED)
+ endif()
+ set(SOPLEX_WITH_ZLIB on)
+ set(libs ${libs} ZLIB::ZLIB)
endif()
if(GMP)
@@ -170,39 +181,24 @@ else()
set(SOPLEX_WITH_PAPILO off)
endif()
-set(BOOST_MINIMUM_VERSION 1.65.0)
+set(BOOST_MINIMUM_VERSION 1.65.0) # PaPILO requires at least Boost 1.65 (on mac 1.72)
if(BOOST)
- find_package(Boost ${BOOST_MINIMUM_VERSION}) # PaPILO requires at least Boost 1.65 (on mac 1.72)
- if(Boost_FOUND)
- set(SOPLEX_WITH_BOOST on)
- include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
- if(NOT Boost_VERSION_MACRO)
- set(Boost_VERSION_MACRO ${Boost_VERSION})
- endif()
- if(${Boost_VERSION_MACRO} LESS "107000")
- if(NOT SOPLEX_WITH_GMP)
- message(SEND_ERROR "If no GMP is linked, then the minimal Boost verion is 1.70. \
- Found Boost version is ${Boost_VERSION_STRING}. Either provide newer Boost, link GMP, or disable Boost by setting BOOST=off.")
- else()
- message(WARNING "The multiprecision and quadprecision features are disabled with Boost versions older than 1.70. \
- Found Boost version is ${Boost_VERSION_STRING}.")
- endif()
- endif()
- if(MPFR) # MPFR is used within boost multiprecision, so using it without Boost does not make sense
- find_package(MPFR)
- endif()
- if(MPFR_FOUND)
- message(STATUS "SoPlex with Boost MPFR libraries")
- set(SOPLEX_WITH_MPFR on)
- include_directories(${MPFR_INCLUDE_DIRS})
- set(libs ${libs} ${MPFR_LIBRARIES})
- else()
- message(STATUS "SoPlex with Boost CPP multiprecision libraries")
- set(SOPLEX_WITH_CPPMPF on)
- endif()
- else()
- set(BOOST off)
- endif()
+ if(NOT TARGET Boost::multiprecision OR NOT TARGET Boost::serialization)
+ message(FATAL_ERROR "Boost::multiprecision or Boost::serialization not available!!!")
+ find_package(Boost ${BOOST_MINIMUM_VERSION} REQUIRED)
+ endif()
+ set(SOPLEX_WITH_BOOST on)
+ set(libs ${libs} Boost::multiprecision Boost::serialization)
+ if(MPFR) # MPFR is used within boost multiprecision, so using it without Boost does not make sense
+ find_package(MPFR REQUIRED)
+ message(STATUS "SoPlex with Boost MPFR libraries")
+ set(SOPLEX_WITH_MPFR on)
+ include_directories(${MPFR_INCLUDE_DIRS})
+ set(libs ${libs} ${MPFR_LIBRARIES})
+ else()
+ message(STATUS "SoPlex with Boost CPP multiprecision libraries")
+ set(SOPLEX_WITH_CPPMPF on)
+ endif()
endif()
# disable fused floating point contraction to enhance reproducibility across compilers and architectures
@@ -247,7 +243,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/soplex/config.h.in ${PROJECT_BINA
configure_file(${PROJECT_SOURCE_DIR}/soplex-config.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/soplex-config.cmake" @ONLY)
add_subdirectory(src)
-add_subdirectory(tests/c_interface)
-add_subdirectory(check)
-
-enable_testing()
+if(BUILD_TESTING)
+ add_subdirectory(tests/c_interface)
+ add_subdirectory(check)
+endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 84ec5a5..4552300 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -3,8 +3,8 @@
#
function(setLibProperties targetname outputname)
set_target_properties(${targetname} PROPERTIES
- OUTPUT_NAME ${outputname}
- MACOSX_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
+ OUTPUT_NAME ${outputname}
+ )
endfunction(setLibProperties)
include(GNUInstallDirs)
@@ -193,24 +193,28 @@ target_link_libraries(libsoplexshared libsoplex ${libs})
set_target_properties(libsoplexshared PROPERTIES CXX_VISIBILITY_PRESET default)
# create soplex binary using library without pic
-add_executable(soplex soplexmain.cpp)
-target_link_libraries(soplex LINK_PUBLIC libsoplex ${Boost_LIBRARIES})
+if(SOPLEX_SOPLEX)
+ add_executable(soplex EXCLUDE_FROM_ALL soplexmain.cpp)
+ target_link_libraries(soplex PRIVATE libsoplex ${Boost_LIBRARIES})
+
+ # set the install rpath to the installed destination
+ set_target_properties(soplex PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
-if(EMSCRIPTEN AND EMSCRIPTEN_HTML)
+ if(EMSCRIPTEN AND EMSCRIPTEN_HTML)
set_target_properties(soplex PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/soplex_webdemo_shell.html)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
-endif()
+ endif()
-if(CMAKE_BUILD_TYPE EQUAL "Debug")
- find_package(Sanitizers)
- add_sanitizers(soplex)
+ if(CMAKE_BUILD_TYPE EQUAL "Debug")
+ find_package(Sanitizers)
+ add_sanitizers(soplex)
+ endif()
endif()
-add_executable(example EXCLUDE_FROM_ALL example.cpp)
-target_link_libraries(example libsoplex)
-
-# set the install rpath to the installed destination
-set_target_properties(soplex PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
+if(SOPLEX_EXAMPLE)
+ add_executable(example example.cpp)
+ target_link_libraries(example libsoplex)
+endif()
# install the header files of soplex
install(FILES ${headers} ${PROJECT_BINARY_DIR}/soplex/config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/soplex)
@@ -237,15 +241,28 @@ install(FILES
DESTINATION include/soplex/external/zstr)
# install the binary and the library to appropriate lcoations and add them to an export group
-install(TARGETS soplex libsoplex libsoplex-pic libsoplexshared EXPORT soplex-targets
+if(SOPLEX_SOPLEX)
+ install(TARGETS soplex
+ EXPORT soplex-targets
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+endif()
+
+install(TARGETS libsoplex libsoplex-pic libsoplexshared
+ EXPORT soplex-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+install(EXPORT soplex-targets
+ FILE soplex-targets.cmake
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/soplex)
+
# Add library targets to the build-tree export set
-export(TARGETS libsoplex libsoplex-pic libsoplexshared
- FILE "${CMAKE_BINARY_DIR}/soplex-targets.cmake")
+if(SOPLEX_EXPORT)
+ export(TARGETS libsoplex libsoplex-pic libsoplexshared
+ FILE "${CMAKE_BINARY_DIR}/soplex-targets.cmake")
+endif()
#configure the config file for the build tree
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}")
@@ -259,7 +276,6 @@ ${CMAKE_BINARY_DIR}/soplex-config-version.cmake
COMPATIBILITY SameMajorVersion
)
-
#configure the config file for the install
set(CONF_INCLUDE_DIRS "\${CMAKE_CURRENT_LIST_DIR}/../../../include")
configure_file(${PROJECT_SOURCE_DIR}/soplex-config.cmake.in
@@ -267,7 +283,6 @@ configure_file(${PROJECT_SOURCE_DIR}/soplex-config.cmake.in
# install the targets of the soplex export group and the config file so that other projects
# can link easily against soplex
-install(EXPORT soplex-targets FILE soplex-targets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/soplex)
install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/soplex-config.cmake"
${CMAKE_BINARY_DIR}/soplex-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/soplex)