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

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

How to make it work?

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 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?

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?

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. A number of your questions will be answered by working through that, including its examples.

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

I commented the line above: 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 .