Skip to content

Commit

Permalink
(#18741) openfx: migrate to Conan v2
Browse files Browse the repository at this point in the history
* openfx: migrate to Conan v2

* openfx: add OpenGL dep to CMakeLists.txt

* openfx: restore VirtualRunEnv in test_package

---------

Co-authored-by: Carlos Zoido <[email protected]>
  • Loading branch information
valgur and czoido authored Aug 6, 2023
1 parent 37c9c3a commit c53c2c0
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 61 deletions.
20 changes: 9 additions & 11 deletions recipes/openfx/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.12)
project(openfx VERSION 1.4.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-D_HAS_AUTO_PTR_ETC)

# Flags
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWINDOWS -DNOMINMAX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWINDOWS -DNOMINMAX -D_WIN32")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-deprecated -Wno-deprecated-declarations")
add_definitions(-Dlinux)
endif()

# Conan
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(KEEP_RPATHS)
find_package(EXPAT REQUIRED)
find_package(expat REQUIRED)
find_package(OpenGL REQUIRED)

# Macros
set(SOURCE_SUBFOLDER ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder)
set(SOURCE_SUBFOLDER ${CMAKE_CURRENT_LIST_DIR}/src)

# Sources
set(OFX_HEADER_DIR "${SOURCE_SUBFOLDER}/include")
Expand Down Expand Up @@ -50,7 +50,7 @@ add_library(OfxHost
${OFX_HOSTSUPPORT_HEADER_FILES}
${OFX_HOSTSUPPORT_LIBRARY_FILES})

target_link_libraries(OfxHost PUBLIC EXPAT::EXPAT)
target_link_libraries(OfxHost PUBLIC expat::expat OpenGL::GL)

target_include_directories(OfxHost PUBLIC
${OFX_HEADER_DIR}
Expand All @@ -68,7 +68,5 @@ install(FILES
${OFX_HOSTSUPPORT_HEADER_FILES}
DESTINATION "include")

install(TARGETS OfxSupport OfxHost
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
include(GNUInstallDirs)
install(TARGETS OfxSupport OfxHost)
106 changes: 65 additions & 41 deletions recipes/openfx/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,99 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir

required_conan_version = ">=1.53.0"


class openfx(ConanFile):
name = "openfx"
description = "OpenFX image processing plug-in standard."
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://openeffects.org"
description = "OpenFX image processing plug-in standard."
topics = ("image-processing", "standard")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"fPIC": True,
"shared": False,
"fPIC": True,
}
requires = ("opengl/system", "expat/2.4.8")
exports_sources = "CMakeLists.txt", "cmake/*", "symbols/*"

generators = "cmake", "cmake_find_package"
_cmake = None
def export_sources(self):
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)
copy(self, "*",
src=os.path.join(self.recipe_folder, "cmake"),
dst=os.path.join(self.export_sources_folder, "cmake"))
copy(self, "*",
src=os.path.join(self.recipe_folder, "symbols"),
dst=os.path.join(self.export_sources_folder, "symbols"))

def source(self):
tools.get(
**self.conan_data["sources"][self.version],
destination="source_subfolder",
strip_root=True
)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("opengl/system")
self.requires("expat/2.5.0")

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure()
return self._cmake
def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def build(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure(build_script_folder=self.source_path.parent)
cmake.build()

@property
def _build_modules(self):
return [os.path.join("lib", "cmake", "OpenFX.cmake")]

def package(self):
cmake = self._configure_cmake()

tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

cmake = CMake(self)
cmake.install()

self.copy("*.symbols", src="symbols", dst="lib/symbols")
self.copy("*.cmake", src="cmake", dst="lib/cmake")
self.copy("LICENSE", src="source_subfolder/Support", dst="licenses")
self.copy("readme.md")
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
copy(self, "*.symbols",
src=os.path.join(self.export_sources_folder, "symbols"),
dst=os.path.join(self.package_folder, "lib", "symbols"))
copy(self, "*.cmake",
src=os.path.join(self.export_sources_folder, "cmake"),
dst=os.path.join(self.package_folder, "lib", "cmake"))
copy(self, "LICENSE",
src=os.path.join(self.source_folder, "Support"),
dst=os.path.join(self.package_folder, "licenses"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "openfx"
self.cpp_info.names["cmake_find_package_multi"] = "openfx"

self.cpp_info.set_property("cmake_file_name", "openfx")
self.cpp_info.set_property("cmake_target_name", "openfx::openfx")
self.cpp_info.set_property("cmake_build_modules", self._build_modules)
self.cpp_info.builddirs.append(os.path.join("lib", "cmake"))
self.cpp_info.build_modules["cmake_find_package"] = self._build_modules
self.cpp_info.build_modules["cmake_find_package_multi"] = self._build_modules

if self.options.shared:
self.cpp_info.libs = ["OfxSupport"]
Expand All @@ -84,5 +102,11 @@ def package_info(self):

if self.settings.os in ("Linux", "FreeBSD"):
self.cpp_info.system_libs.extend(["GL"])
if self.settings.os == "Macos":
if is_apple_os(self):
self.cpp_info.frameworks = ["CoreFoundation", "OpenGL"]

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "openfx"
self.cpp_info.names["cmake_find_package_multi"] = "openfx"
self.cpp_info.build_modules["cmake_find_package"] = self._build_modules
self.cpp_info.build_modules["cmake_find_package_multi"] = self._build_modules
7 changes: 3 additions & 4 deletions recipes/openfx/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-D_HAS_AUTO_PTR_ETC)

# Conan
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
find_package(openfx REQUIRED CONFIG)

# Flags
Expand Down
19 changes: 14 additions & 5 deletions recipes/openfx/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run("%s --help" % bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(f"{bin_path} --help", env="conanrun")
8 changes: 8 additions & 0 deletions recipes/openfx/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
17 changes: 17 additions & 0 deletions recipes/openfx/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run("%s --help" % bin_path, run_environment=True)

0 comments on commit c53c2c0

Please sign in to comment.