CMake "Could not read from count file." - cmake

In my main CMakeLists file I include() another cmake file which has these two lines:
add_custom_target(myTarget)
add_custom_command(TARGET myTarget COMMAND echo ARGS "Here is an echo" WORKING_DIRECTORY ${PARENT_DIR})
Here is the output after I build and run 'make myTarget':
Could not read from count file.
Here is an echo
Built target myTarget
Could not read from count file.
I have no idea what this 'count file' is that it tells me about twice. Can anyone tell me what this means?
Cmake version 3.6.2

The "count file" is where CMake logs the build progress, so that it can give its "% complete" output.
I seriously doubt the "could not read from count file" is related to your two lines. Insufficient write permissions to the binary directory, perhaps, or some path mismatch?

I had the same problem (in a build directory where I had accidentally called cmake from a sub directory). Removing all contents of the build directory and running cmake again fixed the issue.

Related

CMAKE keeps giving error "does not appear to contain CMakeLists.txt"

I am trying to figure out CMake and can't seem to figure out this basic issue. Every time I try to configure the project using CMake GUI it gives me an error stating the "source directory does not appear to contain CMakeLists.txt" when it clearly does. The text of the CMakeLists.txt file is:
cmake_minimum_required(VERSION "3.19.0")
project("Hello_World")
add_executable("${PROJECT_NAME}" "main.cpp")
install (TARGETS "${PROJECT_NAME}" DESTINATION bin)
install (FILES "main.cpp" DESTINATION src)
Also here is an image of my screen with all the relevant info:
When I navigate to the Hello_World directory in the console and enter cmake, I get this:
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
cmake [options] -S <path-to-source> -B <path-to-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Run 'cmake --help' for more information.
What am I missing? Any help would be appreciated. Thanks.
What happens if you open a console, change to the Hello-World-Directory and call 'cmake'?
I figured it out. For those struggling with the same issue see this video: https://www.youtube.com/watch?v=gYmgbqGfv-8
The issue is that you must go into the View settings of the Windows Explorer and make sure that the "file name extensions" box is checked so that Windows won't consider your file extension to be part of the file name. Such as CMakeLists.txt.txt.

boost bjam fails as a cmake external project

I am trying to add boost bjam build as an external cmake project.
This is my cmake code to build boost
include(ExternalProject)
ExternalProject_Add(
libboost
PREFIX ${BOOST_BUILD_DIRECTORY}
SOURCE_DIR ${BOOST_SOURCE_DIRECTORY}
BINARY_DIR ${BOOST_SOURCE_DIRECTORY}
CONFIGURE_COMMAND ""
BUILD_COMMAND ${b2Path}
--build-dir=${BOOST_BUILD_DIRECTORY}
--link=static
--variant=debug
--build-type=complete
INSTALL_COMMAND ${b2Path}
--prefix=${BOOST_BUILD_DIRECTORY}/${BoostFolderName}
--link=static
--variant=debug
--build-type=complete
INSTALL_DIR ${BOOST_BUILD_DIRECTORY}/${BoostFolderName}
LOG_BUILD ON
LOG_INSTALL ON
)
message("boostbuild done")
The problem here is, once in a while it fails. the same step for bjam doesn't fail if invoked through command line.
The error is
type "C:\Users\adhal\AppData\Local\Temp\jam6818c95b4.000" > "C:\build-sdk-Desktop_Qt_5_11_3_MSVC2017_64bit-Debug\external\boost\boost\bin.v2\libs\program_options\build\msvc-14.1\debug\address-model-64\link-static\runtime-link-static\threading-multi\libboost_program_options-variant-vc141-mt-sgd-x64-1_73-static.cmake"
...failed text-action C:\build-sdk-Desktop_Qt_5_11_3_MSVC2017_64bit-Debug\external\boost\boost\bin.v2\libs\program_options\build\msvc-14.1\debug\address-model-64\link-static\runtime-link-static\threading-multi\libboost_program_options-variant-vc141-mt-sgd-x64-1_73-static.cmake...
...skipped <pC:\proj\sdk\external\boost-program-options\stage\lib\cmake\boost_program_options-1.73.0>libboost_program_options-variant-vc141-mt-sgd-x64-1_73-static.cmake for lack of <pC:\build-sdk-Desktop_Qt_5_11_3_MSVC2017_64bit-Debug\external\boost\boost\bin.v2\libs\program_options\build\msvc-14.1\debug\address-model-64\link-static\runtime-link-static\threading-multi>libboost_program_options-variant-vc141-mt-sgd-x64-1_73-static.cmake...
compile-c-c++ C:\build-sdk-Desktop_Qt_5_11_3_MSVC2017_64bit-Debug\external\boost\boost\bin.v2\libs\regex\build\msvc-14.1\debug\address-model-64\link-static\runtime-link-static\threading-multi\regex.obj
When I run the exact same step, it doesn't fild the file(C:\Users\adhal\AppData\Local\Temp\jam6818c95b4.000). Since it's a temporary file, it's deleted.
Can someone tell me, if I am doing anything wrong ? Is it possible to specify a separate temporary directory for bjam ?
Got same issue. In my case moving build folder up helped.
Issue check story - tmp .bat file contains
type "C:\Users\amorozov\AppData\Local\Temp\jam43e8891f.000" > "bin.v2\libs\program_options\build\msvc-14.1\debug\address-model-64\link-static\runtime-link-static\threading-multi\libboost_program_options-variant-vc141-mt-sgd-x64-1_73-static.cmake"
Running it from cmake binary dir where build happens fails too. Splitting command to type and dir for target directory succeeds. Writing to file with shorter name succeeds. Checked total filepath length for .cmake file and it's over 256 bytes. It seems as cmd doesn't allow redirecting to really long pathnames. Moving whole project few directories up solved my issue.
If that doesn't help, check your tmp .bat file by running b2 under windbg with breakpoint on kernel32!DeleteFileW. Filename is du poi(#esp+4). Hope that helps.

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 (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.

Is there a way to get errors when a CMake command fails?

I am writing a script and started working with the install command (for copying files) and it is not working. CMake configure/generate does not show any errors (i.e. it does not stop and no warnings/errors show related to this command) and the command does not seem to be working, because I don't see any files being copied.
Since I am new, I am wondering:
How can I tell that install failed (perhaps the source directory was wrong, or the destination directory was wrong)? It appears to be failing silently.
Are there error codes I can check to see what went wrong?
When is install called? When I click configure? Or when the project is built?
I am on Windows.
To the general question, there are a number of ways to get more verbose output from CMake - I just learned a third for gnarly errors:
to debug CMake recipes, I like using the message command and you can even iterate over directories and issue messages*
e.g. message( STATUS "SQLITE3_LIB: ${SQLITE3_LIB} SQLITE3_PATH: ${SQLITE3_PATH}") # prints SQLITE3_LIB and SQLITE3_PATH variables
perform verbose builds to troubleshoot your build itself
run make VERBOSE=1 (with make, ninja -v with ninja, etc.) to help you troubleshoot the process, such as cmake -DYOUR_OPTION="insert values" ~/path/to/files/ && make VERBOSE=1
if you ever find an inscrutable error, I just learned that we can run strace on the failing command - this can be a bit overwhelming, but can help when you have exhausted #1 and #2
I just used strace /usr/bin/cmake -E copy_directory $MY_SOURCE_PATH $MY_DEST_PATH to try to understand why a copy was failing
*I have used DLRdave's answer to a different question to print out the INCLUDE_DIRS:
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()
When you add an install command to your CMakeLists.txt, you get a new target created called "install".
In order to actually install the chosen files/targets, you need to build this install target. It's not automatically built as part of the "ALL" target.
For example, if you're using Visual Studio, the "INSTALL" target should appear in the "CMakePredefinedTargets" folder of the Solution Explorer. Just selecting this target and building it will cause the solution to be built and the selected items installed.
If any part of the build or install process fails, the notifications should then be apparent.