# CMake Error : Cannot find source file -\> No SOURCES given to target

**URL:** https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650
**Category:** Code
**Tags:** os:linux, gen:makefiles, gen:ninja
**Created:** [December 16, 2023, 1:04pm UTC](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650 "2023-12-16T13:04:24Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Raphy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/raphy/32/4087_2.png) [@Raphy](https://discourse.cmake.org/u/Raphy)
#### Post date: [December 16, 2023, 1:04pm UTC](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650/1 "2023-12-16T13:04:24Z")

</div>

With this `CMakeLists.txt` file:

```
cmake_minimum_required(VERSION 3.24)
project(my_application LANGUAGES CXX)

include(FetchContent)
FetchContent_Declare(
  WebKit2
  #URL https://webkitgtk.org/releases/webkitgtk-2.42.3.tar.xz
  GIT_REPOSITORY https://github.com/raphael10-collab/webkitgtkIncludable.git
)
FetchContent_MakeAvailable(webkit2)
add_executable(my_application src/main.cpp)

add_library(webkit2 webkitgtk-2.42.3.tar.xz)
target_link_libraries(webkit2 webkitgtk-2.42.3)

```

I get this error :

```
cmake -B build
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (3.0s)
CMake Error at CMakeLists.txt:37 (add_library):
  Cannot find source file:

    webkitgtk-2.42.3.tar.xz

CMake Error at CMakeLists.txt:37 (add_library):
  No SOURCES given to target: webkit2

```

I’ve noticed that it does not decompress the webkitgtk-2.42.3.tar.gz file :

```
/build/_deps/webkit2-src$ ls -lah
total 31M
drwxrwxr-x 3 raphy raphy 4,0K dic 16 15:39 .
drwxrwxr-x 5 raphy raphy 4,0K dic 16 15:39 ..
drwxrwxr-x 8 raphy raphy 4,0K dic 16 15:39 .git
-rw-rw-r-- 1 raphy raphy 31M dic 16 15:39 webkitgtk-2.42.3.tar.xz

```

My objective is to reproduce the WebKitGTK building phases within a CMakeLists.txt : [BuildingGtk – WebKit](https://trac.webkit.org/wiki/BuildingGtk#BuildingWebKitGTKfromareleasetarball)

How to make it work?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 17, 2023, 9:12pm UTC](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650/2 "2023-12-17T21:12:57Z")

</div>

You’ve commented out the `URL` keyword, so it isn’t downloading the `webkitgtk-2.42.3.tar.xz` file. It is cloning the git repository you specified instead.

But even if you were using `URL`, you don’t get access to the original downloaded file by default. It is not saved in the current source or build directory, it is saved in an internal location. If you want to _not_ extract it and operate on the `tar.xz` file yourself instead (which doesn’t seem to be the case), you can set `DOWNLOAD_NO_EXTRACT` to true. See the help for that keyword for how to find the location of the downloaded file in that case (it’s in the [ExternalProject](https://cmake.org/cmake/help/latest/module/ExternalProject.html) docs, not FetchContent).

The call to `add_library(webkit2 webkitgtk-2.42.3.tar.xz)` also makes no sense. What were you aiming to achieve by adding an archive directly as a source file to a library target?

---

<div class="post-metadata">

### Author: ![Raphy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/raphy/32/4087_2.png) [@Raphy](https://discourse.cmake.org/u/Raphy)
#### Post date: [December 19, 2023, 5:05pm UTC](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650/3 "2023-12-19T17:05:17Z")

</div>

Hi Craig

thank you for your kind patient help

With:

```
include(FetchContent)
FetchContent_Declare(
  WebKit2
  GIT_REPOSITORY https://github.com/raphael10-collab/webkitgtkIncludable.git
)
FetchContent_MakeAvailable(webkit2)
add_executable(webkit2 src/main.cpp)

```

I actually get the source files contained in the git repo:

```
ls -lah build/_deps/webkit2-src/webkitgtk-2.42.3/
total 140K
drwxrwxr-x 5 raphy raphy 4,0K dic 19 18:59 .
drwxrwxr-x 4 raphy raphy 4,0K dic 19 18:59 ..
-rw-rw-r-- 1 raphy raphy 2,0K dic 19 18:59 CMakeLists.txt
drwxrwxr-x 5 raphy raphy 4,0K dic 19 18:59 Documentation
-rw-rw-r-- 1 raphy raphy 115K dic 19 18:59 NEWS
drwxrwxr-x 12 raphy raphy 4,0K dic 19 18:59 Source
drwxrwxr-x 6 raphy raphy 4,0K dic 19 18:59 Tools

```

How to include within this `CMakeLists.txt` file the first two steps outlined in `Building WebKitGTK` :

```
cmake -DPORT=GTK -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja
ninja

```

in order to include the building process of WebKitGTK within this CMakeLists.txt file? Is that feasible?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 19, 2023, 9:50pm UTC](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650/4 "2023-12-19T21:50:30Z")

</div>

If there’s a `CMakeLists.txt` file at the top of the `webkitgtk` sources, you don’t need to explicitly run `cmake` on it. Those sources will get absorbed directly into your main project automatically as part of the call to `FetchContent_MakeAvailable()`. If there’s no `CMakeLists.txt` file at the top of the `webkitgtk` sources, but if there is one at a deeper level that you want to use as the top of its CMake build, you can tell `FetchContent_Declare()` where it is with the `SOURCE_SUBDIR` keyword.

I recommend you take the time to read through the [FetchContent documentation](https://cmake.org/cmake/help/latest/module/FetchContent.html). A number of your questions will be answered by working through that, including its examples.

---

<div class="post-metadata">

### Author: ![Raphy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/raphy/32/4087_2.png) [@Raphy](https://discourse.cmake.org/u/Raphy)
#### Post date: [December 20, 2023, 11:12am UTC](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650/5 "2023-12-20T11:12:09Z")

</div>

Being the `CMakeLists.txt` of the git-cloned webkitgtk in the sub-folder `webkitgtk-2.42.3` :

```
/build/_deps/webkit2-src/webkitgtk-2.42.3$ ls -lah
total 140K
drwxrwxr-x 5 raphy raphy 4,0K dic 20 11:44 .
drwxrwxr-x 4 raphy raphy 4,0K dic 20 11:44 ..
-rw-rw-r-- 1 raphy raphy 2,0K dic 20 11:44 CMakeLists.txt
drwxrwxr-x 5 raphy raphy 4,0K dic 20 11:44 Documentation
-rw-rw-r-- 1 raphy raphy 115K dic 20 11:44 NEWS
drwxrwxr-x 12 raphy raphy 4,0K dic 20 11:44 Source
drwxrwxr-x 6 raphy raphy 4,0K dic 20 11:44 Tools

```

I defined SOURCE\_SUBDIR webkitgtk-2.42.3,  
and specified WebKitCommon as target\_link\_library:

```
include(FetchContent)
FetchContent_Declare(
  WebKit2
  GIT_REPOSITORY https://github.com/raphael10-collab/webkitgtkIncludable.git
  SOURCE_SUBDIR webkitgtk-2.42.3
)
FetchContent_MakeAvailable(webkit2)
add_executable(webkit2 src/main.cpp)
target_link_libraries(WebKitCommon WebKitCommon)

```

But get these two errors: `include could not find requested file: WebKitCommon` and `Unknown CMake command "WEBKIT_FRAMEWORK_DECLARE"`

```
cmake -B build
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The C compiler identification is GNU 12.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
CMake Deprecation Warning at build/_deps/webkit2-src/webkitgtk-2.42.3/CMakeLists.txt:14 (cmake_policy):
  The OLD behavior for policy CMP0116 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances. Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.

CMake Error at build/_deps/webkit2-src/webkitgtk-2.42.3/CMakeLists.txt:21 (include):
  include could not find requested file:

    WebKitCommon

CMake Error at build/_deps/webkit2-src/webkitgtk-2.42.3/Source/bmalloc/CMakeLists.txt:698 (WEBKIT_FRAMEWORK_DECLARE):
  Unknown CMake command "WEBKIT_FRAMEWORK_DECLARE".

-- Configuring incomplete, errors occurred!

```

The CMakeLists.txt of webkitgtk actually looks for including WebKitCommon: [https://github.com/raphael10-collab/webkitgtkIncludable/blob/master/webkitgtk-2.42.3/CMakeLists.txt#L21](https://github.com/raphael10-collab/webkitgtkIncludable/blob/master/webkitgtk-2.42.3/CMakeLists.txt#L21)

I commented the line above: [https://github.com/raphael10-collab/webkitgtkIncludable/blob/master/webkitgtk-2.42.3/CMakeLists.txt#L20C1-L20C1](https://github.com/raphael10-collab/webkitgtkIncludable/blob/master/webkitgtk-2.42.3/CMakeLists.txt#L20C1-L20C1) :

```
#set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Source/cmake")

```

which assumes that webkit2 is the top level project

I tried also with `FetchContent_Populate` :

```
include(FetchContent)
FetchContent_Declare(
  WebKit2
  GIT_REPOSITORY https://github.com/raphael10-collab/webkitgtkIncludable.git
  SOURCE_SUBDIR webkitgtk-2.42.3
)
FetchContent_Populate(webkit2)
#FetchContent_MakeAvailable(webkit2)
add_executable(webkit2 src/main.cpp)

```

but I get no output in `/build/_deps/webkit2-build/` folder :

```
cmake -B build
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (8.4s)
-- Generating done (0.0s)

/build/_deps/webkit2-build$ ls -lah
total 8,0K
drwxrwxr-x 2 raphy raphy 4,0K dic 20 13:14 .
drwxrwxr-x 5 raphy raphy 4,0K dic 20 13:14 .

```

---

<div class="post-metadata">

### Author: ![Rubber\_Telly\_Media](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rubber_telly_media/32/5317_2.png) [@Rubber\_Telly\_Media](https://discourse.cmake.org/u/Rubber_Telly_Media)
#### Post date: [January 27, 2025, 8:06pm UTC](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650/6 "2025-01-27T20:06:10Z")

</div>

Line 6: WebKit2 should be webkit2

---

<div class="post-metadata">

### Author: ![Rubber\_Telly\_Media](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rubber_telly_media/32/5317_2.png) [@Rubber\_Telly\_Media](https://discourse.cmake.org/u/Rubber_Telly_Media)
#### Post date: [January 29, 2025, 3:52pm UTC](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650/7 "2025-01-29T15:52:04Z")

</div>

Oops, other way around

---

<div class="post-metadata">

### Author: ![Rubber\_Telly\_Media](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rubber_telly_media/32/5317_2.png) [@Rubber\_Telly\_Media](https://discourse.cmake.org/u/Rubber_Telly_Media)
#### Post date: [January 29, 2025, 3:53pm UTC](https://discourse.cmake.org/t/cmake-error-cannot-find-source-file-no-sources-given-to-target/9650/8 "2025-01-29T15:53:37Z")

</div>

FetchContent\_MakeAvailable(webkit2) should be FetchContent\_MakeAvailable(WebKit2)
