Search code examples
buildcmakeprojectclion

Clion: Target "[NAME]" not found


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.


Solution

  • 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.