google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
10.99k stars 2.1k forks source link

CMake FetchContent, Cannot Find target Zlib::Zlib #4281

Closed FlorianXXIV closed 2 months ago

FlorianXXIV commented 2 months ago

What version of OR-Tools and what language are you using? Version: main Language: C++

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)

What operating system (Linux, Windows, ...) and version?

What did you do? Steps to reproduce the behavior:

  1. In the Projects CMakeLists I added:
    
    include(FetchContent)
    FetchContent_Declare(
        or-tools
        GIT_REPOSITORY https://github.com/google/or-tools.git
        GIT_TAG        main
    )

FetchContent_MakeAvailable(or-tools)

target_link_libraries( PRIVATE ortools::ortools)

3. I then executed `cmake -DBUILD_DEPS=ON ..` in my build directory.
5. After going through I got the Following error

CMake Error at build/_deps/or-tools-src/cmake/deps.cmake:29 (message): Target ZLIB::ZLIB not available. Call Stack (most recent call first): build/_deps/or-tools-src/CMakeLists.txt:429 (include) -- Configuring incomplete, errors occurred! See also "/build/CMakeFiles/CMakeOutput.log". See also "/build/CMakeFiles/CMakeError.log". make: *** No targets specified and no makefile found. Stop.


(path to build omitted)
**What did you expect to see**
CMake successfully including the or-tools library
**What did you see instead?**
the error shown above

**Anything else we should know about your project / environment**

The CMake version is 3.29.6-1
I am using the CLion IDE version 1:2024.1.4-1

Disabling BUILD_DEPS and enabling building everything except BUILD_ZLIB worked without issue, since I have zlib on my system, but that isn't a satisfying solution to this problem.

This is my CMakeLists for the project. 
[CMakeLists.txt](https://github.com/user-attachments/files/15945237/CMakeLists.txt)
Mizux commented 2 months ago

I think you need to set

set(BUILD_DEPS ON)

before the FetchContent_MakeAvailable(or-tools) see: https://github.com/or-tools/cmake_or-tools/blob/7bfb4a04518d377d88c342637c46bf6faad3c3a0/CMakeLists.txt#L87-L96

FlorianXXIV commented 2 months ago

clion-Debug-log.txt CMakeLists.txt

I tried doing that but I still get the same error. I have added the debug log and changed CMakeLists.txt, it seems to fail after cloning cbc.

FlorianXXIV commented 2 months ago

Ok, I have found the issue. I am using curl for people (cpr) in the project as well, and that builds curl which also builds zlib, having both or-tools and curl install zlib separatly seemed to have caused the issue. I have now restructured the make available statements and made cpr look for curl instead of building it itself.

This is the CMakeLists that worked for me CMakeLists.txt having the following order of make available statements

set(SKIP_TESTS ON)
set(SKIP_EXAMPLES ON)
set(SKIP_BENCHMARKS ON)
FetchContent_MakeAvailable(graaflib)
set(BUILD_DEPS ON)
set(BUILD_EXAMPLES OFF)
set(BUILD_SAMPLES OFF)
set(BUILD_DOC OFF)
set(USE_SCIP OFF)
set(USE_HIGHS OFF)
FetchContent_MakeAvailable(or-tools)
set(CPR_USE_SYSTEM_CURL ON)
FetchContent_MakeAvailable(cpr)
FetchContent_MakeAvailable(argparse)
FetchContent_MakeAvailable(plog)
FetchContent_MakeAvailable(json)