You are not logged in.

#1 2009-08-21 01:58:34

japtar10101
Member
Registered: 2009-08-08
Posts: 57

[SOLVED] Adding CMake include packages

I'm trying to start a game project using CMake.  To compile with the external libraries Ogre 3D and OIS, I added these 2 lines in CMakeLists.txt:

find_package( OGRE REQUIRED )
find_package( OIS  REQUIRED )

Running cmake, however, returns this error:

$ cmake ~/git/bandura/
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:31 (find_package):
  Could not find module FindOGRE.cmake or a configuration file for package
  OGRE.

  Adjust CMAKE_MODULE_PATH to find FindOGRE.cmake or set OGRE_DIR to the
  directory containing a CMake configuration file for OGRE.  The file will
  have one of the following names:

    OGREConfig.cmake
    ogre-config.cmake



CMake Error at CMakeLists.txt:32 (find_package):
  Could not find module FindOIS.cmake or a configuration file for package
  OIS.

  Adjust CMAKE_MODULE_PATH to find FindOIS.cmake or set OIS_DIR to the
  directory containing a CMake configuration file for OIS.  The file will
  have one of the following names:

    OISConfig.cmake
    ois-config.cmake



-- Configuring incomplete, errors occurred!

The error makes sense: it didn't find OIS or OGRE packages.  However, I can confirm I've installed both of them by checking yaourt:

$ y -Q ogre
==> List all installed packages
local/ogre 1.6.3-1

$ y -Q ois
==> List all installed packages
local/ois 1.2.0-1

So what's wrong?  Do I have to configure Cmake to recognize where OIS and OGRE are located?  Also, is there a place to get quick answers on using CMakeLists.txt?  I'm having a difficult time finding answers via google, and Kitware's Wiki isn't as useful as I hoped.

The full CMakeLists.txt file:

# Referencing from example:
# http://www.cmake.org/cmake/help/examples.html

cmake_minimum_required (VERSION 2.6)
project (bandura)

# Setup flags:

# Set to true if you want to
# compile the testing directory
set( COMPILE_TESTING true )

# Set to true if you want to
# compile the documentation directory
set( COMPILE_DOCUMENTATION true )

# Set to true if you want
# debugging statements
set( COMPILE_DEBUG true )

# Setup versioning

set( VERSION_MAJOR     0 )
set( VERSION_MINOR     1 )
set( VERSION_REVISION  1 )
set( PROJECT_VERSION
    "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_VERSION}"
)

# Find requirements for this projects
find_package( OGRE REQUIRED )
find_package( OIS  REQUIRED )
include_directories( ${OGRE_INCLUDE_DIR} ${OIS_INCLUDE_DIR} )

# Setup Directory output locations

set( DOCUMENTATION_OUTPUT_PATH ${PROJECT_BINARY_DIR}/doc )
set( EXECUTABLE_OUTPUT_PATH    ${PROJECT_BINARY_DIR}/bin )
if( WIN32 )
    set( LIBRARY_OUTPUT_PATH   ${PROJECT_BINARY_DIR}/bin )
else( WIN32 )
    set( LIBRARY_OUTPUT_PATH   ${PROJECT_BINARY_DIR}/lib )
endif ( WIN32 )
link_directories( ${LIBRARY_OUTPUT_PATH} )

# Adding subdirectories

add_subdirectory (src)
if( COMPILE_TESTING )
    add_subdirectory (testing)
endif( COMPILE_TESTING )
if( COMPILE_DOCUMENTATION )
    add_subdirectory (doc)
endif( COMPILE_DOCUMENTATION )

add_subdirectory (art)
add_subdirectory (music)

add_subdirectory (lib)
add_subdirectory (bin)

Last edited by japtar10101 (2009-08-25 23:08:10)

Offline

#2 2009-08-21 08:14:12

WhiteMagic
Member
Registered: 2007-03-01
Posts: 85

Re: [SOLVED] Adding CMake include packages

The FIND_PACKAGE( ... ) directives of cmake need to be written, in order to find and set required libraries. These FindPackageName.cmake files do not exist for every possible software package out there, the ones shipped with cmake are documented in their manual http://www.cmake.org/cmake/help/cmake2.6docs.html under the "Standard CMake modules" section.

In order to use other FIND_PACKAGE for other non standard software these have to be written and placed in a location where cmake will find it, which can be set using:

SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/../CMakeModules )

in the CMakeLists.txt file. This tells cmake to look in the paths you provided for cmake files.
As for the actual FindOGRE.cmake and FindOIS.cmake files required, I can give you two files I used when worked with Ogre, the files are a little barebones and not very smart, i.e. you have to tell them the include and link path via cmake and they will only include the library I needed back then but it's a starting point.

Save this as FindOGRE.cmake in ${CMAKE_SOURCE_DIR}/../CMakeModules or to whatever you set the CMAKE_MODULE_PATH

# Find OGRE library
#
# OGRE_INCLUDE_DIR      where to find the include files
# OGRE_LIBRARY_DIR      where to find the libraries
# OGRE_LIBRARIES        list of libraries to link
# OGRE_FOUND            true if OGRE was found

SET( OGRE_LIBRARYDIR / CACHE PATH "Alternative library directory" )
SET( OGRE_INCLUDEDIR / CACHE PATH "Alternative include directory" )
MARK_AS_ADVANCED( OGRE_LIBRARYDIR OGRE_INCLUDEDIR )

FIND_LIBRARY( OGRE_LIBRARY_DIR OgreMain PATHS ${OGRE_LIBRARYDIR} )
FIND_PATH( OGRE_INCLUDE_DIR OGRE/Ogre.h PATHS ${OGRE_INCLUDEDIR} )

GET_FILENAME_COMPONENT( OGRE_LIBRARY_DIR ${OGRE_LIBRARY_DIR} PATH )

IF( OGRE_INCLUDE_DIR AND OGRE_LIBRARY_DIR )
    SET( OGRE_LIBRARIES OgreMain )
    SET( OGRE_FOUND TRUE )
ELSE( OGRE_INCLUDE_DIR AND OGRE_LIBRARY_DIR )
    SET( OGRE_FOUND FALSE )
ENDIF( OGRE_INCLUDE_DIR AND OGRE_LIBRARY_DIR )

Save this file as FindOIS.cmake

# Find OIS library
#
# OIS_INCLUDE_DIR      where to find the include files
# OIS_LIBRARY_DIR      where to find the libraries
# OIS_LIBRARIES        list of libraries to link
# OIS_FOUND            true if OIS was found

SET( OIS_LIBRARYDIR / CACHE PATH "Alternative library directory" )
SET( OIS_INCLUDEDIR / CACHE PATH "Alternative include directory" )
MARK_AS_ADVANCED( OIS_LIBRARYDIR OIS_INCLUDEDIR )

FIND_LIBRARY( OIS_LIBRARY_DIR OIS PATHS ${OIS_LIBRARYDIR} )
FIND_PATH( OIS_INCLUDE_DIR OIS/OIS.h PATHS ${OIS_INCLUDEDIR} )

GET_FILENAME_COMPONENT( OIS_LIBRARY_DIR ${OIS_LIBRARY_DIR} PATH )

IF( OIS_INCLUDE_DIR AND OIS_LIBRARY_DIR )
    SET( OIS_LIBRARIES OIS )
    SET( OIS_FOUND TRUE )
ELSE( OIS_INCLUDE_DIR AND OIS_LIBRARY_DIR )
    SET( OIS_FOUND FALSE )
ENDIF( OIS_INCLUDE_DIR AND OIS_LIBRARY_DIR )

Edit:
I rewrote the FIND_* files as the old ones really weren't that good. They should find the include and link directories on their own, if ogre and ois are installed in the system path (/usr/include and /usr/lib).
If they are in a non standard location you can use the [OIS|OGRE]_LIBRARYDIR and [OIS|OGRE]_INCLUDEDIR to set the base paths for the search, e.g. if ogre is in /home/user/include/OGRE/* then /home/user/include would be the value for OGRE_INCLUDEDIR. These can be set via cmake -DOGRE_INCLUDEDIR=... or using any gui in the advanced mod.

There also might be some things about using cmake with Ogre on the official ogre site as they seem to be using cmake for their next release.

Last edited by WhiteMagic (2009-08-21 08:58:29)

Offline

#3 2009-08-24 23:54:29

japtar10101
Member
Registered: 2009-08-08
Posts: 57

Re: [SOLVED] Adding CMake include packages

Thanks a lot, that worked.

I still have, like, a million questions left based on cmake though. 

I have a quick "testing" directory that I want to compile seperate from the project itself.  Fore example, I would have a directory structure like this:

#src and bin are project directories
src/
bin/
testing/
    test1_src/
    test1_bin/
    test2_src/
    test2_bin/

What would be the easiest way to compile test1_src/ files in test1_bin/, test2_src/ files in test2_bin/, and so forth?

-------

Turns out I figured out my other question, but I'll post it anyway in case anyone else had a similar problem:

I'm copying a number of directories and their contents into another place in the bin directory.  For example, my project's art directory looks like this:

art/
    proj/
        model/
            model.blend
        terrain/
            terrain.blend
    export/
        model/
            model.mesh
        terrain/
            terrain.mesh

Where proj directory contains maya/blender files, while export directory retains the Ogre-compatible mesh files.  In the bin directory, however, I only want to copy the contents of the export directory so that the final conclusion would look like this:

art/
    model/
        model.mesh
    terrain/
        terrain.mesh

To achieve this, I did:

file( GLOB LIST_EXPORT ${CMAKE_SOURCE_DIR}/art/export/* )
foreach( EXPORT ${LIST_EXPORT} )
    string( REGEX REPLACE "${CMAKE_SOURCE_DIR}/art/export/(.+)"
        "${CMAKE_BINARY_DIR}/art/\\1" NEW_DIR "${EXPORT}" )
    string( REGEX REPLACE "${CMAKE_SOURCE_DIR}/art/export/(.+)"
        "\\1" TARGET "${EXPORT}" )
    add_custom_target( ${TARGET}
        ALL
            echo "Copying ${TARGET} from artworks"
        COMMAND
            ${CMAKE_COMMAND} -E copy_directory ${EXPORT} ${NEW_DIR}
        COMMENT
            "Copying ${TARGET} from artworks"
    )
endforeach( EXPORT )

Simply run cmake on the project directory, then run make.

Last edited by japtar10101 (2009-08-25 00:51:08)

Offline

#4 2009-08-25 15:47:41

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: [SOLVED] Adding CMake include packages

If I'm not mistaken, that answers the questions.  Mind adding [SOLVED] to the thread topic?

Offline

#5 2009-08-25 23:08:59

japtar10101
Member
Registered: 2009-08-08
Posts: 57

Re: [SOLVED] Adding CMake include packages

scio wrote:

If I'm not mistaken, that answers the questions.  Mind adding [SOLVED] to the thread topic?

I still have more questions. tongue
But to be fair, the original post was answered, so I'll mark it solved.

Offline

Board footer

Powered by FluxBB