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

时间:2011-06-28 14:04:43

标签: c windows cmake

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

头文件夹中的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具有以下内容:

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

并在命令提示符下:

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

后来我在MathFunctions.c中做了一些修改。我在Tutorial.c中没有做任何修改。所以我想重新生成仅用于MathFunctions文件夹的make文件。但我无法做到。我收到以下错误

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

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

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

2 个答案:

答案 0 :(得分:4)

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

GUI下的File下有一个清除缓存的命令。这不是第一次工作,但最终确实如此。我吵了一下,将cmake添加到用户路径,重新启动,不知道是否有任何帮助。

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

答案 1 :(得分:2)

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