0

I'm on OSX and have the following CMakeLists.txt file:

cmake_minimum_required (VERSION 3.12)

project (Test)

add_executable (test main.cpp)

install (TARGETS test DESTINATION bin)

target_include_directories (test PRIVATE Source)

I get the error:

CMake Error at CMakeLists.txt:5 (add_executable): main.cpp not found

when running the makefile from the directory above Source.

I'm new to CMake so I've likely just made a noob mistake but I can't fix the error on my own.

2 Answers2

1

If you want to add just Source/main.cpp then use

add_executable (test Source/main.cpp)

The target_include_directories or include_directories (that is for legacy versions of CMake) are telling to CMake where the .h files are.

Öö Tiib
  • 10,809
  • 25
  • 44
1

target_include_directories is only going to add directories where your build system should search for include files, not source.

You can use add_subdirectory to add directories where source files live.

See documentation on target_include_directories and add_subdirectory.

Bill
  • 1,407
  • 10
  • 18