Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve usage for library consumers #2321

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,31 +204,7 @@ endif()

find_package(sirius_solver REQUIRED)

find_package(ortools)
if(NOT ortools_FOUND OR BUILD_ORTOOLS)
message(STATUS "OR-Tools tag ${ORTOOLS_TAG}")
FetchContent_Declare(ortools
GIT_REPOSITORY "https://github.com/rte-france/or-tools-rte"
GIT_TAG ${ORTOOLS_TAG}
GIT_SHALLOW TRUE
)

# Pass options to OR-Tools's CMake
set(BUILD_DEPS "ON" CACHE INTERNAL "")
set(BUILD_SAMPLES "OFF" CACHE INTERNAL "")
set(BUILD_FLATZINC "OFF" CACHE INTERNAL "")
set(BUILD_EXAMPLES "OFF" CACHE INTERNAL "")
set(USE_SCIP "ON" CACHE INTERNAL "")
set(USE_GLPK "ON" CACHE INTERNAL "")
# We build OR-Tools as a static lib. Cyclic dependencies are detected
# without this flag.
set(BUILD_SHARED_LIBS "OFF" CACHE INTERNAL "")
# In mode optimization error analysis, we call Sirius through or-tools
# So we need to activate Sirius in or-tools configuration (OFF by default)
set(USE_SIRIUS "ON" CACHE INTERNAL "")

FetchContent_MakeAvailable(ortools)
endif()
include(cmake/ensure_ortools.cmake)

find_package(minizip-ng QUIET)
if (minizip-ng_FOUND)
Expand Down
27 changes: 27 additions & 0 deletions src/cmake/ensure_ortools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include(FetchContent)
find_package(ortools QUIET)
if (NOT ortools_FOUND OR BUILD_ORTOOLS)
message(STATUS "OR-Tools tag ${ORTOOLS_TAG}")
FetchContent_Declare(ortools
GIT_REPOSITORY "https://github.com/rte-france/or-tools-rte"
GIT_TAG ${ORTOOLS_TAG}
GIT_SHALLOW TRUE
)

# Pass options to OR-Tools's CMake
set(BUILD_DEPS "ON" CACHE INTERNAL "")
set(BUILD_SAMPLES "OFF" CACHE INTERNAL "")
set(BUILD_FLATZINC "OFF" CACHE INTERNAL "")
set(BUILD_EXAMPLES "OFF" CACHE INTERNAL "")
set(USE_SCIP "ON" CACHE INTERNAL "")
set(USE_GLPK "ON" CACHE INTERNAL "")
# We build OR-Tools as a static lib. Cyclic dependencies are detected
# without this flag.
set(BUILD_SHARED_LIBS "OFF" CACHE INTERNAL "")
# In mode optimization error analysis, we call Sirius through or-tools
# So we need to activate Sirius in or-tools configuration (OFF by default)
set(USE_SIRIUS "ON" CACHE INTERNAL "")

FetchContent_MakeAvailable(ortools)
endif ()
find_package(ortools REQUIRED)
14 changes: 14 additions & 0 deletions src/cmake/ensure_sirius.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include(FetchContent)
find_package(sirius_solver QUIET)
if (NOT sirius_solver_FOUND)
include(FetchContent)
message("SIRIUS not found, fetching it from github")
FetchContent_Declare(sirius_solver
GIT_REPOSITORY https://github.com/AntaresSimulatorTeam/sirius-solver.git
GIT_TAG feature/antares_integ_fix_include
SOURCE_SUBDIR src
OVERRIDE_FIND_PACKAGE ON
)
FetchContent_MakeAvailable(sirius_solver)
endif ()
find_package(sirius_solver REQUIRED)
59 changes: 30 additions & 29 deletions src/cmake/utils.cmake
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
macro(copy_dependency deps target)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
get_target_property( DEP_SHARED_LIB_PATH ${deps} IMPORTED_LOCATION_RELEASE )
else()
get_target_property( DEP_SHARED_LIB_PATH ${deps} IMPORTED_LOCATION_DEBUG )
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
get_target_property(DEP_SHARED_LIB_PATH ${deps} IMPORTED_LOCATION_RELEASE)
else ()
get_target_property(DEP_SHARED_LIB_PATH ${deps} IMPORTED_LOCATION_DEBUG)
endif ()

if (NOT "${DEP_SHARED_LIB_PATH}" STREQUAL "DEP_SHARED_LIB_PATH-NOTFOUND")
if (NOT "${DEP_SHARED_LIB_PATH}" STREQUAL "DEP_SHARED_LIB_PATH-NOTFOUND")

# Copy the shared lib file
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${DEP_SHARED_LIB_PATH} $<TARGET_FILE_DIR:${target}>)

# Add to install
install(FILES ${DEP_SHARED_LIB_PATH} TYPE BIN)
# Copy the shared lib file
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${DEP_SHARED_LIB_PATH} $<TARGET_FILE_DIR:${target}>)

endif()
# Add to install
install(FILES ${DEP_SHARED_LIB_PATH} TYPE BIN)
install(FILES ${DEP_SHARED_LIB_PATH} TYPE LIB)

endif ()

endmacro()

function(get_linux_lsb_release_information)
find_program(LSB_RELEASE_EXEC lsb_release)
if(NOT LSB_RELEASE_EXEC)
if (NOT LSB_RELEASE_EXEC)

message("Could not detect lsb_release executable, can not gather required information. Use of default information (ID : Linux / Version : Unknown / Codename : Unknown")

set(LSB_RELEASE_ID_SHORT "Linux" PARENT_SCOPE)
set(LSB_RELEASE_VERSION_SHORT "Unknown" PARENT_SCOPE)
set(LSB_RELEASE_CODENAME_SHORT "Unknown" PARENT_SCOPE)
else()
set(LSB_RELEASE_CODENAME_SHORT "Unknown" PARENT_SCOPE)
else ()
execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --id OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --release OUTPUT_VARIABLE LSB_RELEASE_VERSION_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --codename OUTPUT_VARIABLE LSB_RELEASE_CODENAME_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE)

set(LSB_RELEASE_ID_SHORT "${LSB_RELEASE_ID_SHORT}" PARENT_SCOPE)
set(LSB_RELEASE_VERSION_SHORT "${LSB_RELEASE_VERSION_SHORT}" PARENT_SCOPE)
set(LSB_RELEASE_CODENAME_SHORT "${LSB_RELEASE_CODENAME_SHORT}" PARENT_SCOPE)
endif()
endif ()

endfunction()


function(find_python_module module)
set(Python3_FIND_REGISTRY "LAST")
find_package(Python3 COMPONENTS Interpreter)

if(Python3_Interpreter_FOUND)
if (Python3_Interpreter_FOUND)
execute_process(
COMMAND ${Python3_EXECUTABLE} -c "import ${module}"
RESULT_VARIABLE EXIT_CODE
OUTPUT_QUIET
ERROR_QUIET
COMMAND ${Python3_EXECUTABLE} -c "import ${module}"
RESULT_VARIABLE EXIT_CODE
OUTPUT_QUIET
ERROR_QUIET
)

if (${EXIT_CODE} EQUAL 0)
set(PYTHON_MODULE_${module}_FOUND "true" PARENT_SCOPE)
endif()
endif()
endif ()

endif ()

endfunction()
3 changes: 3 additions & 0 deletions src/packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/AntaresConfigVersion.cmake"
DESTINATION lib/cmake/Antares
)

file(GLOB_RECURSE ensure_files ${CMAKE_SOURCE_DIR}/cmake/ensure*.cmake)
install(FILES ${ensure_files} DESTINATION lib/cmake/Antares)
13 changes: 10 additions & 3 deletions src/packaging/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ else ()
message (FATAL_ERROR "Minizip dependency (minizip or minizip-ng) not found.")
endif ()
endif ()
find_dependency(ortools REQUIRED)
find_dependency(sirius_solver REQUIRED)

if (ANTARES_INSTALL_DEPS)
message(STATUS "Installing Antares dependencies")
include( ${CMAKE_CURRENT_LIST_DIR}/ensure_sirius.cmake)
find_dependency(sirius_solver REQUIRED)
include( ${CMAKE_CURRENT_LIST_DIR}/ensure_ortools.cmake)
find_dependency(ortools REQUIRED)
else()
find_dependency(sirius_solver)
find_dependency(ortools)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/AntaresTargets.cmake")

check_required_components(Antares)
Loading