CMake Error (configure_file): configure_file error configuring file - cmake

I am working on a project on c++ and need to execute a CMakeLists.txt file to run it. I installed cmake, doxygen, cmake-curses-gui and make using sudo. Then I tried running the file.
The following is a part of the cmake code -
if (BUILD_DOC)
find_package(Doxygen)
configure_file(${PROJECT_SOURCE_DIR}/doc/Doxyfile.in
${PROJECT_SOURCE_DIR}/doc/Doxyfile #ONLY)
add_custom_target(${PROJECT_NAME}_doc ALL ${DOXYGEN_EXECUTABLE}
${PROJECT_SOURCE_DIR}/doc/Doxyfile)
endif ()
Here, it gave me an error message saying that
CMake Error at CMakeLists.txt:77 (configure_file): configure_file
Problem configuring file
Just so that you know, line 77 is configure_file(${PROJECT_SOURCE_DIR}/doc/Doxyfile.in .
If I add AND DOXYGEN_FOUND to the if condition, it doesn't execute anything at all which means that it couldn't find a doxygen executable. But as I already told, I already installed doxygen.
I am new to cmake. So, could anyone please help me with this
Edit:
The OS I am using is Ubuntu 16.04
After I put if(DOXYGEN_FOUND) after the command find_package(doxygen) it executed, but I got the same cmake error in line 78 instead of line 77
Also, now since I got enough information from the comments, I just realized that my problem is more towards finding where the Doxyfile.in file lies than configuring the file. Could anyonee help me with it?

The error is clear
configure_file Problem configuring file
CMake's configure_file(<input> <output>) command is used to copy input file to ouput and replacing #VARIABLES# in input by the corresponding value.
configure_file(${PROJECT_SOURCE_DIR}/doc/Doxyfile.in ${PROJECT_SOURCE_DIR}/doc/Doxyfile #ONLY)
You have to find why this process failed:
Make sure ${PROJECT_SOURCE_DIR} contains the correct path to your project, and make sure the file Doxyfile.in is is the right folder (<project dir>/doc)
Make sure content of Doxyfile.in does not contains any syntax error, in particular with #VARIABLES# that needs to be replaced by their CMake value.
Note that this error has nothing to do with Doxygen on your system, and the fact that CMake actually found it or not.

Related

Cmake can't read file saying it cannot find it, with correct path

I am trying to use conan in a CLion project. Conan generates a conanbuildinfo.cmake file. In this file, it's trying to read another file, generated by conan too, and called conaninfo.txt.
It's not able to find it, and cmake prints the following error :
CMake Error at D:/Sources/vodrm-ecmg_c++/build/conanbuildinfo.cmake:663 (file):
file failed to open for reading (No such file or directory):
/cygdrive/d/Sources/myproject/D:/Sources/myproject/build/conaninfo.txt
As you can see the error is saying cmake could not find the requested file. But it actullay can, because the following code :
if (EXISTS ${_CONAN_CURRENT_DIR}/conaninfo.txt)
message("Found :" ${_CONAN_CURRENT_DIR}/conaninfo.txt)
endif()
file (READ "${_CONAN_CURRENT_DIR}/conaninfo.txt" CONANINFO)
Prints :
Found :D:/Sources/project/build/conaninfo.txt
It's totally contradicting since cmake is finding the file, but not when using file command.
Did anyone encountered this bug, if it's one, before? Any solution? I really don't see what I am doing wrong, since this file is generated by conan.
By the way, I am using cmake version 3.6.2.
Thanks in advance.

CMake Error: cmake don't find source directory or CMakeLists.txt (installing Ogre3D)

so I've tried to use the cmake on ogre to install it but every time I use the command in the directory build :
cmake ..
I've got this error which show up :
CMake Error: The source directory "/home/.../TPs/ogre" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
and after doing :
cmake .. -DCMAKE_MODULE_PATH=/usr/share/OGRE/cmake/modules/
the error transformed in :
CMake Error: The source directory "/home/.../TPs/ogre" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
although it got a CMakeLists.txt.
I've got cmake 2.8.XXX version and python 2.7.XXX, I've tried to use cmake-gui but it also gave me an error about the CMakeCache ...
So do you have any advice?
EDIT : Ok it works, moral of the story, even if you strongly want it, don't ever put '\' in folder names !
Be sure you have activated your virtual env. If you are not, then delete previus build folder. Activate virtual env you want. Make new build folder inside opencv. Then execute cmake.

cmake_parse_arguments missing on CMake re-run

I am trying to write a function which uses cmake_parse_arguments to interpret the parameters. This works fine when running cmake in a fresh build directory. However, any time I try to re-run cmake, CMake seems to believe the function does not exist:
CMake Error at CMakeLists.txt:6 (CMAKE_PARSE_ARGUMENTS):
Unknown CMake command "CMAKE_PARSE_ARGUMENTS".
I feel like I'm missing something obvious. I am using CMake 3.3.2 on Arch Linux.
Include CMakeParseArguments with
include(CMakeParseArguments)
Probably it worked the first time because other Find* files included the file already. As the result of the Find* files are cached and not re-run, they no longer included CMakeParseArguments.

pkg_check_modules cannot find *.pc.cmake

I am using a 3rd party library rbdl, which contains rbdl.pc.cmake, which 'I suppose' is included for using pkg_check_modules in a cmake file.
I update PKG_CONFIG_PATH to point at the rbdl folder
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${CMAKE_BINARY_DIR}/externals/rbdl")
pkg_check_modules(RBDL rbdl)
but pkg_check_modules says it cannot find the module.
When I manually duplicate rbdl.pc.cmake, rename the copy into rbdl.pc and run pkg-config --cflags --libs rbdl in terminal, then my cmake also start working!
Interestingly, now even if I delete rbdl.pc, rbdl module if perfectly found by rbdl.pc.cmake!
So my questions are:
What is the difference between *.pc and *.pc.cmake?
How do I correctly setup my cmake to work with original rbdl.pc.cmake?
Why rbdl.pc.cmake starts to be accepted by pkg_check_modules after that tweak with duplicating it, renaming the copy and running pkg-config manually?
You understand it wrong! rbdl.pc.cmake is just a template file. It is not supposed to be used by you! Take a look into CMakeLists.txt line 160 -- configure_file() used to render variables ("quoted" by # in template file) and produce a rbdl.pc (a real pkg-config) file. Latter should be installed (some way) and then will be available to pkg-config hence can be used in your project.
pkg-config is stupid do not interpret or validate compiler/linker flags any way, so your renamed file "works" (yeah, producing invalid command line for compiler/linker).
I wish you to read CMake documentation before trying to code something using it! It'll save your time and give you a necessary knowledge which stops you from doing stupid things like you described in your question ;-)

How to find the CMake command line I used for the build?

This is what typically happens. I get source code that has cmake build scripts. I create a build subdirectory, change to it, run cmake <options> ... Depending upon the project and its dependencies I have to repeat the last step until it finds all necessary dependencies and generates makefiles. I successfully build and use the project. Few days pass, I forget about this installation. Then one day I'm trying to setup the same project on another machine and now I can't recall what exact CMake command line I used in the past to get things working.
I still have the old build directory on the old machine. Can I find the cmake command line I used in the past, by looking into some of the autogenerated files in the build directory? I was expecting CMake would just put the exact command line I used in one of these files in commented form. But if it does so, I haven't found it yet.
How can I find the original CMake command line I used?
You can't.
Original CMake command can be guessed from analysis of CMakeCache.txt
As a workaround, you could always create a simple wrapper to store the original command line used. Something along these lines:
#!/bin/bash
echo "$#" > cmake_command.log
$#