Skip to content

Instantly share code, notes, and snippets.

@Talkless
Created October 20, 2020 05:26
Show Gist options
  • Save Talkless/a2eda9abfb005bd314c92140e72c3b2b to your computer and use it in GitHub Desktop.
Save Talkless/a2eda9abfb005bd314c92140e72c3b2b to your computer and use it in GitHub Desktop.
WIP Google ORTools Conan pacakge
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import fnmatch
import os
class ORToolsConan(ConanFile):
name = "ortools"
version = "7.7"
license = "Apache License 2.0"
url = "https://github.com/google/or-tools/"
description = "Google Optimization Tools"
settings = "os", "compiler", "build_type", "arch"
requires = ["abseil/20200225.3@",
"gflags/2.2.2@",
"glog/0.4.0@",
"zlib/1.2.11@",
"protobuf/3.11.4@"]
#build_requires = "protoc_installer/3.9.1@bincrafters/stable",
generators = "cmake_find_package_multi"
options = {
"shared": [True, False],
"fPIC": [True, False]
}
default_options = {'shared': False, 'fPIC': True}
@property
def _archive_url(self):
return "https://github.com/google/or-tools/archive/v7.7.tar.gz"
@property
def source_subfolder(self):
return "source_subfolder"
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.settings.os == "Windows" and self.options.shared:
raise ConanInvalidConfiguration("Shared build is not supported on Windows by upstream")
def source(self):
tools.get(self._archive_url)
archive = "or-tools-{}".format(self.version)
os.rename(archive, self.source_subfolder)
for root, _, files in os.walk(self.source_subfolder):
for filename in files:
if fnmatch.fnmatch(filename, "*.cmake") or filename == "CMakeLists.txt":
full_filename = os.path.join(root, filename)
# No need after abseil Conan package introduced components!
#tools.replace_in_file(full_filename, "abseil::abseil", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::any", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::base", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::cord", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::random_random", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::status", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::container", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::hash", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::memory", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::meta", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::raw_hash_set", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::str_format", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::strings", "absl::absl", False)
#tools.replace_in_file(full_filename, "absl::synchronization", "absl::absl", False)
tools.replace_in_file(full_filename, "protobuf::libprotobuf", "Protobuf::Protobuf", False)
tools.replace_in_file(full_filename, "protobuf::protoc", "protoc", False)
# No longer needed since idk when...
#tools.replace_in_file(os.path.join(self.source_subfolder, "cmake", "cpp.cmake"), "Protobuf", "protobuf")
#tools.replace_in_file(os.path.join(self.source_subfolder, "cmake", "cpp.cmake"), "absl", "abseil")
tools.replace_in_file(os.path.join(self.source_subfolder, "cmake", "cpp.cmake"), "DEPENDS ${PROTO_FILE} protoc", "DEPENDS ${PROTO_FILE}")
# No longer needed since idk when...
#tools.replace_in_file(os.path.join(self.source_subfolder, "makefiles", "Makefile.third_party.unix.mk"), "libabsl_debugging_internal.a", "libabsl_internal_debugging_internal.a")
def _configure_cmake(self):
# make dependecies build in parallel:
with tools.environment_append({"CMAKE_BUILD_PARALLEL_LEVEL": str(os.cpu_count())}):
cmake = CMake(self)
cmake.definitions["BUILD_Cbc"] = True
cmake.definitions["BUILD_Cgl"] = True
cmake.definitions["BUILD_Clp"] = True
cmake.definitions["BUILD_CoinUtils"] = True
cmake.definitions["BUILD_Osi"] = True
cmake.definitions["BUILD_TESTING"] = False
cmake.definitions["BUILD_absl"] = False
cmake.definitions["BUILD_glags"] = False
cmake.definitions["BUILD_glog"] = False
cmake.configure(source_folder=self.source_subfolder)
return cmake
def build(self):
with tools.chdir(self.source_subfolder):
cmake = self._configure_cmake()
cmake.build()
cmake.install()
def package(self):
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
def package_info(self):
self.cpp_info.libs = ["ortools"]
self.cpp_info.includedirs = ['include']
self.cpp_info.libdirs = ['lib']
@Talkless
Copy link
Author

Oh you mean other dependencies must be compiled in C++17..? Ouch...

@philsuess
Copy link

Oh you mean other dependencies must be compiled in C++17..? Ouch...

I know. See "Known Breaking Change" on https://github.com/google/or-tools/releases/tag/v8.0

@philsuess
Copy link

I think I've had enough. I will start using CLP's bare interface. It's too annoying to keep up with google's strange notions of project management. -For example, were you aware that abseil maintainers strongly discourage maintaining a binary library and instead recommend building from source at head?? No wonder we can't get ortools from conan. It's a f@*$ing hydra!

Thanks for your conanfile, though. I'll push my latest version here soon. Maybe you see something there that can help you.

Cheers!

@Talkless
Copy link
Author

It's a f@*$ing hydra!

Haha :) . Yeah Google practices are strange. I understand that it works for their internal ~200mil. code base, but for others, for FOSS projects..?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment