0
|---Engine |----CMakeList.txt |----Engine.cpp |----Engine.h |---Models |----CMakeList.txt |----Snake.cpp |----Snake.hpp |---Type |----CMakeList.txt |----Point.hpp |---CMakeList.txt |---main.cpp 

I just can't tell the main sheet that I want to add a directory with files to it ...

Each time, errors of the following type appear:

CMake Error at CMakeLists.txt: 12 (target_include_directories): Cannot specify include directories for target "Snake" which is not built by this project. CMake Error at CMakeLists.txt: 13 (target_link_directories): Cannot specify link directories for target "Snake" which is not built by this project. CMake Error at Engine / CMakeLists.txt: 8 (target_include_directories): Cannot specify include directories for target "Snake" which is not built by this project. CMake Error at CMakeLists.txt: 17 (target_link_libraries): Cannot specify link libraries for target "Snake" which is not built by this project. - Configuring incomplete, errors occurred! 

Which, for several hours of intensified attempts, are not corrected in any way. Can anyone help with this?

CMakeLists.txt from Engine folder:

set(HEADERS Engine.h) set(SOURCES Engine.cpp) add_library(Engine ${HEADERS} ${SOURCES}) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}) 

Main CMakeList.txt:

cmake_minimum_required(VERSION 3.16.3) project(Snake) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(PROJECT_SOURCES main.cpp ) target_include_directories(${PROJECT_NAME} PUBLIC Engine) target_link_directories(${PROJECT_NAME} PUBLIC Engine) add_subdirectory(Engine) target_link_libraries(${PROJECT_NAME} Engine) add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} ) find_package(SFML 2.5.1 COMPONENTS graphics audio REQUIRED) include_directories(${SFML_INCLUDE_DIR}) target_link_libraries(${PROJECT_NAME} sfml-graphics sfml-audio) set(SFML_STATIC_LIBRARIES FALSE) 
2
  • 3
    You're trying to use a target (${PROJECT_NAME}) before it's been declared. Commented Sep 16, 2021 at 16:56
  • 2
    Variable PROJECT_NAME refers to the name of the current project, started with project() command. It seems that you forgot to call project() in the Engine/CMakeLists.txt. Commented Sep 16, 2021 at 17:13

1 Answer 1

2

There are two errors. The first one is to call a PROJECT_NAME that hasn't been built yet. add_executable(${PROJECT_NAME} ...) and add_library(${PROJECT_NAME ...) should be used before the target_include_directories and target_link_directories that refers to it. Because, as @Stephen Newell noted, otherwise you will be using a PROJECT NAME that hasn't been declared/built yet.

The second error is that you are calling a PROJECT_NAME inside Engine/CMakeLists. Maybe you are missing a project(...) inside of it.

Maybe you should move set(SFML_STATIC_LIBRARIES FALSE) before linking it, as well.

Sign up to request clarification or add additional context in comments.

2 Comments

I changed my main CMakeLIst and right now its work good but i have another problem and it Type/CMakeLIst.txt ``` project(Snake) set(HEADER Point.hpp) add_library(Type ${HEADER}) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}) ``` Its cannot linking with main cmakelist and i havent an idea for solve this problem. New main cmakelist : pastebin.com/tPts9kVu
You would need to also show the Type/CMakeLists.txt, which by the way you wrote with a typo ... make sure that your file doesn't have one as well

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.