Very new to make files here, so please forgive me if this is a noob question. I can't seem to find the answer on the internet.
I've forked a public repository from github, and it repository itself is supposed to be download, make and run, but I've already fixed a half dozen errors in their make files trying to get it running. Now I'm down to this one, which seems to be something to do with CMake not finding the right QT4 command.
When I'm in a build folder, the instructions (according to the owner of the repository) says to type "cmake .." - which is an obvious reference to CMakeList.txt in the parent folder. The file is hosted on Github, the line that throws the error is line 94, it says:
QT4_ADD_RESOURCES(OFFNAO_RES_SRCS ${OFFNAO_RES})
I am trying to build this program on Ubuntu 14.04.5 (because that's the OS it was originally built on, I can work on upgrading that after it is working).
The error text it spits out is:
CMake Error at CMakeLists.txt:94(QT$_ADD_RESOURCES):
Unknown CMake command "QT4_ADD_RESOURCES".
-- Configuring incomplete, errors occurred!
I have installed qt4-dev-tools (which also installs all qt4 libraries).
I can't seem to find how to get CMake to recognise QT4 and its commands.
I'm new to CMake and this is the first time I've come across QT4 so I don't know what I'm looking for. Happy to provide any more info if needed. All help is appreciated.
EDIT:
Here's the contents of the offnao CMakeList.txt:
cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
PROJECT(OFFNAO)
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}")
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${CTC_DIR}/libnaoqi/include)
INCLUDE_DIRECTORIES(${CTC_DIR}/zlib/include)
INCLUDE_DIRECTORIES(${CTC_DIR}/../sysroot_legacy/usr/include)
SET(OFFNAO_CXX_SRCS
utils/OverlayPainter.cpp
// contents skipped for brevity
tabs/teamBallTab.cpp
)
SET(OFFNAO_MOC
readers/reader.hpp
// contents skipped for brevity
tabs/teamBallTab.hpp
)
if(CMAKE_TOOLCHAIN_FILE)
list(APPEND OFFNAO_CXX_SRCS tabs/cameraTab.cpp)
list(APPEND OFFNAO_MOC tabs/cameraTab.hpp)
endif(CMAKE_TOOLCHAIN_FILE)
SET(OFFNAO_UI
visualiser.ui
ConnectionBar.ui
tabs/LogTab.ui
tabs/LogsTab.ui
)
SET(OFFNAO_RES
resources/visualiser_resources.qrc
)
# build cxx files for resources
QT4_ADD_RESOURCES(OFFNAO_RES_SRCS ${OFFNAO_RES})
# build ui_XXX files from the XML-style .ui files
QT4_WRAP_UI(OFFNAO_UI_SRCS ${OFFNAO_UI})
# this moc's the above variable and appends to the cxx sources
QT4_WRAP_CPP(OFFNAO_MOC_SRCS ${OFFNAO_MOC})
ADD_EXECUTABLE(offnao.bin ${OFFNAO_CXX_SRCS} ${OFFNAO_RES_SRCS} ${OFFNAO_MOC_SRCS} ${OFFNAO_UI_SRCS})
cotire(offnao.bin)
set_source_files_properties(
tabs/graphTab.cpp
tabs/plots.cpp
tabs/walkTab.cpp
tabs/zmpTab.cpp
main.cpp
visualiser.cpp
${OFFNAO_MOC_SRCS} #too lazy to split and list them
PROPERTIES COMPILE_FLAGS "-I${QWT_INCLUDE_DIR}")
find_library ( QGLVIEWER_LIBRARY NAMES QGLViewer qglviewer-qt4 )
find_package ( OpenGL REQUIRED )
find_package ( PNG REQUIRED )
TARGET_LINK_LIBRARIES(
offnao.bin
${QT_LIBRARIES}
${QWT_LIBRARY}
${QGLVIEWER_LIBRARY}
Furthermore, the README that states to build this is rather vague, it doesn't actually say what folder to run these commands from. It states:
Welcome to Off-Nao, the rUNSWift debugging toolsuite.
To build this project, either:
You get lucky and bin/build_setup.sh just works :D
(verified under Ubuntu 14.04.1 LTS both natively and in VMs;
but builds successfully then segfaults at runtime in libGL.so.1
under fresh download of 14.04.3 LTS # 15/9/2015
according to gdb - so much for Ubuntu being stable).
---OR---
You need Qt4 and probably a bunch of other things like QGLViewer to build it natively:
$ mkdir build
$ cd build
$ cmake ..
$ make
$ ./offnao
Once you have performed the steps above once, in future you only need to:
$ make
$ ./offnao
In the 'build' directory
I do get the segfault as mentioned in the README at LibGL.so.1 so I've attempted to follow the instruction below it. I can only get the the "cmake .." stage and that's where I get the error.
Reformulating my previous comment as answer:
To use macros QT4_ADD_RESOURCES, QT4_WRAP_UI, QT4_WRAP_CPP and others you need to call find_package(Qt4 REQUIRED) first in your CMakeLists.txt. See the documentation for the FindQt4.cmake module (https://cmake.org/cmake/help/v3.0/module/FindQt4.html).
Related
I am wondering how is cmake finding my llvm cmake configuration if I haven't given it any variable telling it where to find it.
I am an LLVM newcomer. I am building a Hello World LLVM pass. I am on Ubuntu 16.04. My version of LLVM is 8.0.0. My version of CMake is 3.5.1.
This is my /CMakeLists.txt file:
cmake_minimum_required(VERSION 3.1)
project(FunctionDebugger)
find_package(LLVM REQUIRED CONFIG)
include_directories(${LLVM_INCLUDE_DIRS})
add_subdirectory(FunctionDebugger)
set(CMAKE_VERBOSE_MAKEFILE on)
This is the FunctionDebugger/CMakeLists.txt file:
add_library(LLVMFunctionDebugger MODULE
FunctionDebugger.cpp
)
set_target_properties(LLVMFunctionDebugger PROPERTIES
COMPILE_FLAGS "-fno-rtti -std=c++11"
)
I configure and compile like this:
mkdir build && cd build
cmake ..
make
It correctly compiles and links a shared library called libLLVMFunctionDebugger.so. What I don't understand is how cmake could find the package requested in:
# <project-root>/CMakeLists.txt
find_package(LLVM REQUIRED CONFIG)
I am not giving it any path nor I have anything defined in the environment but the path to the LLVM binaries.
I read the CMake documentation, but it says that the find_package looks in folders under CMAKE_PREFIX_PATH. I print that variable with message(STATUS ${CMAKE_PREFIX_PATH}) and the output is empty.
Your set-up looks correct and clearly CMake is finding LLVMConfig.cmake script (i.e. the script that find_package consumes to propagate the necessary CMake variables with LLVM 8 set-up).
On the Ubuntu 16.04 machine that I have access to, LLVMConfig.cmake is located in /usr/lib/llvm-8/lib/cmake/llvm/LLVMConfig.cmake, but there's also a symlink in /usr/lib/llvm-8/cmake/. So the natural questions is: does CMake know that it should look there? The answer is yes. In CMake docs you can see that one of the search paths is:
<prefix>/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/ (U)
You can verify that usr is on the list of prefixes by printing CMAKE_SYSTEM_PREFIX_PATH. On my machine that's set-up to:
/usr/local;/usr;/;/usr;/usr/local
Finally, you can print LLVM_DIR in your CMake script to check which version/installation of LLVM was picked by find_package. The variable will be empty on the first execution of CMake, but then find_package finds LLVM-8, the variable is set and saved in CMakeCache.txt.
Hope this helps.
EDIT
This answer was tested on Ubuntu 16.04 on which LLVM 8 was installed in the default, system-wide location through apt-get. If you install LLVM 8 elsewhere, then there are various ways of pointing CMake to the right location, see the docs for find_package. Editing the PATH variable is one of them:
Search the standard system environment variables. This can be skipped if NO_SYSTEM_ENVIRONMENT_PATH is passed. Path entries ending in /bin or /sbin are automatically converted to their parent directories:
PATH
Since cmake 3.17, you can use cmake --debug-find <cmake-options> to ask cmake to output a bunch of debugging information on find_* functions. On my machine, it outputs
Standard system environment variables [CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH].
/home/jiaqi/Documents/LLVM/llvm-project/build
/home/jiaqi/.local
/home/jiaqi/.yarn
/home/jiaqi/anaconda3
/home/jiaqi/anaconda3/condabin
/usr/local
/usr
/
/usr/games
/usr/local/games
/snap
... outputs omitted...
find_package considered the following locations for LLVM's Config module:
/home/jiaqi/Documents/LLVM/Test/build/CMakeFiles/pkgRedirects/LLVMConfig.cmake
/home/jiaqi/Documents/LLVM/Test/build/CMakeFiles/pkgRedirects/llvm-config.cmake
/home/jiaqi/Documents/LLVM/llvm-project/build/LLVMConfig.cmake
/home/jiaqi/Documents/LLVM/llvm-project/build/llvm-config.cmake
/home/jiaqi/Documents/LLVM/llvm-project/build/cmake/LLVMConfig.cmake
/home/jiaqi/Documents/LLVM/llvm-project/build/cmake/llvm-config.cmake
/home/jiaqi/Documents/LLVM/llvm-project/build/lib/cmake/llvm/LLVMConfig.cmake
The file was found at
/home/jiaqi/Documents/LLVM/llvm-project/build/lib/cmake/llvm/LLVMConfig.cmake
So, the cmake is using Config mode here and the file is located at /home/jiaqi/Documents/LLVM/llvm-project/build/lib/cmake/llvm/LLVMConfig.cmake
To figure out how cmake finds the LLVMConfig.cmake, take a look at https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure
For step 5, it says the cmake will search the environment variable $PAT, and note that
Path entries ending in /bin or /sbin are automatically converted to their parent directories.
Since I have put the path to llvm executables in $PATH:
$ echo $PATH
/home/jiaqi/Documents/LLVM/llvm-project/build/bin:/home/jiaqi/.local/bin:/home/jiaqi/.yarn/bin:/home/jiaqi/anaconda3/bin:/home/jiaqi/anaconda3/condabin:/home/jiaqi/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
The folder /home/jiaqi/Documents/LLVM/llvm-project/build will be used as prefix. According to https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure, the folder <prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/ will be searched.
I know that KDevelop 4 was able to import CMake projects (hand written CMakeLists.txt not generated by KDevelop) ... but now after I installed ubuntu 18.04 it seems this is not possible anymore (the Project > Open/Import Project dialog simply refuse take CMakeLists.txt when I click on it )? Or I miss something?
I tried to run cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS
as described here but it refuse with error message:
prokop#s2-041:~/git/SimpleSimulationEngine/cpp/Build$ cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS
Parse error in command line argument: -DCMAKE_EXPORT_COMPILE_COMMANDS
Should be: VAR:type=value
CMake Error: No cmake script provided.
CMake Error: Problem processing arguments. Aborting.
EDIT
OK, so according to the advice below I run
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
and now it generate compile_commands.json but I still cannot open it with KDevelope ... the Import Project dialog still shows everything gray and inactive (see screenshots below). Not sure if it matters that I run KDevelop under xubuntu 18.04 LTS (not Kubuntu) and Gnome-Flashback Desktop environment.
This should still work in KDevelop 5. There's no need to run cmake -DCMAKE_EXPORT_COMPILE_COMMANDS .., KDevelop will do it for you.
The version of KDevelop packaged in Ubuntu 18.04 is rather old and has many known bugs, please try the 5.4.2 AppImage and see if that resolves your problem.
You should put the path to your source (top-level CMakeLists.txt file) at the end of your command, after any options.
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
Here is the command line syntax documentation.
Edit: As Tsyvarev points out, CMake specifically complains about your -D syntax, which is missing the assignment to ON.
Currently I am trying to build PlusRemote from SlicerIGT, but I keep getting errors that don't make much sense to me. I downloaded SlicerIGT from GitHub here, and I made sure to update CMake to version 3.2.3. The directory I am getting the source from should be fine. This is the error log I am getting:
CMake Error at CMakeLists.txt:19 (slicerMacroBuildScriptedModule):
Unknown CMake command "slicerMacroBuildScriptedModule".
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.2)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
Is there any way to solve this, or is there a better way to go about building PlusRemote?
EDIT:
I managed to specify the minimum required version so now the only error I am getting is:
CMake Error at CMakeLists.txt:19 (slicerMacroBuildScriptedModule):
Unknown CMake command "slicerMacroBuildScriptedModule".
If anything, this is what CMake is reading:
#-----------------------------------------------------------------------------
set(MODULE_NAME PlusRemote)
cmake_minimum_required(VERSION 3.2)
#-----------------------------------------------------------------------------
set(MODULE_PYTHON_SCRIPTS
${MODULE_NAME}.py
)
set(MODULE_PYTHON_RESOURCES
Resources/Icons/${MODULE_NAME}.png
Resources/Icons/icon_Record.png
Resources/Icons/icon_Stop.png
Resources/Icons/icon_Wait.png
Resources/Icons/VisibleOff.png
Resources/Icons/VisibleOn.png
)
#-----------------------------------------------------------------------------
slicerMacroBuildScriptedModule(
NAME ${MODULE_NAME}
SCRIPTS ${MODULE_PYTHON_SCRIPTS}
RESOURCES ${MODULE_PYTHON_RESOURCES}
WITH_GENERIC_TESTS
)
#-----------------------------------------------------------------------------
if(BUILD_TESTING)
# Register the unittest subclass in the main script as a ctest.
# Note that the test will also be available at runtime.
slicer_add_python_unittest(SCRIPT ${MODULE_NAME}.py)
# Additional build-time testing
add_subdirectory(Testing)
endif()
Did I miss downloading or updating anything?
EDIT: Is this what I'm missing?
PlusRemote does not need to be built using CMake in order to have Plus run. Plus will start on it's own. Wish I had known this 3 hours ago.
How can you link GLEW to a project with CMake?
We've been trying to link GLEW to our project using CMake for at least 3 hours without any success so any help is accepted.
I'm using the FindGLEW.cmake which comes with CMake 3.1.0
CMakeLists.txt
find_package(GLEW REQUIRED)
if (GLEW_FOUND)
include_directories($(GLEW_INCLUDE_DIRS))
endif()
Environment Variables
I'm using MinGW w64 to compile the sources and we successfully linked GLFW and GLM just by copying the includes and libs to their respective folders, but after doing the same with GLEW, CMake still couldn't find it.
Sorry if I wasn't clear enough while formulating the question. I will provide any additional information required.
Edit: I've managed to link the header files by specifying their location in the CMake Cache file, though I'm getting undefined reference to glew functions like glewInit().
Typical CMake scripts like FindGLEW will define variables that specify the paths and files that your project needs. If the script can't automatically identify the correct paths (usually because of nonstandard install location, which is fine), then it leaves these variables up to you to fill in.
With command line CMake, you use the -D flag to define and set the value of a given variable. Other CMake interfaces, like CMake-gui or an IDE integration, give you this ability some other way.
However you do it, you can also modify the cache directly (CMakeCache.txt) and see what CMake is using in there or just clear the cache altogether. You'll have to rerun CMake for it to pick up your changes.
When it comes to linking, that's when you need to tell CMake which libs to link. Use the link_libraries command with what the automated script gives you.
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})
Other answers do obviously work, but the target based style of cmake makes it even easier since the GLEW find module defines the imported target GLEW::GLEW. All you need is:
find_package(GLEW REQUIRED)
target_link_libraries(YourTarget GLEW::GLEW)
YourTarget is the target that you created with add_executable or add_library. No need to explicitly add include directories, they are added automatically by linking the targets.
The secret of find_package(GLEW) is in FindGLEW.cmake file with cmake install.
find_path(GLEW_INCLUDE_DIR GL/glew.h)
find_library(GLEW_LIBRARY NAMES GLEW glew32 glew glew32s PATH_SUFFIXES lib64)
The find_path and find_library commands find paths in standard system paths. If you want them to find paths in user defined directories, you should tell them.
For example:
set(CMAKE_PREFIX_PATH "d:/libs/glew-1.10.0")
set(CMAKE_LIBRARY_PATH "d:/libs/glew-1.10.0/lib/Release/Win32/")
find_package(GLEW REQUIRED)
Reference:
http://www.cmake.org/cmake/help/v3.0/command/find_path.html
http://www.cmake.org/cmake/help/v3.0/command/find_library.html
I was struggling hard to link glew to cmake through command line on mac. This might be helpful but I am not sure :) I will walk you through step by step of what I have done.
I installed Cmake source from the web.
Then I went inside the cmake folder in terminal and typed
./bootstrap && make && make install
(this will install cmake command line tools on our OS platform)
I have some exercise files. I want cmake to generate xcode files for me for all those exercise files (ex. triangles.cpp, shader.cpp etc) So i made a directory inside exercise files folder.
$ mkdir xcode
$ cd xcode
$ cmake -G "Xcode" ..
At this point, Cmake suppose to install all xcode files that included correct libraries. But there was an error :
$ cmake -G "Xcode" ..
CMake Warning (dev) at CMakeLists.txt:3 (cmake_minimum_required):
Compatibility with CMake < 2.4 is not supported by CMake >= 3.0.
This warning is for project developers. Use -Wno-dev to suppress it.
system name is: Darwin-14.1.0
system processor is: x86_64
-- Could NOT find GLEW (missing: GLEW_INCLUDE_DIR GLEW_LIBRARY)
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Using Cocoa for window creation
-- Using NSGL for context creation
-- Building GLFW only for the native architecture
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GLEW_LIBRARY
linked by target "TextureLoader" in directory /Users/Mydir/Desktop/Exercise/Exercise Files
-- Configuring incomplete, errors occurred!
Then to make sure I have installed GLEW and all its libraries correctly, I ran
$brew install glew
Yes, I have installed glew already but it was NOT linked. See the Warning below:
Warning: glew-1.12.0 already installed, it's just not linked
Then I ran the following commands:
$ brew unlink glew
$ brew link glew
And I have solved the error. So just make sure that you have linked glew. Hope this helps.
Happy Coding :)
Finally I found a simple and short CMakeLists which works if you have installed everything in default paths.(openGL, glfw and glew)
cmake_minimum_required(VERSION 3.3)
project(openGL_tutorial)
find_package(OpenGL REQUIRED)
if(NOT OPENGL_FOUND)
message("ERROR: OpenGL not found")
endif(NOT OPENGL_FOUND)
set(GL_LIBRARY GL GLU X11)
add_executable(openGL_tutorial main.cpp)
target_link_libraries(openGL_tutorial glfw GLEW libGLEW.so libGLU.so libGL.so)
For what it is worth, in 2023, this works for me, on macOS, with GLEW, GLFW, and CMake installed using Homebrew:
cmake_minimum_required(VERSION 3.10)
project(Project)
add_executable(Project main.cpp)
find_package(glfw3 REQUIRED)
find_package(GLEW REQUIRED)
target_link_libraries(Project glfw GLEW::glew)
I installed Ogre3D 1.8.1 (the source package) on Ubuntu 12.04 and everything went fine (I managed to run some samples on the Ogre interface). However, I hit a problem while I was compiling an external project (that one) that needed the OpenCV, ArUco and Ogre librarys. When I run the CMake of the project, I receive the following:
CMake Error at CMakeLists.txt:46 (find_package):
By not providing "FindOGRE.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OGRE", but
CMake did not find one.
Could not find a package configuration file provided by "OGRE" 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.
-- Configuring incomplete, errors occurred!
I know where the FindOGRE.cmake is, it's in the /usr/local/lib/OGRE/cmake, but I don't know how to say to CMake to look for that folder and fix this problem.
You just need to use the -D command line option along with the CMAKE_MODULE_PATH variable:
cmake . -DCMAKE_MODULE_PATH=/usr/local/lib/OGRE/cmake
Just for the record, an alternative solution would be to add the module path directly in the CMakeLists.txt. For example (tested on Debian 9):
set(CMAKE_MODULE_PATH "/usr/share/OGRE/cmake/modules/;${CMAKE_MODULE_PATH}")
Just make sure to add the line before find_package is called.
For me, it only works to set the following in CMakeLists.txt before find_package:
set(OGRE_DIR /usr/share/OGRE/build/sdk/CMake)
Note that the CMake directory is the one containing OGREConfig.cmake. For some reason, my CMake ignores CMAKE_MODULE_PATH.
Maybe, of some help for someone
For me, this solution work on manjaro:
set(CMAKE_MODULE_PATH "/usr/lib/OGRE/cmake;${CMAKE_MODULE_PATH}")
find_package(OGRE QUIET)
if (OGRE_FOUND)
include_directories( ${ogre_INCLUDE_DIR})
link_directories(${OGRE_LIBRARIES})
message(STATUS "OGRE: FOUND")
else()
message(STATUS "OGRE: NOT FOUND")
endif()