OpenCV3 block with ci_make_app

I’m trying to make a simple cmake based app with openCV with the following CMakeLists.txt:

    cmake_minimum_required(VERSION 3.8)
    set( CMAKE_VERBOSE_MAKEFILE ON )
    project(ritratto)

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

    get_filename_component( CINDER_PATH "~/Repositories/Cinder" ABSOLUTE )
    get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE )

    include( ${CINDER_PATH}/proj/cmake/modules/cinderMakeApp.cmake )

    ci_make_app(
            APP_NAME    "Ritratto"
            CINDER_PATH ${CINDER_PATH}
            SOURCES     ${APP_PATH}/src/main.cpp
            INCLUDES    ${APP_PATH}/include
            BLOCKS      ${CINDER_PATH}/blocks/Cinder-OpenCV3
    ) 

But I get the following warning from CMake and the compiler fails to find OpenCV:

CMake Warning at /Users/mattia/Repositories/Cinder/proj/cmake/modules/cinderMakeApp.cmake:145 (find_package):
  Could not find a package configuration file provided by "Cinder-OpenCV3"
  with any of the following names:

    Cinder-OpenCV3Config.cmake
    cinder-opencv3-config.cmake

  Add the installation prefix of "Cinder-OpenCV3" to CMAKE_PREFIX_PATH or set
  "Cinder-OpenCV3_DIR" to a directory containing one of the above files.  If
  "Cinder-OpenCV3" provides a separate development package or SDK, be sure it
  has been installed.

I tried adding another cinder block (Box2D) and that seemed to work fine, and I noticed that Box2D contained a cmake file while the OpenCV3 one did not. Is there something I’m doing wrong or is the OpenCV3 block not compatible with ci_make_app?

Hi @Ghirigoro

No, it doesn’t seem to have support for Cinder’s new CMake configuration. I have done it in the past but things have changed completely since then.

In which platform are you trying to run this on?

If it is macOS or Linux you could probably get away by installing OpenCV3 systemwide and then using something like the following CMakeLists.txt for compiling the ocvBasic sample:

cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
set( CMAKE_VERBOSE_MAKEFILE ON )

project( ocvBasic )

get_filename_component( CINDER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../" 
    
get_filename_component( APP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../" ABSOLUTE )

include( "${CINDER_PATH}/proj/cmake/modules/cinderMakeApp.cmake" )

find_package(  OpenCV 3 REQUIRED )

ci_make_app(
    SOURCES     ${APP_PATH}/src/ocvBasicApp.cpp    
    INCLUDES    ${APP_PATH}/../../../../include
    CINDER_PATH ${CINDER_PATH}
    LIBRARIES   ${OpenCV_LIBS}
)

The paths assume that the CMakeLists.txt file is located under :

${CINDER_PATH}/blocks/Cinder-OpenCV3/samples/ocvBasic/proj/cmake

This is off the top of my head and untested but it should be the in right direction to get you started if interested.

Cheers,
Petros

That did the trick. Thanks so much.