Fixed: don't look for Ogre library binaries for linking when we are using Ogre sources - instead, use the target names.

#164 Merged at 08342eb
Repository
ogre_papercut
Branch
v1-9
Repository
ogre
Branch
v1-9
Author
  1. A. Joël Lamotte
Reviewers
Description

This change fixes an issue in FindOgre that I found using Ogre and OgreProcedural from sources. The basic setup is that I have a directory set this way:

dependencies/CMakeLists.txt
dependencies/ogre/...                       (Ogre sources)
dependencies/ogre_procedural/....   (OgreProcedural sources)

Then in the CMakeLists.txt file, I have something similar to the following (very simplified):

# Ogre

# blah blah
# ...set configuration for Ogre

add_subdirectory( ogre )  # This will create the targets defined from Ogre cmake files

# set some variable so that other dependencies using Ogre can find it (injecting info for FindOgre)

# OgreProcedural

# blah blah OgreProcedural configuration

add_subdirectory( ogre_procedural )

# set some variable so that other dependencies using OgreProcedural can find it

This works well, but FindOgre will look for .lib files whatever the setup, even if you only have source files. At first, it's ok because if there is no .lib file, the script will just make sure there is at least the rest of the library that is found.

However, if FindOgre does find .lib files, it wil try to link with it even if it's not for the right configuration. To clarify, here is how to reproduce the problem:

  1. have the setup described before;
  2. set the CMakeLists.txt so that OGRE_LIBRARIES always contain only "OgreMain" which is the OgreMain target name - it have to be defined BEFORE all add_subdirectory() calls to projects depent on OgreMain;
  3. make sure OGRE_REL_LIBRARY and OGRE_DBG_LIBRARY are empty BEFORE all add_subdirectory() calls to projects depent on OgreMain;
  4. run cmake: OgreProcedural will correctly "Find: OgreMain"
  5. open the project file, compile OgreMain in ReleaseDebug;
  6. run cmake: OgreProcedural will INCORRECTLY "Find: ../../blah/blah/ogre/lib/relwithdebinfo/OgreMain.lib"
  7. at this point, if I try to compile OgreProcedural in Release or Debug, it will ALWAYS link with ogre/lib/relwithdebinfo/OgreMain.lib instead of the right lib file depending on the mode;

So basically, the problem is simply that FindOgre look for library files instead of just adding OgreMain (and other libraries) as a link dependency. If we remove the library files search in the case of Ogre being provided by sources to FindOgre, then the generated projects will always link with the OgreMain target instead of a specific .lib file set on Cmake setup.

I'm not sure if I'm totally clear here so feel free to ask questions. The change should affect only usage from sources by forcing setting OGRE_LIBRARIES (to clarify which Ogre targets to use in Ogre-dependent projects like OgreProcedural) and skip (with a visible message) the .lib file search if OGRE_SOURCE is set.

I can't check right now if it have no effect on classic setup where binaries of Ogre are installed, but Ogre's team should be able to easily check that.

Comments (0)