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

windows 环境下,生成 CMakeLists.txt 文件,使用 cmake Ninja tcc 编译时报错 #5448

Open
ZCB1208 opened this issue Aug 8, 2024 · 5 comments

Comments

@ZCB1208
Copy link

ZCB1208 commented Aug 8, 2024

Is your feature request related to a problem? Please describe.

  1. 生成 cmakelist 文件
    xmake project -k cmakelists
    可以正常生成 CMakeList.txt 文件

  2. 然后创建 cmake_build 文件夹,并进入 cmake_build 文件夹:
    cd cmake_build

  3. 使用命令调用 cmake 编译 cmakelist 文件
    cmake .. -G Ninja

  4. 此时报错信息如下:
    ` The C compiler identification is unknown
    CMake Error at CMakeLists.txt:11 (project):
    No CMAKE_C_COMPILER could be found.

The C compiler identification is unknown
CMake Error at CMakeLists.txt:11 (project):
No CMAKE_C_COMPILER could be found.

Configuring incomplete, errors occurred!`

无法进行正常编译生成 ninja 文件

Describe the solution you'd like

set(CMAKE_C_COMPILER "tcc") 这一行,移动至 CMakeLists.txt 最上面,即可解决问题

临时解决,让cmake 通过编译可以采用这种方式

Describe alternatives you've considered

此种解决方案,在下一次生成 cmakelists 文件后又会无法解决,故而需要对 生成 cmakelist 文件的脚本进行修改

在文件 xmake\plugins\project\cmake\cmakelists.lua 文件中增加如下函数

function _add_CMAKE_C_COMPILER_first(cmakelists, target)
	cmakelists:print("# tmp fix tcc use xmake create cmakelists bug ")
	if config.get("toolchain") or target:get("toolchains") then
        local cc = target:tool("cc")
        if cc then
            cc = path.unix(cc)
            cmakelists:print("set(CMAKE_C_COMPILER \"%s\")", cc)
        end
	end
	cmakelists:print("")
end

再在函数 _generate_cmakelists 中增加调用

-- _add CMAKE_C_COMPILER first 
	for _, target in table.orderpairs(project.targets()) do
		_add_CMAKE_C_COMPILER_first(cmakelists, target)
    end

原则上需要对下面生成的set(CMAKE_C_COMPILER "tcc") 内容注释掉,但是实际测试,不注释也没有问题,
暂时用这样不修改原有生成脚本的基础上可以解决问题

Additional context

image

image

image

@Issues-translate-bot
Copy link

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


Title: windows environment, the CMakeLists.txt file is generated, and an error is reported when using cmake Ninja tcc to compile.

@waruqi
Copy link
Member

waruqi commented Aug 8, 2024

xmake 可以直接编译干嘛不用? xmake 可以直接生成 build ninja 干嘛不用?要这么饶两层?

另外,为啥移动至 CMakeLists.txt 最上面就可以,这不应该是 cmake 的 issues 么,为啥要改 xmake。。

@Issues-translate-bot
Copy link

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


Why not use xmake if you can compile it directly? xmake can directly generate build ninja, why not use it? Do you want to spare two layers like this?

In addition, why can it be moved to the top of CMakeLists.txt? Shouldn't this be an issue of cmake? Why should xmake be changed? .

@ZCB1208
Copy link
Author

ZCB1208 commented Aug 8, 2024

是的,确实是绕了两层,非常无奈公司要求就是必须要用使用 cmake ninja ,原因在于国外的团队开发组用了这个组合,所以要求我们也要切换至这样。

虽然极力推荐 使用 xmake ,并阐述了个人的几个看法,无奈人微言轻,只能被迫这样的兼容设计,自己在开发与测试的时候,都是直接使用 xmake 进行的,方便很多。 目前在本地开发以及 cicd 测试的时候,我尽量都是使用 xmake 二 cmake 只是作为一个补充,只是为了符合公司要求而已。

虽然这确实是 cmake 的问题,但是目前我只能这样选择去做兼容,最终选择做出这样的提交,希望能为与我一样处境的开发者提供一些便利,确实找这个问题也是花费了一些时间,并不许想后续如我类似的开发者在遇到这样的问题就放弃l 这么好的工具,希望未来 xmake 能成为开发者的首选。看看我们国人做的多么优秀的工具,对洋人,洋工具能祛魅。

@Issues-translate-bot
Copy link

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


Yes, it is indeed two layers of detours. It is very frustrating that the company requires that cmake ninja must be used. The reason is that the foreign team development team uses this combination, so we are required to switch to this.

Although I strongly recommend the use of xmake and elaborated on several personal opinions, I have no choice but to speak lightly and can only be forced to adopt such a compatible design. When developing and testing, I directly use xmake, which is much more convenient. At present, when developing locally and testing cicd, I try to use xmake and cmake as a supplement, just to meet the company's requirements.

Although this is indeed a problem with cmake, at present I can only choose to make it compatible. I finally chose to make this submission, hoping to provide some convenience to developers in the same situation as me. It did take some time to find this problem. , and I don’t think that developers like me will give up such a good tool when encountering such problems. I hope that xmake will become the first choice of developers in the future. Look at the excellent tools our Chinese make. For foreigners, foreign tools can dispel their charm.

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

No branches or pull requests

3 participants