Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义cmake查找路径时,找不到对应的cmake包 #5102

Closed
monkiq opened this issue May 14, 2024 · 8 comments
Closed

自定义cmake查找路径时,找不到对应的cmake包 #5102

monkiq opened this issue May 14, 2024 · 8 comments
Labels

Comments

@monkiq
Copy link

monkiq commented May 14, 2024

Xmake 版本

v2.9.1+20240511

操作系统版本和架构

Linux b2c613d49b5d 5.4.241-1-tlinux4-0017.8 #1 SMP Fri Mar 15 12:14:37 CST 2024 x86_64 GNU/Linux

描述问题

xmake.lua中添加cmake依赖

add_requires("cmake::absl", {
    system=true,
    configs = {
        moduledirs= "/workspace/cpp/3rd/lib/cmake/absl",
        link_libraries = {
            "absl::base",
            "absl::strings",
            "absl::status",
            "absl::statusor",
            "absl::flat_hash_map"
        }
    }})

执行xmake后,提示

note: the following packages were not found on your system, try again after installing them:
  -> cmake::absl latest

但是在添加了
presets = {absl_DIR = "/workspace/cpp/3rd/lib/cmake/absl"}
xmake可以执行成功,但是链接的时候提示找不到对象,同时用xmake project -k cmakelists生成的cmakelists.txt文件中也没有链接absl的库

# this is the build file for project 
# it is autogenerated by the xmake build system.
# do not edit by hand.

# project
cmake_minimum_required(VERSION 3.15.0)
cmake_policy(SET CMP0091 NEW)
project(hello LANGUAGES CXX)

# target
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
add_executable(hello "")
set_target_properties(hello PROPERTIES OUTPUT_NAME "hello")
set_target_properties(hello PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/linux/x86_64/release")
target_include_directories(hello PRIVATE
    /workspace/cpp/3rd/include
)
target_include_directories(hello SYSTEM PRIVATE
    /workspace/cpp/3rd/include
)
target_compile_options(hello PRIVATE
    $<$<COMPILE_LANGUAGE:C>:-m64>
    $<$<COMPILE_LANGUAGE:CXX>:-m64>
    $<$<COMPILE_LANGUAGE:C>:-DNDEBUG>
    $<$<COMPILE_LANGUAGE:CXX>:-DNDEBUG>
)
set_target_properties(hello PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(hello PRIVATE cxx_std_11)
if(MSVC)
    target_compile_options(hello PRIVATE $<$<CONFIG:Release>:-Ox -fp:fast>)
else()
    target_compile_options(hello PRIVATE -O3)
endif()
if(MSVC)
else()
    target_compile_options(hello PRIVATE -fvisibility=hidden)
endif()
if(MSVC)
    set_property(TARGET hello PROPERTY
        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_link_libraries(hello PRIVATE
    curl
    uuid
    yaml-cpp
    rt
    ssl
    crypto
)
target_link_directories(hello PRIVATE
    /workspace/cpp/3rd/lib
    /usr/lib/x86_64-linux-gnu
)
target_link_options(hello PRIVATE
    -m64
)
target_sources(hello PRIVATE
    hello/src/main.cpp
)

期待的结果

能够正确链接absl库

工程配置

add_rules("mode.debug", "mode.release")

set_languages("cxx11")

add_requires("cmake::absl", {
    system=true,
    configs = {
        moduledirs= "/workspace/cpp/3rd/lib/cmake/absl",
        link_libraries = {
            "absl::base",
            "absl::strings",
            "absl::status",
            "absl::statusor",
            "absl::flat_hash_map"
        }
    }})
add_requires("cmake::OpenSSL", {
    system=true,
    configs = {components = {"Crypto"}}
    })

target("hello")
    set_kind("binary")
    add_files("hello/src/*.cpp")

    add_includedirs("/workspace/cpp/3rd/include")
    add_linkdirs("/workspace/cpp/3rd/lib")

    add_packages("cmake::absl")
    add_packages("cmake::OpenSSL")

absl的cmake配置如下
absl.tar.gz

附加信息和错误日志

xmake执行结果

checking for gcc ... /usr/bin/gcc
checking for unzip ... /usr/bin/unzip
checking for git ... /usr/local/bin/git
checking for gzip ... /usr/bin/gzip
checking for tar ... /usr/bin/tar
finding absl from cmake ..
checking for cmake ... /usr/bin/cmake
finding it from the generated CMakeLists.txt:
cmake_minimum_required(VERSION 3.25.1)
project(find_package)
list(APPEND CMAKE_MODULE_PATH "/workspace/cpp/3rd/lib/cmake/absl")
find_package(absl REQUIRED )
if(absl_FOUND)
add_executable(test_absl test.cpp)
target_include_directories(test_absl PRIVATE absl_INCLUDE_DIR absl_INCLUDE_DIRS ABSL_INCLUDE_DIR ABSL_INCLUDE_DIRS)
target_include_directories(test_absl PRIVATE absl_CXX_INCLUDE_DIRS)
target_link_libraries(test_absl PRIVATE absl::base absl::strings absl::status absl::statusor absl::flat_hash_map)
endif(absl_FOUND)

/usr/bin/cmake /tmp/.xmake271055/240514/_B8CA1E0960DF4E3081E6F60394B39C60.dir
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.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
-- 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
CMake Error at CMakeLists.txt:4 (find_package):
By not providing "Findabsl.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "absl", but
CMake did not find one.

Could not find a package configuration file provided by "absl" with any of
the following names:

abslConfig.cmake
absl-config.cmake

Add the installation prefix of "absl" to CMAKE_PREFIX_PATH or set
"absl_DIR" to a directory containing one of the above files. If "absl"
provides a separate development package or SDK, be sure it has been
installed.

-- Configuring incomplete, errors occurred!
See also "/tmp/.xmake271055/240514/_B8CA1E0960DF4E3081E6F60394B39C60.dir/CMakeFiles/CMakeOutput.log".
checking for cmake::absl ... no
finding OpenSSL from cmake ..
finding it from the generated CMakeLists.txt:
cmake_minimum_required(VERSION 3.25.1)
project(find_package)
find_package(OpenSSL REQUIRED COMPONENTS Crypto)
if(OpenSSL_FOUND)
add_executable(test_OpenSSL test.cpp)
target_include_directories(test_OpenSSL PRIVATE OpenSSL_INCLUDE_DIR OpenSSL_INCLUDE_DIRS OPENSSL_INCLUDE_DIR OPENSSL_INCLUDE_DIRS)
target_include_directories(test_OpenSSL PRIVATE OpenSSL_CXX_INCLUDE_DIRS)
target_link_libraries(test_OpenSSL PRIVATE OpenSSL_LIBRARY OpenSSL_LIBRARIES OpenSSL_LIBS OPENSSL_LIBRARY OPENSSL_LIBRARIES OPENSSL_LIBS)
endif(OpenSSL_FOUND)

/usr/bin/cmake /tmp/.xmake271055/240514/_77EC808472554A208803F3986A0F6430.dir
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.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
-- 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
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "3.0.11") found components: Crypto
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/.xmake271055/240514/_77EC808472554A208803F3986A0F6430.dir
finding includes from /tmp/.xmake271055/240514/_77EC808472554A208803F3986A0F6430.dir/CMakeFiles/test_OpenSSL.dir/flags.make

CMAKE generated file: DO NOT EDIT!

Generated by "Unix Makefiles" Generator, CMake Version 3.25

compile CXX with /usr/bin/c++

CXX_DEFINES =

CXX_INCLUDES =

CXX_FLAGS =

finding links from /tmp/.xmake271055/240514/_77EC808472554A208803F3986A0F6430.dir/CMakeFiles/test_OpenSSL.dir/link.txt
/usr/bin/c++ CMakeFiles/test_OpenSSL.dir/test.cpp.o -o test_OpenSSL /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/x86_64-linux-gnu/libcrypto.so

checking for cmake::OpenSSL ... OpenSSL
note: the following packages were not found on your system, try again after installing them:
-> cmake::absl latest
error: @programdir/core/main.lua:329: @programdir/core/sandbox/modules/import/core/base/task.lua:65: stack traceback:
[C]: in function 'error'
[@programdir/core/base/os.lua:984]:
[...modules/private/action/require/impl/install_packages.lua:754]:
[@programdir/modules/private/action/require/install.lua:85]:
[@programdir/actions/config/main.lua:387]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:275]:
[@programdir/core/base/task.lua:491]: in function 'run'
[@programdir/core/sandbox/modules/import/core/base/task.lua:63]: in function 'run'
[@programdir/actions/build/main.lua:191]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:275]:
[@programdir/core/base/task.lua:491]: in function 'run'
[@programdir/core/main.lua:327]: in function 'cotask'
[@programdir/core/base/scheduler.lua:406]:

stack traceback:
[C]: in function 'error'
@programdir/core/base/os.lua:973: in function 'base/os.raiselevel'
(...tail calls...)
@programdir/core/main.lua:329: in upvalue 'cotask'
@programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>

@monkiq monkiq added the bug label May 14, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: When customizing the cmake search path, the corresponding cmake package cannot be found

@star-hengxing
Copy link
Contributor

这个库很复杂,先试试用 xrepo 上的 abseil

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


This library is very complex. Try using abseil on xrepo first.

@waruqi
Copy link
Member

waruqi commented May 15, 2024

cmake::xxx 包,首先 cmake 本身的跟着 FindXXX 就很不可靠,要各种传参调整。。这块你只能自己调,可以先搞个 cmake 工程,直接去调通参数,再原样传进来。。。另外 xmake 内部目前的实现比较 hack,它需要解析提取获取到的 links 。。

所以,能不用就不要去用,尽可能用 xmake-repo 仓库的包。。如果非要用,自己调下 https://github.com/xmake-io/xmake/blob/master/xmake/modules/package/manager/cmake/find_package.lua

@monkiq
Copy link
Author

monkiq commented May 15, 2024

cmake::xxx 包,首先 cmake 本身的跟着 FindXXX 就很不可靠,要各种传参调整。。这块你只能自己调,可以先搞个 cmake 工程,直接去调通参数,再原样传进来。。。另外 xmake 内部目前的实现比较 hack,它需要解析提取获取到的 links 。。

所以,能不用就不要去用,尽可能用 xmake-repo 仓库的包。。如果非要用,自己调下 https://github.com/xmake-io/xmake/blob/master/xmake/modules/package/manager/cmake/find_package.lua

感谢您的解答,那如果想在xmake项目中集成这个cmake仓库,这个支持components吗,比如说foo::a,foo::b.看了add_requires貌似没找到相关的API呢

@monkiq monkiq closed this as completed May 15, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


cmake::xxx package, first of all, cmake itself is very unreliable with FindXXX, and requires various parameter adjustment. . You can only adjust this yourself. You can first create a cmake project, directly adjust the parameters, and then pass them in as they are. . . In addition, the current internal implementation of xmake is relatively hacky, and it needs to parse and extract the obtained links. .

Therefore, don’t use it if you can’t use it, and use the packages from the xmake-repo warehouse as much as possible. . If you must use it, adjust it yourself https://github.com/xmake-io/xmake/blob/master/xmake/modules/package/manager/cmake/find_package.lua

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


cmake::xxx package, first of all, cmake itself is very unreliable with FindXXX, and requires various parameter adjustment. . You can only adjust this yourself. You can first create a cmake project, directly adjust the parameters, and then pass them in as they are. . . In addition, the current internal implementation of xmake is relatively hacky, and it needs to parse and extract the obtained links. .

Therefore, don’t use it if you can’t use it, and use the packages from the xmake-repo warehouse as much as possible. . If you must use it, adjust it yourself https://github.com/xmake-io/xmake/blob/master/xmake/modules/package/manager/cmake/find_package.lua

Thank you for your answer. If you want to integrate this cmake warehouse in the xmake project, does it support components, such as foo::a, foo::b. After looking at add_requires, it seems that I can't find the relevant API.

@waruqi
Copy link
Member

waruqi commented May 15, 2024

cmake::xxx 包,首先 cmake 本身的跟着 FindXXX 就很不可靠,要各种传参调整。。这块你只能自己调,可以先搞个 cmake 工程,直接去调通参数,再原样传进来。。。另外 xmake 内部目前的实现比较 hack,它需要解析提取获取到的 links 。。
所以,能不用就不要去用,尽可能用 xmake-repo 仓库的包。。如果非要用,自己调下 https://github.com/xmake-io/xmake/blob/master/xmake/modules/package/manager/cmake/find_package.lua

感谢您的解答,那如果想在xmake项目中集成这个cmake仓库,这个支持components吗,比如说foo::a,foo::b.看了add_requires貌似没找到相关的API呢

支持,参考 sdl 那个包,文档不也有么 https://xmake.io/#/manual/package_dependencies?id=add-package-components

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants