cmake_parse_arguments missing on CMake re-run - cmake

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.

Related

CMake Error (configure_file): configure_file error configuring file

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.

Cmake on msys2 for someone who's unfamiliar with the environment

I'm trying to get cmake working on msys2. I try to compile some code that I've been given for another project and:
CMake Error: Could not create named generator MSYS Makefiles
I've found this thread and this thread and tried to follow the instructions...only to realize that the wiki that the threads eventually link back to never states where msys stores toolchains. Googling around didn't really help.
Even more oddly, the program that I'm trying to use somehow runs and produces valid data despite throwing an error due to the missing cmake. I don't get it.
I've never used msys before; as someone who's brand new to msys2/cygwin and can't even understand the lingo, how do I get cmake installed and working?
Sounds like you are specifying a -G "MSYS Makefiles" as the CMake generator, but CMake doesn't recognize that generator. When I use CMake on msys2 I just use the default Unix Makefiles generator and everything works just fine. Also, on my current msys2 install, CMake doesn't seem to have a MSYS Makefile generator that I can see (running cmake --help will list the available generators). Try running cmake without the -G option. Also, make sure make is installed first via pacman -Sy make.

Compiling latest release of CppUTest (3.7) with MinGw, pthreads missing

I'm trying to use CppUTest in Windows, first step is to get it to work and I already have problems. These are the things I've tried:
First Approach
With CMake, using the cmake GUI I can do the configure and generate command and I get something in the output directory, but no binaries and no libraries, just a bunch of cmakefiles. The CMake GUI says everything went OK during the configuration and generation steps, however the libraries (.lib files) are not generated in the output directory... is there something I am missing? I've never used CMake before.
Second approach
With MinGW and msys alone, running cmd in Windows and executing a MinGW shell by typing sh in the Windows terminal, afterwards I execute the following commands:
cd <CppUTest folder>
mount c:\mingw /mingw
./autogen.sh
./configure
make
The build process starts but it fails with a message indicating that pthread.h was not found in MinGW directory. If I install the pthread-win32 package with the MinGW package manager and repeat the same steps as above the build process starts but fails with a message indicating that the structure timespec is defined in time.h and pthread.h.
I've tried to follow this same procedure with CppUTest 3.6 and it works perfectly fine, I get the .lib files, so I guess I will have to continue with this for now.
Does anyone know how to build CppUTest 3.7 (latest release) with MinGW or CMake?
In the end I used Cygwin to compile it, I couldn't find a way to compile it with MinGW properly, I added a dirty trick to make it compile under MinGW (handled the timespec redifinition) but chances are that is going to cause issues.
Just make sure that you use Cygwin aswell to compile your tests, something that I found out after making this question (https://www.youtube.com/watch?v=oVmd0P85D8o).

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 ;-)

syntax error near unexpected token `CMAKE_INSTALL_PREFIX'

I'm trying to install gflags on openSuse 13.1.
CMake generated the install files OK, but when I try to run cmake_install.cmake, I get the above error.
The line it's referring to is:
set(CMAKE_INSTALL_PREFIX "/usr/local")
Does anyone know what to do to get it to work, and why it has generated a seemingly unusable file?
As far I know, you just can't do this:
set(CMAKE_INSTALL_PREFIX "/usr/local")
To set the prefix and works as you expected..you need to defined before configuration begins, even before cmake begins:
cmake -DCMAKE_INSTALL_PREFIX="/usr/local" ..
Also, you must know that typical build procedure is
cmake [..]
make
make install