3.28RC3 and xcframeworks

I’ve been trying out the 3.28RC3 and to me it looks like building against xcframeworks is not really working yet. I built a minimal project using a prebuilt xcframework and I tried building against it both directly specifying the path to the xcframework in add_library, creating an imported target and setting its IMPORTED_LOCATION property or using find_library. In all cases compiling the C++ file that uses the framework does not work since the include folder does not seem to be added the the compilation command.

Here’s the simple test file I’m using:

#include <opencv2/opencv.hpp>

int foo() {
    cv::Mat img = cv::imread("input.jpg");
    if (img.empty()) {
        printf("Could not open or find the image\n");
        return -1;
    }
    cv::Mat img_gray;
    cv::cvtColor(img, img_gray, cv::COLOR_BGR2GRAY);
    cv::imwrite("output.jpg", img_gray);
    return 0;
}

And here’s the CMakeLists.txt file:

cmake_minimum_required(VERSION 3.28)
project(GrayscaleConverter LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 14)

add_library(OpenCV SHARED IMPORTED)
set_target_properties(OpenCV PROPERTIES IMPORTED_LOCATION <PATH_TO_THE_FILE>/opencv2.xcframework)

add_library(GrayscaleConverter STATIC foo.cc)

target_link_libraries(GrayscaleConverter OpenCV)

install(TARGETS GrayscaleConverter DESTINATION lib)

@kyle.edwards