windows 在整个项目中使用 cmake 后在子目录中使用 Cmake 的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6507717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:14:08  来源:igfitidea点击:

Problem with using Cmake in sub directories after once using cmake on the entire project

cwindowscmake

提问by javaMan

I have a head folder called Tutorial and sub folder called MathFunctions each having one code each I wrote CMakeLists.txt for both the folders and used cmake in cmd promptand it is working fine.

我有一个名为 Tutorial 的头文件夹和一个名为 MathFunctions 的子文件夹,每个文件夹都有一个代码,我为这两个文件夹编写了 CMakeLists.txt 并在 cmd 提示符下使用了 cmake,它工作正常。

CMakeLists.txt in head folder has the following:

head 文件夹中的 CMakeLists.txt 具有以下内容:

CMAKE_MINIMUM_REQUIRED ( VERSION 2.6)

PROJECT (Tutorial)

SET (Tutorial_VERSION_MAJOR 1)
SET (Tutorial_VERSION_MINOR 0)

CONFIGURE_FILE (
"${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
"${PROJECT_BINARY_DIR}/TutorialConfig.h "
)

INCLUDE_DIRECTORIES ("${PROJECT_BINARY_DIR}")

OPTION (USE_MYMATH "Use tutorial provided math implementation" ON)

if (USE_MYMATH)
  INCLUDE_DIRECTORIES ("${PROJECT_SOURCE_DIR}/MathFunctions")

  ADD_SUBDIRECTORY (MathFunctions)
  SET (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (USE_MYMATH)

ADD_EXECUTABLE (Tutorial tutorial.c)
TARGET_LINK_LIBRARIES (Tutorial ${EXTRA_LIBS})

CMakeLists.txt in sub folder has the following:

子文件夹中的 CMakeLists.txt 有以下内容:

CMAKE_MINIMUM_REQUIRED ( VERSION 2.6)
add_library (MathFunctions mysqrt.c )

and in command prompt :

并在命令提示符下:

C:\home\Tutorial\BUILD>cmake ..

-- Building for: Visual Studio 9 2008

-- Check for working C compiler using: Visual Studio 9 2008

-- Check for working C compiler using: Visual Studio 9 2008 --

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Check for working CXX compiler using: Visual Studio 9 2008

-- Check for working CXX compiler using: Visual Studio 9 2008

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Configuring done

-- Generating done

-- Build files have been written to: C:/home/Tutorial/BUILD

Later I made some modifications in MathFunctions.c .I made no changes in Tutorial.c. So i want to re generate make files only for MathFunctions folder. But I am not able to do it. I am getting the following error

后来我在 MathFunctions.c 中做了一些修改。我在 Tutorial.c 中没有做任何更改。所以我想只为 MathFunctions 文件夹重新生成 make 文件。但我做不到。我收到以下错误

C:\home\Tutorial\BUILD>cmake ../MathFunctions

CMake Error: The source "C:/home/Tutorial/MathFunctions/CMakeLists.txt" does not match the source "C:/home/Tutorial/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.

CMake 错误:源“C:/home/Tutorial/MathFunctions/CMakeLists.txt”与用于生成缓存的源“C:/home/Tutorial/CMakeLists.txt”不匹配。使用不同的源目录重新运行 cmake。

I cannot figure out why this error is coming. Please help Thanks

我无法弄清楚为什么会出现此错误。请帮忙谢谢

采纳答案by tibur

If you have made modifications to a source file which is already in the project, there is no need to relaunch CMake. Just recompile.

如果您对项目中已有的源文件进行了修改,则无需重新启动 CMake。重新编译就好了

回答by ClintFromVa

OK, I know this is ancient but...had a similar problem, same error message.

好的,我知道这是古老的,但是......有一个类似的问题,同样的错误信息。

There is a command under File on the GUI that cleans out the cache. This did not work the first time but eventually it did. I thrashed around a bit, adding cmake to the user path, reboot, don't know if any of that helped.

GUI 上的 File 下有一个命令可以清除缓存。这在第一次没有奏效,但最终奏效了。我折腾了一下,将 cmake 添加到用户路径,重新启动,不知道是否有帮助。

I got into trouble initially by trying to run cmake on a CMakeLists.txt that was NOT the root. This error popped up when I tried again with the proper source directory. V3.1.3.

我最初尝试在不是根的 CMakeLists.txt 上运行 cmake 时遇到了麻烦。当我再次尝试使用正确的源目录时,出现此错误。V3.1.3。

回答by Stanislav Parkhomenko

Just remove

只需删除

.externalNativeBuild

.externalNativeBuild

folder from your project and sync it again. By doing this you will remove build cache.

项目中的文件夹并再次同步。通过这样做,您将删除构建缓存。