In one of my CMakeLists.txt file I do:
include( AICxxProject )
and under certain circumstances (wrong installation) this gives:
CMake Error at src/CMakeLists.txt:1 (include):
include could not find load file:
AICxxProject
I'd like to tell the user what they did wrong and how to fix it
with a FATAL_ERROR message. But, how can I detect if a module
like AICxxProject is going to be found before include-ing it?
Solved by actually reading the documentation of include.
The following works,
include( AICxxProject OPTIONAL RESULT_VARIABLE _module_path )
if ( NOT _module_path )
message( FATAL_ERROR
"include could not find load file: AICxxProject\n"
"1) Make sure that you have the git submodule https://github.com/CarloWood/cwm4 in the top-level directory.\n"
"2) Use `include(cwm4/cmake/AICxxProject)` right below the `project(...)` command in your top-level CMakeLists.txt."
)
endif ()
with as output
CMake Error at cwds/CMakeLists.txt:9 (message):
include could not find load file: AICxxProject
1) Make sure that you have the git submodule
https://github.com/CarloWood/cwm4 in the top-level directory.
2) Use `include(cwm4/cmake/AICxxProject)` right below the `project(...)`
command in your top-level CMakeLists.txt.
-- Configuring incomplete, errors occurred!
Related
I'm writing CMake scripts for my project and I'm trying to call another compiler for subset of files, located under subdirectory of the project source tree.
I've found that I can do it using ExternalProject_Add command.
Here is the part of my code
Root CMakeLists.txt
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
add_subdirectory(src)
src/CMakeLists.txt
...
include(ExternalProject)
ExternalProject_Add(subproject_name
PREFIX subproject
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/subproject
DOWNLOAD_COMMAND ""
# UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${PROJECT_SOURCE_DIR}/cmake/custom.toolchain.cmake
)
However, I'm getting following errors:
CMake Error at /usr/local/share/cmake-3.15/Modules/ExternalProject.cmake:1695 (file):
file attempted to create a directory:
/home/user/project/src/subproject into a source directory.
Call Stack (most recent call first):
/usr/local/share/cmake-3.15/Modules/ExternalProject.cmake:3156 (_ep_set_directories)
src/CMakeLists.txt:93 (ExternalProject_Add)
-- Configuring incomplete, errors occurred!
I've read manual on ExternalProject_Add several times. It says clearly:
SOURCE_DIR ...
If no download method is specified, this must point to an existing directory where the external project has already been unpacked or cloned/checked out.
DOWNLOAD_COMMAND ...
Overrides the command used for the download step (generator expressions are supported). If this option is specified, all other download options will be ignored. Providing an empty string for effectively disables the download step.
So, to my mind, CMake should take sources in the subdirectory and create build system under build subdirectory.
However, it tries to create directory src/subproject that already exists.
I've also tried removing PREFIX argument, but have got the same error.
What am I doing wrong?
It seems that current implementation of ExternalProject_Add conflicts with CMAKE_DISABLE_IN_SOURCE_BUILD option. You need to avoid this option when SOURCE_DIR parameter for ExternalProject_Add points inside your source tree.
See that bugreport: https://gitlab.kitware.com/cmake/cmake/-/issues/18811.
Hi im trying to get cmake to find dbus-1
I keep getting this error when i try to compile
-- Checking for module 'dbus-1'
-- No package 'dbus-1' found
Ive tried this command
pkg-config --cflags dbus-glib-1
I get the output
-I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
I edited the CMakeLists.txt and added
include_directories(/usr/include/dbus-1.0/)
What am i doing wrong??
The first thing to know about CMake in this situation is don't use the include_directories to include any system directories with a hard-coded path(which is what you are doing now). What you should do instead is use the CMake FindPkgConfig module which will call pkg-config and get those include directories for you.
To do this, something like the following should work.
include( FindPkgConfig )
pkg_check_modules( dbus REQUIRED dbus-1 )
# Add the include directories to our target executable/shared object.
# In this case, our target is called 'executable' and must have been
# created by a previous call to either 'add_executable' or 'add_library'
target_include_directories( executable PUBLIC ${dbus_INCLUDE_DIRECTORIES} )
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).
Following my question What can cause a CMake option not work? I attempted to find out whether there is any difference between using clean-all.cmake and manually deleting the build directory. After running clean-all, I still experience the option problem. When I remove the build subdirectory, I receive the error message below:
-- Looking for include file pthread.h
-- Looking for include file pthread.h - not found
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: Internal CMake error, TryCompile configure of cmake failed
CMake Error at /usr/local/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
/usr/local/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:374 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.2/Modules/FindThreads.cmake:204 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
cmake/Dependencies.cmake:11 (find_package)
CMakeLists.txt:53 (include)
and the log file only contains:
Determining if files pthread.h exist failed with the following output:
Source:
/* */
#include <pthread.h>
int main(void){return 0;}
And, since that, the system keeps telling that error. So, it looks like there is a difference :) ; what is it? Is it possible that my CMakeLists.txt leads to some internal error?
PS: After having this permanent error, I started to look for its reason, building up my CMakeLists.txt again, starting with deleted build subdirectory.
At the beginning, I have
option (CLEAN_ALL "Make a cleanup before building" OFF)
later
if(CLEAN_ALL)
include(cmake/clean-all.cmake)
endif(CLEAN_ALL)
and the cmake file is
# clean-all.cmake
# Cleans all subdirectories in the build subdirectory
set(cmake_generated ${CMAKE_BINARY_DIR}/CMakeCache.txt
${CMAKE_BINARY_DIR}/cmake_install.cmake
${CMAKE_BINARY_DIR}/Makefile
${CMAKE_BINARY_DIR}/CMakeFiles
# Above this, the common directories, below the project-specific ones
${CMAKE_BINARY_DIR}/bin
${CMAKE_BINARY_DIR}/lib
${CMAKE_BINARY_DIR}/QtGUI
${CMAKE_BINARY_DIR}/test
)
foreach(file ${cmake_generated})
if (EXISTS ${file})
file(REMOVE_RECURSE ${file})
endif()
endforeach(file)
It looks like the error is reproducible: deleting build and switching the option ON, I receive the error mentioned. At the same time, with option OFF, it builds OK. Is there anything harmful with using that clean-all?
CMake stores the state of the project built as files in the build directory for the project. These files are not protected, so improper modification of them (like deleting) may cause state of the project to become non-consistent.
Message Internal CMake error means that this is (probably) an error within CMake if project build files, generated by CMake, are not corrupted outside.
Otherwise, such an error just signals that the project build is broken somehow.
In the given case, the inconsistent state is caused by deleting file CMakeCache.txt during CMake invocation. The answer which is origin of your clean- all.cmake script explicitly says that after calling this script no CMake command will work.
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()