CMake find package error

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


NoeMurr
Gnoblar
Posts: 11
Joined: Sat May 18, 2019 1:02 pm

CMake find package error

Post by NoeMurr »

Hi all,

I'm trying Ogre 2.1 just to see if I like how it works.
I found a small problem with CMake:
I have installed on my pc a version 1.9 of ogre (I'm using ubuntu 18.04 LTS so the version is been installed by apt).
As I don't want to change my installation in the root so I downloaded and compiled ogre 2.1.

I decided to create a new blank CMake project with that directory structure:

Code: Select all

project/
    include/
        *.hpp
    src/
        *.cpp
    deps/
    CMakeLists.txt
I installed the version 2.1 in the deps folder with the command `$cmake -DCMAKE_INSTALL_PREFIX=path_to_project/deps -P cmake_install.cmake` from the directory of the build of ogre 2.1.

Now in my CMakeLists.txt I added the deps lib to the CMAKE_PREFIX_PATH and the deps/lib/OGRE/cmake directory to the CMAKE_MODULE_PATH.

Now, if I uninstall the library 1.9 and use the find_package(OGRE) command, all works perfectly, but if I do that with the 1.9 installed the FindOGRE.cmake file will find half of the library of the 2.1 and half of the 1.9! of course that is a problem at link time.

Here you can see my CMakeLists.txt:

Code: Select all

cmake_minimum_required(VERSION 3.14)
project(ogre-test)

## Options and cache variables #################################################

## appending custom cmake modules ##############################################
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/lib/OGRE/cmake")

message(STATUS ${CMAKE_PREFIX_PATH})
message(STATUS ${CMAKE_MODULE_PATH})

## finding packages ############################################################
#set(OGRE_HOME "${CMAKE_CURRENT_SOURCE_DIR}/deps/lib/")
#find_package(OGRE 2.1 REQUIRED PATHS "${CMAKE_CURRENT_SOURCE_DIR}/deps")
#find_package(OGRE 2.1 REQUIRED PATHS "${CMAKE_CURRENT_SOURCE_DIR}/deps/lib")
#find_package(OGRE 2.1 REQUIRED HINTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/lib/OGRE/cmake")
find_package(OGRE 2.1 REQUIRED)

## including directories #######################################################
include_directories(${OGRE_INCLUDE_DIRS})
message(STATUS ${OGRE_LIBRARIES})
message(STATUS ${OGRE_INCLUDE_DIRS})

## Adding subdirs ##############################################################
add_compile_definitions(_DEBUG)
add_executable(test src/main.cpp)
target_link_libraries(test ${OGRE_LIBRARIES})
If I use any of the commented find_package command cmake will complain that it can't find the file
ogre-config.cmake or ogreConfig.cmake, that is understandable because that files does not exists under
the installation folder deps.

here the complete error:

Code: Select all

CMake Error at CMakeLists.txt:15 (find_package):
  Could not find a package configuration file provided by "OGRE" (requested
  version 2.1) with any of the following names:

    OGREConfig.cmake
    ogre-config.cmake

  Add the installation prefix of "OGRE" to CMAKE_PREFIX_PATH or set
  "OGRE_DIR" to a directory containing one of the above files.  If "OGRE"
  provides a separate development package or SDK, be sure it has been
  installed.
I know that I could use the OGRE_BUILD and OGRE_SOURCE directory for giving
directly the source and where I compiled it, but I don't like the idea because it forces me to
compile and build in a specific location or to create a symlink. I would like more to make my
CMakeLists.txt say something like: "allright tell me the install prefix you used to install the lib and I will use it",
without forcing the user to compile Ogre.


In all of that the real problem that I see is that the FindOGRE.cmake script is confusing the version 2.1 with the version 1.9.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5505
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1372

Re: CMake find package error

Post by dark_sylinc »

Hi!

I don't know if that FindOGRE.cmake supports Ogre 2.1+, but most likely it won't

We provide OGRE.cmake which by default will look into %your_repo%/Dependencies/Ogre and the compiled versions in %your_repo%/Dependencies/Ogre/build/Debug (and ./Release etc for each CMAKE_BUILD_TYPE) for the built code.

However you can control these locations via OGRE_SOURCE & OGRE_BINARIES

You CMake script needs to call:

Code: Select all

setupOgre( OGRE_SOURCE, OGRE_BINARIES, OGRE_LIBRARIES, FALSE )
# ...
target_link_libraries( ${PROJECT_NAME} ${OGRE_LIBRARIES} )
By default OGRE.cmake will call setupOgreSamplesCommon which copies code from Ogre for you to use with useful initialization tools, it is recommended for convenience however this is not required and you can comment out that line.

Since you seem like a veteran Ogre 1.x user, we've written Tutorial00_Basic.cpp
which shows how to initialize Ogre 2.x from scratch with nothing fancy.

OGRE.cmake will also generate Plugins.cfg and Resources.cfg files out of its for you templates but this is not strictly required.

Please note that OGRE.cmake will copy data folders (e.g. Hlms scripts) which are required and placed them under %your_repo%/bin/Data

Cheers
NoeMurr
Gnoblar
Posts: 11
Joined: Sat May 18, 2019 1:02 pm

Re: CMake find package error

Post by NoeMurr »

Hi,

I see that solution and it's working.

The only problem with that is that I'm forced to have the sources of Ogre and not only the installation.
But all right if it's the only way.

Thanks for your answer!
NoeMurr
Gnoblar
Posts: 11
Joined: Sat May 18, 2019 1:02 pm

Re: CMake find package error

Post by NoeMurr »

Hi,

I use again this thread because I found out some problems, with the Tutorial_00Basic that you advised me.

You're using the feature provided by the Ogre::Window class. The problem is that in the branch v2-1 this class does not exists.

I suppose that this is a feature that is been added recently, so do you advise me to use the master version of the library? if yes: is it enough stable to be used?
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5505
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1372

Re: CMake find package error

Post by dark_sylinc »

Hi!
NoeMurr wrote: Tue Mar 31, 2020 1:03 pm You're using the feature provided by the Ogre::Window class. The problem is that in the branch v2-1 this class does not exists.
In Ogre 2.2, "Window" replaced "RenderWindow" thus it could be ported to 2.1 with relative easy.

However to answer your other question:
NoeMurr wrote: Tue Mar 31, 2020 1:03 pmI suppose that this is a feature that is been added recently, so do you advise me to use the master version of the library? if yes: is it enough stable to be used?
Yes!
It is stable enough to be used. Very few features haven't been ported yet (e.g. saving textures to DDS files and a few other formats)