Question about CMakeLists.txt

Currently, I can use CMakeLists.txt to build a project. Let’s say, in CMake to build the project, the path of source code is PATH, and the path of binaries is PATH/bin.

Then, I want to add some myself code, for example, some classes.
I put the myclass.h and myclass.cpp in PATH. Then, in the main code, I include myclass.h by " #include <myclass.h> ", and bug is reported as:

cannot open source file “myclass.h”

Should I change the CMakeLists.txt to include the myclass.h and myclass.cpp?

My CMakeLists.txt is:

project(GPURegistration)

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

add_executable(GPURegistration GPURegistration.cxx )
target_link_libraries(GPURegistration ${ITK_LIBRARIES})

If you are #include-ing myclass.h from GPURegistration.cxx, it should work. You do need to add myclass.cpp to CMakeLists.txt like so:

add_executable(GPURegistration GPURegistration.cxx myclass.cpp)

I don’t understand by ‘#include-ing myclass.h from GPURegistration.cxx’. The myclass is not defined in the GPURegistration.cxx, but in a seperate file myclass.h. I put the myclass.h and GPURegistration.cxx in the same folder. The folder contains:

–GPURegistrationProject
–bin
GPURegistration.cxx
myclass.h
myclass.cpp

However, the ‘#include <myclass.h>’ would show the bug ‘cannot open include file “myclass.h”: not such file or directory’.

#include <myclass.h> only looks for includes in “system” directories. To also look in current directory, you need #include "myclass.h" (quotes, not angle brackets).