Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork888
find package: optimize#6354
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:dev
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
SineStriker commentedApr 22, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
编写 localpackage=find_package("cmake::QWindowKit", {presets= {QWindowKit_DIR="C:/qwindowkit/build/install/lib/cmake/QWindowKit",CMAKE_PREFIX_PATH="C:/Qt/5.15.2/mingw81_64/lib/cmake/Qt5" },force=true,configs= {search_mode="config",link_libraries= {"QWindowKit::Core" } } })print("Package:",package) 执行命令 因为有一堆命令行参数前缀,这个地方接下去我不太清楚怎么处理了,可能需要你把 TODO 里的内容给处理下,另外,之前 ninja 里面的 includedirs 可能是这样包含一堆 buildCMakeFiles/main.dir/main.cpp.obj:CXX_COMPILER__main_unscanned_DebugC$:/Users/truef/Documents/GitHub/xmake-learning/extract-cmake/main.cpp||cmake_object_order_depends_target_mainDEFINES= -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -DQWK_CORE_STATICFLAGS= -flagsINCLUDES= -I"C:/xmake-learning/extract-cmake/test space" -isystem C:/qwindowkit/build/install/include/QWindowKit -isystem C:/Qt/5.15.2/mingw81_64/include -isystem C:/Qt/5.15.2/mingw81_64/include/QtCore -isystem C:/Qt/5.15.2/mingw81_64/./mkspecs/win32-g++ -isystem C:/Qt/5.15.2/mingw81_64/include/QtGui -isystem C:/Qt/5.15.2/mingw81_64/include/QtANGLE -isystem C:/Qt/5.15.2/mingw81_64/include/QtWidgets 这些参数前缀可能需要去掉。 |
SineStriker commentedApr 22, 2025
我之后再补充一些测试。 |
Uh oh!
There was an error while loading.Please reload this page.
SineStriker commentedApr 22, 2025
这里我补充了对 MSVC 的处理。 libfiles 和 links 其实是一样的,都是链接的库。这里可能没考虑 mac 的 framework。 |
Issues-translate-bot commentedApr 22, 2025
I'll add some tests later. |
Issues-translate-bot commentedApr 22, 2025
Here I have added the treatment of MSVC. libfiles and links are actually the same, both are linked libraries. The framework of mac may not be considered here. |
| -- find package | ||
| function_find_package(cmake,name,opt) | ||
| localis_windows=os.host()=="windows" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
is_host("windows")
SineStriker commentedApr 23, 2025
现在有个小问题。 我们生成的 CMakeLists.txt 里添加了一个测试目标,然后从 build.ninja 里获取到的 link libraries 有极小概率是跟目标类型有关的,比如 QtCore 会为 Win32 的 exe 目标添加 qt winmain 的库(其实这种就相当于是 xmake 里的 rule,但是 Qt 是用生成表达式把 qtmain 给写进 CMake 的 Qt::Core 的 INTERFACE_LINK_LIBRARIES 属性去了),不过总体来说问题不大,可以在 xmake 里特殊判断然后补上,我在 find_package 的 options 里加了 target_type 的提示字段,可以传 executable、shared、static。 |
SineStriker commentedApr 23, 2025
Linux上不行,用假的 |
Issues-translate-bot commentedApr 23, 2025
Not possible on Linux, using fake |
waruqi commentedApr 23, 2025
怎么个调用法,传递不同的参数?根据不同参数去返回不同状态来绕过呢 |
Issues-translate-bot commentedApr 23, 2025
How to pass different parameters in a call? Return to different states according to different parameters to bypass |
SineStriker commentedApr 23, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
使用假的 ninja 的时候,CMake 检查编译器输出的 CMakeCXXCompiler.cmake 里面的信息是不全的,包括连接器路径,编译器字长什么的都是空的,这些会影响后面 find_package 的流程。比如 GNUInstallDirs 里就需要用 CMAKE_SIZEOF_VOID_P,这个是空的,就炸了。 细节点说,CMake 检查的时候会调用 |
Issues-translate-bot commentedApr 23, 2025
When using fake ninja, CMake checks that the information in CMakeCXXCompiler.cmake output by the compiler is incomplete, including the connector path, the compiler word length and other empty, which will affect the subsequent find_package process. For example, in GNUIinstallDirs, you need to use CMAKE_SIZEOF_VOID_P, which is empty and will explode. |
waruqi commentedApr 23, 2025
那非 win 下,还是之前的搞法,切到 make/makefile 上去,不走 ninja |
Issues-translate-bot commentedApr 23, 2025
That's not win, but the previous method is to cut to make/makefile and not leave ninja |
SineStriker commentedApr 23, 2025
win 下我觉得也不能这样了。现在因为这个,linux 会找不到 GNUInstallDirs,虽然 windows 没这个问题,但是说不准会有什么暗病,因为那些变量就是缺了。 |
Issues-translate-bot commentedApr 23, 2025
I don't think this is the case after win. Now because of this, Linux will not be able to find GNUIinstallDirs. Although Windows does not have this problem, it is not certain that there will be any hidden problems, because those variables are missing. |
waruqi commentedApr 23, 2025
l
那就没办法了,要么继续去硬解的vcproj |
Issues-translate-bot commentedApr 23, 2025
l
Then there is nothing to do, either continue to solve the problem of vcproj |
waruqi commentedApr 23, 2025
或者可以在 win上生成 nmake makefile,然后统一走makefile解析提取 |
Issues-translate-bot commentedApr 23, 2025
Or you can generate nmake makefile on win, and then go to makefile to parse and extract. |
SineStriker commentedApr 25, 2025
这个先放着吧,我过段时间看看 |
Issues-translate-bot commentedApr 25, 2025
Let's leave this for now, I'll take a look in a while |
优化了 CMake find_package 的处理逻辑:
步骤:
目前需要额外处理的逻辑:
.、..ninja_xxx等变量里的命令行选项前缀进行去除,比如把-I/path/to变成/path/to,这个在 TODO 里写了经过这么一系列处理,可以保证拿到的 CMake 库的信息是准确的。