3

When trying to build my project, I see this in the build configurations (it pops up):

Run/Debug Configrations window, with error message

"LUCID" is the name of my project. I think it all built fine yesterday, but now after only restating I'm getting this:

Error: Target 'LUCID (LUCID)' not found.

The "Target" dropdown only has that one item in it (and also the "Build All" option). I do have project(LUCID) and add_executable(LUCID ${SOURCE_FILES}) in CMakeLists.txt, as was suggested in this question, although the situation is slightly different.

So, why am I getting this error and what do I do to fix it?

Another thing to note is that all the file names that should be part of my project and are specified in set(SOURCE_FILES ...) are greyed out in the CLion file browser, which they should not be.

Community
  • 1
  • 1
Ludwik
  • 2,247
  • 2
  • 27
  • 45

3 Answers3

2

I think you may put all you include_directory before add_executable. And use only the find_package(SDL2 REQUIRED) futher more if you use the REQUIRED keyword you don't have to use the if (lib_FOUND) source here.

You CMake may look like something like this

cmake_minimum_required(VERSION 3.2)
project(LUCID)

set(EXEC_NAME LUCID)

MESSAGE("a test message")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

find_package (Box2D REQUIRED)
find_package (opengl REQUIRED)
find_package (SDL2 REQUIRED)

set(INCLUDE_DIR
    sinclude
    sinclude/3rdparty
    uniheader
    D:/freetype-2.5.3/GnuWin32/include
    ${BOX2D_INCLUDE_DIRS}
    ${OPENGL_INCLUDE_DIRS}
    ${SDL2_INCLUDE_DIRS}
)

include_directories(${INCLUDE_DIR})

set(SOURCE_FILES
    ssrc/Cam.cpp
    #...
    #Lots of source and header files in the same form
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")


message(STATUS "Boaorm")

add_executable(${EXEC_NAME} ${SOURCE_FILES})

target_link_libraries(${EXEC_NAME} ${BOX2D_LIBRARIES} ${OPENGL_LIBRARIES} ${SDL2_LIBRARY})

For SDL i used this answer, but i don't like to use ${PROJECT_NAME} for executable name (you can choose what you prefer anyway)

Edit :
Multiple target_link_libraries are explained here
The problem with the old cmake was the include_directories after the add_executable and the common toolchain is include -> compile -> link then i just follow this logic.

Community
  • 1
  • 1
Waxo
  • 1,816
  • 16
  • 25
  • Thank you, this looks way cleaner. However, would you care to explain why and which part fixes the problem with the missing target? Also, `set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")` can't be moved below the find_package calls, because they need it to find the `FindBox2D.cmake` etc. files. – Ludwik Aug 12 '15 at 07:55
  • ok i fixed the position of `set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")` i've never used this. And added some explanations. Is this working now ? – Waxo Aug 12 '15 at 08:45
  • Yes, this fixes my problem (I still have build issues, but that's another story). And thank you for the clarification, I now understand that it was the includes that were the issue. – Ludwik Aug 12 '15 at 11:51
  • I think I should add a note that I'm not sure it was this that solved my problem. I seems this problem randomly appears or disappears upon restarting Clion. I can't get a grasp over this... – Ludwik Aug 12 '15 at 13:13
  • In this case it's mostly a problem with clion i can suggest you to report a bug to them : https://youtrack.jetbrains.com/issues?q=project%3A+CLion. I hope they can fix it for you fast. – Waxo Aug 12 '15 at 13:35
2

Reset cache and reload project!

Tools > CMake > Reset Cache and Reload Project

enter image description here

Yas
  • 4,957
  • 2
  • 41
  • 24
0

I came across this weird bug yesterday. My CMakeLists.txt is correct (because I can build the project though the terminal).

The end of my CMakeLists.txt looks like this:

add_executable(assignment-1 main.cpp ${SOURCES})
add_library(libassignment-1 STATIC ${SOURCES})

I removed the CMake cache directory, commented out add_library() and reloaded it. Just like that, CLion can now find the assignment-1 executable. Then I uncommented the last line. All the configurations are still fine.

MakotoE
  • 1,814
  • 1
  • 20
  • 39