Skip to content

Change CMakelist to acommodate newer SCIP#2

Open
ArvellLeoputra wants to merge 4 commits into
GioniMexi:mainfrom
ArvellLeoputra:main
Open

Change CMakelist to acommodate newer SCIP#2
ArvellLeoputra wants to merge 4 commits into
GioniMexi:mainfrom
ArvellLeoputra:main

Conversation

@ArvellLeoputra

Copy link
Copy Markdown

Background and Problem

In the current CMakeLists.txt file for FeasPumpCollection, the configuration for SCIP is as follows:

find_package(SCIP)
...
if (SCIP_FOUND)
  target_compile_definitions(fp PUBLIC HAS_SCIP=1)
  target_compile_definitions(fp2 PUBLIC HAS_SCIP=1)
  target_sources(fp PRIVATE src/scipmodel.cpp)
  target_link_libraries(fp PUBLIC Scip::Scip)
endif()
...

When using CMake with the command cmake .. -LH, users are required to manually provide the paths to the SCIP libraries and include directories via:

  • -DSCIP_LIB: Path to the SCIP library directory.
  • -DSCIP_INCLUDE_DIR: Path to the SCIP include directory.

In newer versions of SCIP, such as scipoptsuite-9.2.0, the make install step is mandatory after building SCIP to generate the required include directories. These include directories are essential for compiling older projects that depend on SCIP, such as FeasPumpCollection. Without completing the make install step, the headers needed for these projects may not be available.

Solution Inspired by the Sudoku Build Script

The build script for the Sudoku example in SCIP provides a more streamlined approach:

if(TARGET SCIP::SCIP)
  # Find package by SCIP PATH
  find_package(SCIP CONFIG PATHS ${SCIP_BINARY_DIR} REQUIRED)
else()
  find_package(SCIP REQUIRED)
endif()

include_directories(${SCIP_INCLUDE_DIRS})

add_executable(sudoku
   src/sudoku_main.cpp
   src/sudoku_utils.h)

target_link_libraries(sudoku ${SCIP_LIBRARIES})

This script allows users to specify only the SCIP directory via -DSCIP_DIR. Modern versions of SCIP create a CMake package configuration file (SCIPConfig.cmake) during compilation. This file contains all the required informations for CMake to automatically locate SCIP’s headers, libraries, and other configuration settings.

By leveraging this package file, this approach eliminates the need to manually specify separate variables such as SCIP_LIB and SCIP_INCLUDE_DIR, simplifying the integration process and reducing potential errors.

Proposed Changes to FeasPumpCollection Build Script

To adopt this streamlined approach, the CMakeLists.txt file for FeasPumpCollection should be updated as follows:

  1. Add the SCIP include directories via ${SCIP_INCLUDE_DIRS}.
  2. Link SCIP libraries using ${SCIP_LIBRARIES} instead of Scip::Scip.
  3. Ensure FindSCIP.cmake is not used, as it might interfere with the configuration.

Here’s the updated configuration snippet for FeasPumpCollection:

if (SCIP_FOUND)
  target_compile_definitions(fp PUBLIC HAS_SCIP=1)
  target_compile_definitions(fp2 PUBLIC HAS_SCIP=1)
  include_directories(${SCIP_INCLUDE_DIRS}) # Automatically adds SCIP include directories
  target_sources(fp PRIVATE src/scipmodel.cpp)
  target_link_libraries(fp PUBLIC ${SCIP_LIBRARIES}) # Automatically links SCIP libraries
endif()

Addressing FindSCIP.cmake

The presence of FindSCIP.cmake in the module folder can override the manually specified SCIP_DIR variable, potentially leading to incorrect paths or misconfigurations. To ensure proper functionality:

  • Remove FindSCIP.cmake from the module folder if it is not needed.
  • Use find_package(SCIP CONFIG PATHS ...) exclusively, as it directly utilizes SCIP’s provided CMake package configuration.

Notes

These changes improve the build process for projects using SCIP as the solver by leveraging the modern CMake package configuration capabilities. This approach automates the inclusion of necessary paths and libraries, reduces user intervention, and ensures compatibility with recent SCIP versions. Note that these changes apply only when SCIP is the selected solver. Different solvers may require alternative configurations.

Arvell Octavius Leoputra and others added 3 commits January 13, 2025 17:53
  - Update fmt to 11.1.4 (for CMake 4.0)
  - Replace deprecated std::unary/binary_function, random_shuffle                                                                              - Make STLRandGen compatible with std::shuffle
  - Fix empty if bodies and missing return in scipmodel.cpp
  - Remove duplicate libraries in fp2 link line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant