I found a great answer on how to get find the executable files in Qt with CMake, cmake not finding Qt4
How do you use CMAKE_INCLUDE_PATH? I tried it out, but I got an error:
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../cmake_modules)
project(vrvu)
find_package(OpenGL REQUIRED)(CMAKE_INCLUDE_PATH <--- this is where I'm getting an error
C:\QtSDK\Desktop\Qt\4.8.0\msvc2010\bin)find_package(Qt4 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
include(${QT_USE_FILE})
find_package(Coin3 REQUIRED)
find_package(Quarter REQUIRED)
add_subdirectory(bullet-2.77)
add_subdirectory(starlight)
file(GLOB SOURCES "*.cpp" "*.cxx" "*.h" "*.hpp")
include_directories(${OPENGL_INCLUDE_DIR} ${QT_INCLUDE_DIR} ${COIN_INCLUDE_DIR} ${QUARTER_INCLUDE_DIR} "./bullet-2.77/src" "./starlight")
link_directories(${QT_LIB_DIR} ${COIN_LINK_DIRECTORIES} ${QUARTER_LINK_DIRECTORIES})
add_definitions(${QT_DEFINITIONS} ${COIN_DEFINITIONS} ${QUARTER_DEFINITIONS})
add_executable(vrvu ${SOURCES})
target_link_libraries(vrvu ${OPENGL_LIBRARIES} ${QT_LIBRARIES} ${COIN_LIBRARIES} ${QUARTER_LIBRARIES} LinearMath BulletCollision starlight)
Sorry for the long code….thanks!
There are a couple of issues here.
I’m not sure if it’s just a typo but you can’t just append the instruction to set
CMAKE_INCLUDE_PATHto the end of thefind_packagecommand, you need a separatesetcommand:Note that the path specified needs the separators to be escaped if you’re using backslashes. Alternatively, you can use a single forward slash in place of the double backslash, even on Windows. Putting the path in quotes has no effect in this case, but it’s a good habit to get into in case the path contains spaces.
Setting
CMAKE_INCLUDE_PATHextends the list of paths CMake tries when doingfind_pathandfind_filecalls only. This will be useful to thefind_packagecall, but even more so in this case might be to setCMAKE_PREFIX_PATHwhich extends the seach paths for allfind_XXXcommands. It does mean you’d need to strip “\bin” from the path, since it’s appended to theCMAKE_PREFIX_PATHwhen searching for executables:Next,
file(GLOB SOURCES "*.cpp" "*.cxx" "*.h" "*.hpp"). While this isn’t actually an error, generally it’s frowned upon to use this technique to create a list of source files since if a file is added or deleted to the source tree, CMake will have no “knowledge” and won’t re-run. The recommended method is to add each source file by hand to the CMakeLists.txt, so that an addition or deletion will automatically cause CMake to re-run.Also, “
SOURCES” is a poor choice of variable name since it also represents a property of CMake targets.Another frowned-upon practice is the use of
link_directories. The documentation indicates why it’s not usually needed, which should be the case here.The
add_definitionsline too may be unnecessary. Qt does define definitions, but they have already been added when you didinclude(${QT_USE_FILE})(see the documentation for FindQt4), so you’re adding them twice here. I’m not familiar with Coin3 or Quarter, but they may not actually generate any required preprocessor definitions. You could check their contents by adding:temporarily (after the corresponding
find_packagecalls). If these are empty, you can delete theadd_definitionscall.Assuming the variables
${COIN_LIBRARIES}and${QUARTER_LIBRARIES}specify the full paths to these libs, then I think you should be good to go.