Hi guy's,
I got into a problem writing a Conan recipe for a library created with AutoTools
The library requires OpenSSL, which was normally specified via a fixed relative path in the Makefile.
Like this:
ifeq (,$(findstring DUSE_OPENSSL,$(CFLAGS)))
INCLUDE_PATH += -I../../openssl/install/include/openssl -I../../openssl/install/include
endif
#Compile c source file in static dir
$(SDIR)/%.o: %.c $(LIB_HEADERS) | $(SDIR)
@echo 'Compiling file (static): $<'
$(CC) $(COMPILE_OPTION) $(INCLUDE_PATH) $(CFLAGS) $(EXTRA_CFLAGS) -o $@ -c $<
@echo 'Finished compiling: $<'
@echo ''
But now the OpenSSL is also built with Conan and is therefore no longer in the specified directory. So I have to tell the library where the OpenSSL is located without changing the official Makefile too much. I thought of the FindOpenSSL.cmake and overwrite the variable INCLUDE_PATH with the OpenSSL_INCLUDES. However, I don't know how I can get this variable with the Conan tools.
The repice:
def requirements(self):
self.requires("openssl/1.1.1d@conan-center/stable")
def build(self):
autotools = AutoToolsBuildEnvironment(self)
env_vars = autotools.vars
env_vars['INCLUDE_PATH'] = '$(OpenSSL_INCLUDES)' # TODO
build_args = []
if self.settings.os == "Linux":
build_args.append("TARGET_PLATFORM=LINUX_ZIP2")
elif self.settings.os == "Macos":
build_args.append("TARGET_PLATFORM=OSX_ZIP2")
build_args.append("DEBUG=%s" % ("1" if self.settings.build_type == "Debug" else "0"))
build_args.append("SHARED=%s" % ("1" if self.options.shared == True else "0"))
autotools.make(vars=env_vars, args=build_args)
Is there a special procedure for that I am not yet familiar with?
Hi @FohlenAFK
You might get access to the Openssl package folders via the self.deps_cpp_info interface: https://docs.conan.io/en/latest/reference/conanfile/attributes.html#deps-cpp-info
So something like this:
def build(self):
autotools = AutoToolsBuildEnvironment(self)
env_vars = autotools.vars
openssl_includes = self.deps_cpp_info["openssl"].include_paths
# we don't want to fully overwrite the INCLUDE_PATHS, it might contain other things?
# maybe replacing in the file?
# https://docs.conan.io/en/latest/reference/tools.html#tools-replace-in-file
tools.replace_in_file("Makefile",
"INCLUDE_PATH += -I../../openssl/install/include/openssl -I../../openssl/install/include",
"INCLUDE_PATH += %s" % " ".join(openssl_includes)
Hi @memsharded
Thanks a lot. That worked fine, easier than I thought!
Most helpful comment
Hi @FohlenAFK
You might get access to the Openssl package folders via the
self.deps_cpp_infointerface: https://docs.conan.io/en/latest/reference/conanfile/attributes.html#deps-cpp-infoSo something like this: