What version of OR-Tools and what language are you using?
Version: v9.15
Language: C++
cmake version 4.3.2
Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
none, this is a cmake issue
What operating system (Linux, Windows, ...) and version?
Linux
What did you do?
Steps to reproduce the behavior:
- Create cmake project that tries to consume or-tools
if(NOT ORTOOLS_FOUND)
find_package(ortools CONFIG QUIET
HINTS ${_ortools_hints}
PATHS ${_ortools_search_paths}
PATH_SUFFIXES lib/cmake/ortools)
if(TARGET ortools::ortools)
set(ORTOOLS_LIBRARIES ortools::ortools)
get_target_property(_ortools_inc ortools::ortools INTERFACE_INCLUDE_DIRECTORIES)
if(_ortools_inc)
set(ORTOOLS_INCLUDE_DIRS "${_ortools_inc}")
endif()
if(DEFINED ortools_VERSION)
set(ORTOOLS_VERSION "${ortools_VERSION}")
endif()
endif()
endif()
...
target_link_libraries(my_target PRIVATE ortools::ortools)
- Run cmake
- See error
What did you expect to see
CMake configuration and generation to complete successfully, producing valid build files.
What did you see instead?
-- Found OR-Tools 9.15.9999 -- FindORTOOLS.cmake
-- Configuring done (0.8s)
-- Generating done (0.2s)
CMake Error:
Error evaluating generator expression:
$<TARGET_OBJECTS:ortools_math_opt_core>
Objects of target "ortools_math_opt_core" referenced but no such target exists.
CMake Error:
Error evaluating generator expression:
$<TARGET_OBJECTS:ortools_math_opt_constraints_indicator>
Objects of target "ortools_math_opt_constraints_indicator" referenced but no such target exists.
-- Build files have been written to: ...
[Failed to reload]
Anything else we should know about your project / environment
some ideas about resolution
CMakeLists.txt target_sources is called with the PUBLIC keyword for $<TARGET_OBJECTS:...>:
ortools/math_opt/CMakeLists.txt:
cmaketarget_sources(${NAME} PUBLIC # <<< maybe should be private?
$<TARGET_OBJECTS:${NAME}_core>
$<TARGET_OBJECTS:${NAME}_core_c_api>
$<TARGET_OBJECTS:${NAME}_cpp>
$<TARGET_OBJECTS:${NAME}_elemental>
$<TARGET_OBJECTS:${NAME}_io>
$<TARGET_OBJECTS:${NAME}_labs>
$<TARGET_OBJECTS:${NAME}_solvers>
$<TARGET_OBJECTS:${NAME}_storage>
$<TARGET_OBJECTS:${NAME}_validators>
)
ortools/math_opt/constraints/CMakeLists.txt
cmaketarget_sources(${NAME} PUBLIC # <<< same
$<TARGET_OBJECTS:${NAME}_indicator>
$<TARGET_OBJECTS:${NAME}_quadratic>
$<TARGET_OBJECTS:${NAME}_second_order_cone>
$<TARGET_OBJECTS:${NAME}_sos>
$<TARGET_OBJECTS:${NAME}_util>
)
and then:
install(TARGETS ortools_math_opt EXPORT ortoolsTargets)
Using PUBLIC propagates these $<TARGET_OBJECTS:...> expressions into the exported target's INTERFACE_SOURCES and INTERFACE_LINK_LIBRARIES.
What version of OR-Tools and what language are you using?
Version: v9.15
Language: C++
cmake version 4.3.2
Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
none, this is a cmake issue
What operating system (Linux, Windows, ...) and version?
Linux
What did you do?
Steps to reproduce the behavior:
What did you expect to see
CMake configuration and generation to complete successfully, producing valid build files.
What did you see instead?
Anything else we should know about your project / environment
some ideas about resolution
CMakeLists.txt target_sources is called with the PUBLIC keyword for $<TARGET_OBJECTS:...>:
ortools/math_opt/CMakeLists.txt:
ortools/math_opt/constraints/CMakeLists.txt
and then:
install(TARGETS ortools_math_opt EXPORT ortoolsTargets)Using PUBLIC propagates these $<TARGET_OBJECTS:...> expressions into the exported target's INTERFACE_SOURCES and INTERFACE_LINK_LIBRARIES.