0

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?

Community
  • 1
  • 1
katang
  • 2,474
  • 5
  • 24
  • 48
  • [The answer](http://stackoverflow.com/a/13714219/3440745) which is origin of your `clean-all.cmake` script **explicitely says**, that any CMake action after calling this script will not work. So, what do you want? – Tsyvarev Mar 02 '16 at 12:39
  • I think "will not work" and "leads to an internal error", are different. And also, in a second run, when the option is OFF, shall CMake remember that it was ON, until I manually delete build? – katang Mar 02 '16 at 12:56
  • Values for options, like other cache variables, are stored in file `CMakeCache.txt`. If you delete this file, all stored option's values are lost. – Tsyvarev Mar 02 '16 at 14:04

1 Answers1

0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153