在我的问题What can cause a CMake option not work?之后,我试图找出使用clean-all.cmake和手动删除构建目录之间是否有任何区别。在运行clean-all之后,我仍然遇到选项问题。当我删除build子目录时,我收到以下错误消息:
-- 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)
并且日志文件仅包含:
Determining if files pthread.h exist failed with the following output:
Source:
/* */
#include <pthread.h>
int main(void){return 0;}
并且,从那以后,系统一直在告诉错误。所以,它看起来有区别:);它是什么?我的CMakeLists.txt是否可能导致内部错误?
PS:在遇到这个永久性错误后,我开始寻找原因,再次构建我的CMakeLists.txt,从已删除的build子目录开始。
一开始,我有
option (CLEAN_ALL "Make a cleanup before building" OFF)
后
if(CLEAN_ALL)
include(cmake/clean-all.cmake)
endif(CLEAN_ALL)
并且cmake文件是
# 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)
看起来错误是可重现的:删除构建并打开选项,我收到提到的错误。同时,选项OFF,它构建正常。使用全干净的东西有什么害处吗?
答案 0 :(得分:0)
CMake将作为文件构建的项目的状态存储在项目的构建目录中。这些文件不受保护,因此对它们进行不正确的修改(如删除)可能会导致项目状态变得不一致。
消息Internal CMake error
表示这是(可能)
否则,这样的错误只表示项目构建以某种方式被破坏。
在给定的情况下,在CMake调用期间删除文件CMakeCache.txt
会导致不一致状态。 clean- all.cmake
脚本的来源The answer明确表示,在调用此脚本后,没有CMake命令可以正常工作。