or-tools / cmake_or-tools

Modern CMake C++ Sample using google/or-tools
Apache License 2.0
6 stars 0 forks source link

Unable to find_package after a source build in custom location #1

Open onecable5781 opened 5 months ago

onecable5781 commented 5 months ago

Hi @Mizux

I am trying to follow the advice you gave me over on the other thread.

As indicated there, I have installed OR Tools on Windows Visual Studio 2022 using the steps mentioned on the website.

Now, I performed the steps exactly as mentioned on https://developers.google.com/optimization/install/cpp/source_windows

from my local drive: E:\ortools

Now, after all steps are run, the folder structure is E:\ortools\or-tools\ .git and other subfolders here such as bazel\ , binder\ , build\ , cmake\ , ortools\ etc.

I have my project folder elsewhere, say, C:\myproject\CMakeLists.txt

Within this CMakeLists.txt, the following find_package() line fails.

 set(ortools_loc_2 "E:\\ortools\\or-tools\\ortools")
 if(EXISTS "${ortools_loc_2}" AND IS_DIRECTORY "${ortools_loc_2}")
     message(STATUS "ortools exists on this machine")
     set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "E:\\ortools\\or-tools\\ortools") # should ideally go in presets file see https://www.reddit.com/r/cpp_questions/comments/17r5g6r/comment/k8imfvs/
     find_package(ortools CONFIG REQUIRED)
     set(ortoolsfound 1)

Could you please suggest how I can inform my project's CMakeLists.txt to find the source built ORTools of my custom location?

Thanks.

onecable5781 commented 5 months ago

Just want to add that when I changed the location as follows:

set(ortools_loc_2 "E:\ortools\or-tools\build")

it "works" but fails subsequently with the following error:

1> [CMake] CMake Error at E:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
1> [CMake]   Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.11")
1> [CMake] Call Stack (most recent call first):
1> [CMake]   E:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
1> [CMake]   E:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/FindZLIB.cmake:200 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
1> [CMake]   E:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/CMakeFindDependencyMacro.cmake:76 (find_package)
1> [CMake]   E:/ortools/or-tools/build/ortoolsConfig.cmake:25 (find_dependency)
1> [CMake]   CMakeLists.txt:219 (find_package)
Mizux commented 5 months ago

this template project automatically fetch and rebuild the or-tools project, it doesn't depend on any prebuilt. see https://github.com/or-tools/cmake_or-tools/blob/7bfb4a04518d377d88c342637c46bf6faad3c3a0/CMakeLists.txt#L87-L96

For your own issue trying to use the prebuilt please provide a minimal reproducible example.

onecable5781 commented 5 months ago

Actually, I want to avoid usage of FetchContent because within each of my projects, it ends up creating almost 2 GB of stuff. I was hoping to use a single build in a custom location once and then access this from multiple projects all using different components of OR tools without having to FetchContent individually for each project. I don't have so much hard disk space.

On delving into this further, with the same CMakeLists.txt and opening the project in Linux, the build works fine.

I am able to see CMake output indicate that the ZLib version found was 1.2.13

On Windows, the ZLib version found is only 1.2.11 and it is failing in this step.

Is there a minimum version requirement of ZLib within ortools?

Regarding minimum example, I am not sure what that would be -- all I did was I followed the steps in https://developers.google.com/optimization/install/cpp/source_windows this morning (so, the code is most recent) and built it as instructed on that site with -DBUILD_DEPS=ON

So, I would imagine the above built the latest zlib directory. However, the version picked on my Windows machine is still lower than what I found on my Linux machine. If you do have access to a Windows machine/VS2022, could you please let me know what ZLib version you find?

Thanks for the continued support and sorry for lack of a minimal example -- it is just that I am not sure what that would be in this case, perhaps I am stuck with an older Windows/VS Version and hence ZLib is not up to date?

Mizux commented 5 months ago

strange, ZLIB is build using https://github.com/google/or-tools/blob/5f7eabb3ffa1de786c224a722f0e9561101c3ab2/cmake/dependencies/CMakeLists.txt#L60-L71