[Solved] Little help with CMake...

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

[Solved] Little help with CMake...

Post by Zeal »

Been using CMake (3.4.3 gui) more and more lately, with mixed results (sometimes it's idiot proof, sometimes it feels beyond unintuitive).

The latest project I have been having trouble with...

http://www.ogre3d.org/forums/viewtopic. ... 48#p524748

I think it's an issue with how I am pointing to the dependencies. So after doing some research, I started to wonder - how exactly are you supposed to tell a cmake file where to locate other libraries? How is the "find_package" command supposed to magically find where the headers and libs are located?

Thanks for any help
Last edited by Zeal on Thu Apr 07, 2016 7:59 pm, edited 1 time in total.
User avatar
moejac
Halfling
Posts: 45
Joined: Tue Dec 08, 2009 9:18 am

Re: Little help with CMake...

Post by moejac »

I suspect that the find_ffmpeg script is looking for the FFMPEG_DIR environment variable. Try and set that.

Code: Select all

setx FFMPEG_DIR wherever
On *nix this is much easier because of the LFS.

Whenever I need to figure out what a particular find_something script expects, I simply Google it and a whole host of codebases should hopefully appear in the search results.
Sometimes, they wrote a custom find script, othertimes it is shipped with CMake.

You can also look in that directory - packages - create a shortcut to it once you find it.
User avatar
moejac
Halfling
Posts: 45
Joined: Tue Dec 08, 2009 9:18 am

Re: Little help with CMake...

Post by moejac »

This is a snippet from FindFFMPEG:

Code: Select all

find_path(FFMPEG_INCLUDE_DIR1 avformat.h
  $ENV{FFMPEG_DIR}
  $ENV{FFMPEG_DIR}/ffmpeg
  $ENV{FFMPEG_DIR}/libavformat
  $ENV{FFMPEG_DIR}/include/libavformat
  $ENV{FFMPEG_DIR}/include/ffmpeg
  /usr/local/include/ffmpeg
  /usr/include/ffmpeg
  /usr/include/libavformat
  /usr/include/ffmpeg/libavformat
  /usr/include/${CMAKE_LIBRARY_ARCHITECTURE}/libavformat
  /usr/local/include/libavformat
)
Taken from https://github.com/robotology/ycm/blob/ ... MPEG.cmake
It simply uses the paths listed as a suggestion list to be used when figuring out where things are.
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Re: Little help with CMake...

Post by Zeal »

Hmm still a tad confused, here is the CMakeLists.txt I am working with...

Code: Select all

    cmake_minimum_required(VERSION 2.8)

option(BUILD_VIDEOPLAYER_DEMO "Build the videoplayer demo" ON)



set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/)



# Sources

set(OGRE_FFMPEG_VIDEOPLAYER_SOURCE_FILES
    src/videoplayer.cpp
    src/videostate.cpp
    src/videodefs.hpp
    src/libavwrapper.cpp
    src/audiodecoder.cpp
    src/audiofactory.hpp
)

# Find FFMPEG
# *** Added these two lines 
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/include")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib")
# ***
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL SWSCALE SWRESAMPLE AVRESAMPLE)
unset(FFMPEG_LIBRARIES CACHE)
find_package(FFmpeg)
if ( NOT AVCODEC_FOUND OR NOT AVFORMAT_FOUND OR NOT AVUTIL_FOUND OR NOT SWSCALE_FOUND )
    message(FATAL_ERROR "FFmpeg component required, but not found!")
endif()
set(VIDEO_FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${SWSCALE_LIBRARIES})
if( SWRESAMPLE_FOUND )
    add_definitions(-DHAVE_LIBSWRESAMPLE)
    set(VIDEO_FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${SWRESAMPLE_LIBRARIES})
else()
    if( AVRESAMPLE_FOUND )
        set(VIDEO_FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${AVRESAMPLE_LIBRARIES})
    else()
        message(FATAL_ERROR "Install either libswresample (FFmpeg) or libavresample (Libav).")
    endif()
endif()
include_directories(${FFMPEG_INCLUDE_DIRS})

# Find Boost
# Didnt have to add anything here, I think I set the environment variable when I built boost long ago
set(BOOST_COMPONENTS thread)
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
include_directories(${Boost_INCLUDE_DIRS})

# Find Ogre
# *** Added these two lines 
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/SDKs/Ogre/build/include")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/SDKs/Ogre/build/lib")
# ***
find_package(OGRE REQUIRED)
include_directories(${OGRE_INCLUDE_DIRS})

include_directories(src/)

add_library(${OGRE_FFMPEG_VIDEOPLAYER_LIBRARY} STATIC ${OGRE_FFMPEG_VIDEOPLAYER_SOURCE_FILES})
target_link_libraries(${OGRE_FFMPEG_VIDEOPLAYER_LIBRARY} ${VIDEO_FFMPEG_LIBRARIES} ${Boost_LIBRARIES} ${OGRE_LIBRARIES})

if(BUILD_VIDEOPLAYER_DEMO)
    add_subdirectory(demo)
endif()
As you can see I only added the "SET(CMAKE_INCLUDE_PATH..." parts for each dependency. However, when I generate, this is what I get...

Code: Select all

Found FFmpeg: C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib/avcodec.lib;C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib/avformat.lib;C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib/avutil.lib;C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib/swscale.lib  
Boost version: 1.60.0
Found the following Boost libraries:
  thread
Looking for OGRE...
OGRE_PREFIX_WATCH changed.
Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
Found Ogre Ghadamon (1.9.0)
Found OGRE: C:/SDKs/Ogre/build/lib/Debug/OgreMain_d.lib
Looking for OGRE_Paging...
Could not locate OGRE_Paging
Looking for OGRE_Terrain...
Could not locate OGRE_Terrain
Looking for OGRE_Property...
Could not locate OGRE_Property
Looking for OGRE_RTShaderSystem...
Could not locate OGRE_RTShaderSystem
Looking for OGRE_Volume...
Could not locate OGRE_Volume
Looking for OGRE_Overlay...
Could not locate OGRE_Overlay
CMake Error at CMakeLists.txt:57 (target_link_libraries):
  Cannot specify link libraries for target
  "C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib/avcodec.lib" which is
  not built by this project.


Configuring incomplete, errors occurred!
See also "C:/SDKs/ogre-ffmpeg-videoplayer-master/build/CMakeFiles/CMakeOutput.log".
So it claims it could find ffmpeg, just "Cannot specify link libraries for target".

I googled that error, and lots of stuff came up, but the solution was to do "add_library(" before "target_link_libraries(", which we appear to be doing already, so there must be something else wrong?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Little help with CMake...

Post by c6burns »

When something like this happens in CMake, take the problem line and build a message around it so you can see exactly what you are passing for parameters. Your problem line is:

Code: Select all

target_link_libraries(${OGRE_FFMPEG_VIDEOPLAYER_LIBRARY} ${VIDEO_FFMPEG_LIBRARIES} ${Boost_LIBRARIES} ${OGRE_LIBRARIES})
I bet if you build a debug output line before that statement like this:

Code: Select all

message("target_link_libraries:::::: ${OGRE_FFMPEG_VIDEOPLAYER_LIBRARY} ${VIDEO_FFMPEG_LIBRARIES} ${Boost_LIBRARIES} ${OGRE_LIBRARIES}")
You will see that ${OGRE_FFMPEG_VIDEOPLAYER_LIBRARY} is blank. That is my hunch. If I am correct, add this near the top:

Code: Select all

set(OGRE_FFMPEG_VIDEOPLAYER_LIBRARY "ogreffmpeg")
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Re: Little help with CMake...

Post by Zeal »

Ok thanks that is a handy tool. I added the "message("target_link_libraries:::::: ${OGRE_FFMPEG_VIDEOPLAYER_LIBRARY} ${VIDEO_FFMPEG_LIBRARIES} ${Boost_LIBRARIES} ${OGRE_LIBRARIES}")" line right before the "target_link_libraries(..."

Here is the output -
target_link_libraries:::::: ogreffmpeg C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib/avcodec.lib;C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib/avformat.lib;C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib/avutil.lib;C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib/swscale.lib;C:/SDKs/ffmpeg-20160318-git-a7b8a6e-win64-dev/lib/swresample.lib optimized;C:/SDKs/boost_1_60_0/stage/lib/boost_thread-vc140-mt-1_60.lib;debug;C:/SDKs/boost_1_60_0/stage/lib/boost_thread-vc140-mt-gd-1_60.lib;optimized;C:/SDKs/boost_1_60_0/stage/lib/boost_date_time-vc140-mt-1_60.lib;debug;C:/SDKs/boost_1_60_0/stage/lib/boost_date_time-vc140-mt-gd-1_60.lib;optimized;C:/SDKs/boost_1_60_0/stage/lib/boost_system-vc140-mt-1_60.lib;debug;C:/SDKs/boost_1_60_0/stage/lib/boost_system-vc140-mt-gd-1_60.lib;optimized;C:/SDKs/boost_1_60_0/stage/lib/boost_atomic-vc140-mt-1_60.lib;debug;C:/SDKs/boost_1_60_0/stage/lib/boost_atomic-vc140-mt-gd-1_60.lib;optimized;C:/SDKs/boost_1_60_0/stage/lib/boost_chrono-vc140-mt-1_60.lib;debug;C:/SDKs/boost_1_60_0/stage/lib/boost_chrono-vc140-mt-gd-1_60.lib C:/SDKs/Ogre/build/lib/Debug/OgreMain_d.lib;optimized;C:/SDKs/boost_1_60_0/stage/lib/boost_thread-vc140-mt-1_60.lib;debug;C:/SDKs/boost_1_60_0/stage/lib/boost_thread-vc140-mt-gd-1_60.lib;optimized;C:/SDKs/boost_1_60_0/stage/lib/boost_date_time-vc140-mt-1_60.lib;debug;C:/SDKs/boost_1_60_0/stage/lib/boost_date_time-vc140-mt-gd-1_60.lib;optimized;C:/SDKs/boost_1_60_0/stage/lib/boost_system-vc140-mt-1_60.lib;debug;C:/SDKs/boost_1_60_0/stage/lib/boost_system-vc140-mt-gd-1_60.lib;optimized;C:/SDKs/boost_1_60_0/stage/lib/boost_atomic-vc140-mt-1_60.lib;debug;C:/SDKs/boost_1_60_0/stage/lib/boost_atomic-vc140-mt-gd-1_60.lib;optimized;C:/SDKs/boost_1_60_0/stage/lib/boost_chrono-vc140-mt-1_60.lib;debug;C:/SDKs/boost_1_60_0/stage/lib/boost_chrono-vc140-mt-gd-1_60.lib
So looks like you are correct, OGRE_FFMPEG_VIDEOPLAYER_LIBRARY wasn't being set. Added "set(OGRE_FFMPEG_VIDEOPLAYER_LIBRARY "ogreffmpeg")" to the top, but now I am getting the following...
Looking for pthread.h
Looking for pthread.h - not found
Found Threads: TRUE
CMake Error at C:/Users/jeff/Downloads/cmake-3.4.3-win32-x86/cmake-3.4.3-win32-x86/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find SDL2 (missing: SDL2_LIBRARY SDL2_INCLUDE_DIR)
Call Stack (most recent call first):
C:/Users/jeff/Downloads/cmake-3.4.3-win32-x86/cmake-3.4.3-win32-x86/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
cmake/FindSDL2.cmake:187 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
demo/CMakeLists.txt:12 (find_package)


Configuring incomplete, errors occurred!
So the ogreffmpeg library (http://www.ogre3d.org/forums/viewtopic.php?f=5&t=81934) requires sdl2? I have the source files in my ogre dependencies, but no prebuilt libraries. I thought there was a way to build this without audio support...

*ah thats only if you are building the 'demo' so I removed that. Project generated! Building now...

*Bleh, so close yet so far away. Got 14 errors while trying to build the sln...
Severity Code Description Project File Line
Error C3861 'avcodec_default_get_buffer': identifier not found ogreffmpeg C:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 366
Error C3861 'avcodec_default_release_buffer': identifier not found ogreffmpeg C:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 375
Error C2039 'destruct': is not a member of 'AVPacket' ogreffmpeg C:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 98
Error C2039 'get_buffer': is not a member of 'AVCodecContext' ogreffmpeg C:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 596
Error C2065 'PIX_FMT_RGBA': undeclared identifier ogreffmpeg C:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 317
Error C2065 'PIX_FMT_RGBA': undeclared identifier ogreffmpeg C:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 388
Error C2039 'release_buffer': is not a member of 'AVCodecContext' ogreffmpeg C:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 597
Error (active) class "AVCodecContext" has no member "get_buffer" ogreffmpeg c:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 596
Error (active) class "AVCodecContext" has no member "release_buffer" ogreffmpeg c:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 597
Error (active) class "AVPacket" has no member "destruct" ogreffmpeg c:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 98
Error (active) identifier "avcodec_default_get_buffer" is undefined ogreffmpeg c:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 366
Error (active) identifier "avcodec_default_release_buffer" is undefined ogreffmpeg c:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 375
Error (active) identifier "PIX_FMT_RGBA" is undefined ogreffmpeg c:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 317
Error (active) identifier "PIX_FMT_RGBA" is undefined ogreffmpeg c:\SDKs\ogre-ffmpeg-videoplayer-master\src\videostate.cpp 388
I'm guessing this is no longer a CMake problem? Seems like something is wrong with this ogreffmpeg project? It's from 2014, and I am using the latest prebuilt dev package of ffmpeg (https://ffmpeg.zeranoe.com/builds/), maybe I need to use an older ffmpeg library?

Any ideas?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Little help with CMake...

Post by c6burns »

Looks like you have it, just I am guessing there are incompatibilities between the version of ffmpeg you have, and the version that was used in scrawl's project. ffmpeg has a lot of version churn like that. If you used the newest zeranoe build then chances are you need an older version.
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Re: Little help with CMake...

Post by Zeal »

Anyone know where I can get old builds of ffmpeg? Looked all over https://ffmpeg.zeranoe.com/builds/ but couldnt find anyplace.

I guess my other two options are to build from source (I assume I can get a 2014 source), or try and update scrawls project...
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Little help with CMake...

Post by c6burns »

User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Re: Little help with CMake...

Post by Zeal »

Excellent! Got one from a month before Scrawls post, and no more build errors!

Marking as solved, thanks fellas!