5

我对 CMake 有疑问。我写了一个 CMakeList.txt 文件。但是当我使用 Cmake 运行它时,我收到了一个奇怪的错误“CMakeLists.txt:17 (target_link_libraries) 的 CMake 错误:无法为不是由该项目构建的目标“调试”指定链接库。”。

是否可以创建一个可以同时为Debug和Release模式构建项目文件的Cmake文件?或者有没有一种简单的方法来解决这个错误?

我的 CMakeLists.txt 看起来像这样:

  cmake_minimum_required (VERSION 2.8)

project (SimuVille)

# Import required CMake files
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")

file(GLOB_RECURSE files
    "*.cpp"
)

add_executable(debug ${files})

# Find the find Modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})

#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()


#Find SfeMovie
find_package(sfeMovie REQUIRED)
if(SFEMOVIE_FOUND)
    include_directories(${SFEMOVIE_INCLUDE_DIR})
    target_link_libraries(${EXECUTABLE_NAME} ${SFEMOVIE_LIBRARY})
endif()

#Find Assimp
find_package(ASSIMP REQUIRED)
if(ASSIMP_FOUND)
    include_directories(${ASSIMP_INCLUDE_DIR})
    target_link_libraries(${EXECUTABLE_NAME} ${ASSIMP_LIBRARY})
endif()

#Find DevIL
find_package(DevIL REQUIRED)
if(IL_FOUND)
    include_directories(${IL_INCLUDE_DIR})
    target_link_libraries(${EXECUTABLE_NAME} ${IL_LIBRARY})
    target_link_libraries(${EXECUTABLE_NAME} ${ILU_LIBRARY})
    target_link_libraries(${EXECUTABLE_NAME} ${ILUT_LIBRARY})
endif()

#Find opengl libs
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(NOT OPENGL_FOUND)
    message(ERROR " OPENGL not found!")
endif(NOT OPENGL_FOUND)

#file(GLOB_RECURSE hfiles
#    "*.h"
#)

#add_executable(SimuVille ${hfiles})


LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/Game)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/SfmlObject)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/Camera)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/OpenglObject)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/Playable)

编辑:添加了新的源代码。

4

1 回答 1

10

看起来您的 CMakeLists.txt 不包含两行中的任何一行(这取决于您要创建库还是可执行文件)

add_library(debug <files Name>)

或者

add_executable(debug <files Name>)

如果您的文件中有这些行,请将其放在前面target_link_libraries ()

于 2013-09-06T06:37:07.077 回答