Reputation: 2407
When trying to build my project, I see this in the build configurations (it pops up):
"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.
Upvotes: 5
Views: 10331
Reputation: 5461
Reset cache and reload project!
Tools > CMake > Reset Cache and Reload Project
Upvotes: 4
Reputation: 2099
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.
Upvotes: 0
Reputation: 1976
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.
Upvotes: 2