mercredi 17 mars 2021

cmake cannot find header/cpp file

I am new guy to CMake. After make a couple days of studying guideline by basic CMake I tried to make my own.

Project tree

I have directory that contains:

  • include dir for headers;
  • src dir for cpp files;
  • CMakeLists.txt

Headers are classes which implement in cpp files in src dir.

When I try add_executable() like this:

set(PROJECT_FILES
    ./include/first.h
    ./include/second.h
    
    ./src/first.cpp
    ./src/second.cpp

    ./src/main.cpp
)
add_executable(${PROJECT_NAME}
    ${PROJECT_FILES}
)

I had Cmake error:

CMake Error at CMakeLists.txt:36 (add_executable):
  Cannot find source file:
    first.h

If i delete first two rows int set where i tried to include headers, cpp files will not be founded. I've tried to add target_include_directories* after add_executable:

target_include_directories(${PROJECT_NAME} PUBLIC
    "${CMAKE_CURRENT_SOURCE_DIR}/include"
    "${CMAKE_CURRENT_SOURCE_DIR}/src"
    )

But it doesn't help. What I've missed?

Aucun commentaire:

Enregistrer un commentaire