Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake Error at CMakeLists.txt (target_link_libraries)

Tags:

cmake

I have a problem with CMake. I have wrote a CMakeList.txt file. But when I run it with Cmake I got a strange error "CMake Error at CMakeLists.txt:17 (target_link_libraries): Cannot specify link libraries for target "debug" which is not built by this project.".

Is it possible to create a Cmake file that can build a project file for Debug and Release mode at the same time? Or is there a simple way to fix this error?

My CMakeLists.txt looks like this:

  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)

Edit: Added new source code.

like image 546
JimmyD Avatar asked Sep 06 '13 06:09

JimmyD


People also ask

What does CMake Target_link_libraries do?

Specify libraries or flags to use when linking a given target and/or its dependents. Usage requirements from linked library targets will be propagated. Usage requirements of a target's dependencies affect compilation of its own sources.

What is CMakeLists txt?

CMakeLists. txt file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both). When you create a new project, CLion generates CMakeLists. txt file automatically and places it in the project root directory.


1 Answers

Looks like your CMakeLists.txt doesn't contain either of two lines (which depends you are creating a library or a executable)

add_library(debug <files Name>)

OR

add_executable(debug <files Name>)

If you have these lines in your file, place it before target_link_libraries ()

like image 124
user2618142 Avatar answered Oct 06 '22 22:10

user2618142