CMake错误:找不到请求的文件:WebKitCommon

7fhtutme  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(84)

我编译并安装在Ubuntu 22.04WebKitGTK:https://trac.webkit.org/wiki/BuildingGtk#BuildingWebKitGTKfromareleasetarball
现在我想在 another CmakeLists.txt中对find_packageFetchContent做同样的事情,以便下载并在本地构建它:

cmake_minimum_required(VERSION 3.21)
project(my_application LANGUAGES CXX)

find_package(webkit2 QUIET)
if (NOT webkit2_FOUND)
  message("webkit2 could not be located in CMake module search path. Downloading it,    
and building it locally")
  include(FetchContent)
  FetchContent_Declare(
    WebKit2
    URL https://webkitgtk.org/releases/webkitgtk-2.42.3.tar.xz
  )
  FetchContent_MakeAvailable(webkit2)
endif(NOT webkit2_FOUND)

字符串
但我得到这个错误:

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
webkit2 could not be located in CMake module search path. Downloading it, and building it locally
-- The C compiler identification is GNU 11.4.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 Error at build/_deps/webkit2-src/CMakeLists.txt:21 (include):
  include could not find requested file:

    WebKitCommon

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

-- Configuring incomplete, errors occurred!
See also "build/CMakeFiles/CMakeOutput.log"


/build/_deps文件夹:

build/_deps$ ls -lah
total 20K
drwxrwxr-x 5 raphy raphy 4,0K dic 15 21:18 .
drwxrwxr-x 4 raphy raphy 4,0K dic 15 21:18 ..
drwxrwxr-x 4 raphy raphy 4,0K dic 15 21:18 webkit2-build
drwxrwxr-x 5 raphy raphy 4,0K dic 15 21:18 webkit2-src
drwxrwxr-x 4 raphy raphy 4,0K dic 15 21:18 webkit2-subbuild


/build/_deps/webkit2-src/CMakeLists.txt文件包含的include(WebKitCommon)https://webkitgtk.org/releases/webkitgtk-2.42.3.tar.xz的CmakeLists.txt文件中包含的include(WebKitCommon)相同:
build/_deps/webkit2-src/CMakeLists.txt

cat build/_deps/webkit2-src/CMakeLists.txt 
# -----------------------------------------------------------------------------
# Determine CMake version and build type.
# -----------------------------------------------------------------------------
# NOTE: cmake_minimum_required() and project() *MUST* be the two first commands
# used, see https://cmake.org/cmake/help/v3.3/command/project.html -- the
# latter in particular handles loading a bunch of shared CMake definitions
# and loading the cross-compilation settings from CMAKE_TOOLCHAIN_FILE.

cmake_minimum_required(VERSION 3.16)
project(WebKit)

# Remove this cmake_policy() after upgrading cmake_minimum_required() to 3.20.
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.20")
    cmake_policy(SET CMP0116 OLD)
endif ()

# -----------------------------------------------------------------------------
# Common configuration
#------------------------------------------------------------------------------
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Source/cmake")
include(WebKitCommon)

# -----------------------------------------------------------------------------
# Enable API unit tests and create a target for the test runner
# -----------------------------------------------------------------------------
if (ENABLE_API_TESTS)
    enable_testing()
endif ()

# -----------------------------------------------------------------------------
# Add module directories
# -----------------------------------------------------------------------------
add_subdirectory(Source)

# -----------------------------------------------------------------------------
# Add tools
# -----------------------------------------------------------------------------
if (ENABLE_TOOLS)
    add_subdirectory(Tools)
endif ()

if (DEVELOPER_MODE)
    add_subdirectory(PerformanceTests)
endif ()

# -----------------------------------------------------------------------------
# Print the features list last, for maximum visibility.
# -----------------------------------------------------------------------------
PRINT_WEBKIT_OPTIONS()


webkitgtk-2.42.3/CMakeLists.txt

raphy@raohy:~/webkitgtk-2.42.3$ cat CMakeLists.txt 
# -----------------------------------------------------------------------------
# Determine CMake version and build type.
# -----------------------------------------------------------------------------
# NOTE: cmake_minimum_required() and project() *MUST* be the two first commands
# used, see https://cmake.org/cmake/help/v3.3/command/project.html -- the
# latter in particular handles loading a bunch of shared CMake definitions
# and loading the cross-compilation settings from CMAKE_TOOLCHAIN_FILE.

cmake_minimum_required(VERSION 3.16)
project(WebKit)

# Remove this cmake_policy() after upgrading cmake_minimum_required() to 3.20.
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.20")
    cmake_policy(SET CMP0116 OLD)
endif ()

# -----------------------------------------------------------------------------
# Common configuration
#------------------------------------------------------------------------------
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Source/cmake")
include(WebKitCommon)

# -----------------------------------------------------------------------------
# Enable API unit tests and create a target for the test runner
# -----------------------------------------------------------------------------
if (ENABLE_API_TESTS)
    enable_testing()
endif ()

# -----------------------------------------------------------------------------
# Add module directories
# -----------------------------------------------------------------------------
add_subdirectory(Source)

# -----------------------------------------------------------------------------
# Add tools
# -----------------------------------------------------------------------------
if (ENABLE_TOOLS)
    add_subdirectory(Tools)
endif ()

if (DEVELOPER_MODE)
    add_subdirectory(PerformanceTests)
endif ()

# -----------------------------------------------------------------------------
# Print the features list last, for maximum visibility.
# -----------------------------------------------------------------------------
PRINT_WEBKIT_OPTIONS()


这是build/CMakeFiles/CMakeOutput.loghttps://drive.google.com/file/d/1MBR22aYzs9IdbTZ_eyc02zBPUm41Go6x/view?usp=drive_link
我需要做什么才能正确地将webkitgtk包含在另一个CmakeLists.txt中,以便下载并在本地构建它?

gtlvzcf8

gtlvzcf81#

不幸的是,并不是所有的项目都以允许它们与FetchContent一起使用的方式定义。在这种情况下,webkit 2在其顶级CMakeLists.txt文件中包含以下行:

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

字符串
这一行假设webkit 2是顶层项目。变量${CMAKE_SOURCE_DIR}扩展到顶层目录,当webkit 2通过FetchContent或git子模块被吸收到一个更大的父项目中时,它将不再指向webkit 2项目所期望的目录。在这种情况下,它应该是${CMAKE_CURRENT_SOURCE_DIR},无论webkit 2是否是顶层目录都可以工作。
你可以贡献一个补丁给上游项目,然后等待他们将其合并到一个版本中,或者你可以分叉他们的项目,然后自己将补丁应用到你自己的分支中。你可能会发现在整个webkit 2项目中还有其他类似的问题,所以你可能必须解决其中的一些问题才能得到一个有效的结果。
这是一个相对常见的问题,对于那些从来没有期望被吸收到一个更大的父项目中的项目来说,无论是使用FetchContent还是其他方法,比如git子模块。如果你能做到这一点,在上游修复总是更好的解决方案。
顺便说一下,在您自己的顶级项目的CMakeLists.txt文件中,如果您可以将最低CMake版本提高到3.24,则有一种更简单、更灵活的方式来实现“先尝试find_package(),然后回退到FetchContent”逻辑。请参阅FIND_PACKAGE_ARGS关键字,这带来了CMake 3.24中添加的新的FetchContent/find_package()集成支持。这不会解决您的主要构建问题,我只是顺便提醒您。

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
  FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(webkit2)

相关问题