CMakeLists.txt上的CMake错误(target_link_libraries)

时间:2013-09-06 06:19:35

标签: cmake

我遇到了CMake的问题。我写了一个CMakeList.txt文件。但是当我用Cmake运行它时,我遇到了一个奇怪的错误“CMakeLists.txt上的CMake错误:17(target_link_libraries):   无法为目标“debug”指定链接库,而不是由此构建的   项目“。

是否可以创建一个可以同时为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)

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

1 个答案:

答案 0 :(得分:10)

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

add_library(debug <files Name>)

OR

add_executable(debug <files Name>)

如果您的文件中包含这些行,请将其放在target_link_libraries ()

之前