[CMake] cmake cannot find source file (new to cmake)

Oleksii Vilchanskyi oleksii.vilchanskyi at gmail.com
Thu Dec 20 05:11:38 EST 2018


>     Toplevel
> 
>        |----- CMakeLists.txt
> 
>        |----- src --------|------CMakeLists.txt
> 
>        |                     
> |------common---------------|-------CMakeLists.txt
> 
>        |                      |------dir1-----|                 
>  |------- src1.h
> 
>        |                                          |-----CMakeLists.txt
> 
>        |----bin                                |-----src2.c
> 
>                                                   |-----src3.c

It's quite hard to figure out what's going on here, but I assume src1.h
is under src/common. Please post the output of 'tree' command next time,
if you are on a Unix.

>                 set(src_files src1.h src2.c src3.c)

You don't have to add headers as target dependencies unless you program
in an IDE (just fyi).

>      CMakeLists.txt in common and dir1 are empty.

So, either partially move your CMake scripts into these subdirectories,
or don't do `add_subdirectory()`. For example:

src/CMakeLists.txt:
	add_executable(exec dir1/src1.c dir1/src2.c dir1/src3.c)
	target_include_directories(exec PRIVATE
		"${CMAKE_CURRENT_SOURCE_DIR}/common")

-- 
Alex

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://cmake.org/pipermail/cmake/attachments/20181220/c3677bf8/attachment.sig>


More information about the CMake mailing list