简体   繁体   English

CMake 添加不区分大小写的源文件

[英]CMake adding case insensitive source files

I'm trying to build binaries natively in linux for an existing project with CMakeLists.txt's already built.我正在尝试在 linux 中为已经构建了 CMakeLists.txt 的现有项目本地构建二进制文件。 I keep running into issues where the CMakeLists.txt is trying to add a header or source file but cannot.我一直遇到 CMakeLists.txt 试图添加头文件或源文件但不能添加的问题。 The source file exists in the directory its looking in but the cases dont match.源文件存在于其查找的目录中,但案例不匹配。 For example, here is one of the header searches:例如,这是标题搜索之一:

set(Headers
    resource.h
    stdafx.h
    ...
)

I had gotten an error saying fatal error: stdafx.h: No such file or directory , yet the file that was in the directory was StdAfx.h instead of stdafx.h .我收到一条错误消息,提示fatal error: stdafx.h: No such file or directory ,但fatal error: stdafx.h: No such file or directory的文件是StdAfx.h而不是stdafx.h Apparently CMake cannot make the connection that these are the same files.显然 CMake 无法建立这些是相同文件的连接。

My issue is, this project file is 6 gb worth of code, and if I have to go in and change the includes for every single mis-capitalized file, I'm never gonna finish anything.我的问题是,这个项目文件有 6 gb 的代码,如果我必须进入并更改每个错误大写的文件的包含,我永远不会完成任何事情。 Is there a way for me to tell CMake that the file names might have different capitalization?有没有办法告诉 CMake 文件名可能有不同的大小写? Or am I stuck doing everything by hand until it works.或者我一直在手工做所有事情,直到它起作用为止。

EDIT: It looks as though its the Linux file system that is case sensitive, so I'm removing the cmake tag, as it is not an issue with cmake.编辑:它看起来好像是区分大小写的 Linux 文件系统,所以我正在删除 cmake 标记,因为它不是 cmake 的问题。 Im looking for a solution that would allow me to change all the #include <....> lines within the .cpp files to match the existing header filenames instead of changing the .h file names.我正在寻找一种解决方案,可以让我更改 .cpp 文件中的所有#include <....>行以匹配现有的头文件名,而不是更改 .h 文件名。

EDIT: Just for anyone coming to this later, the full error is this:编辑:只是对于任何人来说,稍后,完整的错误是这样的:

[ 1%] Building CXX object Source/UeiSimuDriver/CMakeFiles/UeiSimuDriver_vc15.dir/StdAfx.cpp.o
In file included from /var/tmp/<workspaceHash>/Framework/Source/UeiSimuDriver/StdAfx.cpp:2 
fatal error: stdafx.h: No such file or directory
#include "stdafx.h"
compilation terminated

The issue is not with cmake, but with the filesystem.问题不在于 cmake,而在于文件系统。 The filesystems in linux are generally case sensitive. linux 中的文件系统通常区分大小写。 stdafx.h is not the same file as Stdafx.h. stdafx.h 与 Stdafx.h 不是同一个文件。 If your CMakeLists.txt and source files use wrong case that doesn't match the name of the file, then the project is not compatible with linux and its filesystems.如果您的 CMakeLists.txt 和源文件使用了与文件名不匹配的错误大小写,则该项目与 linux 及其文件系统不兼容。 So, your options are:所以,你的选择是:

  1. Use a case-insensitive filesystem, since that is what the project supports使用不区分大小写的文件系统,因为这是项目支持的
    1. You could try a case-insensitive filesystem on linux, but that is a hacky solution.您可以在 linux 上尝试一个不区分大小写的文件系统,但这是一个笨拙的解决方案。
    2. Use windows.使用窗户。
  2. Fix the project to support case sensitive filesystems by correcting the filenames and their references in CMakeLists.txt and inclusions.通过更正 CMakeLists.txt 和包含中的文件名及其引用来修复项目以支持区分大小写的文件系统。 Note that there may be further problems when executing the program if it has been written with expectation of case-insensitive filesystem.请注意,如果程序是在不区分大小写的文件系统的情况下编写的,则在执行程序时可能会出现更多问题。

I'm never gonna finish anything我永远不会完成任何事情

Simple solution: Change all filenames to lower case, change all references in CMakeLists.txt and inclusions in source to lower case: No need to perform a comparison or try to figure out include roots.简单的解决方案:将所有文件名更改为小写,将 CMakeLists.txt 中的所有引用和源中的包含更改为小写:无需执行比较或尝试找出包含根。 Both can be performed with a short shell script.两者都可以用一个简短的 shell 脚本来执行。 Although technically not correct because the source files have non-regular grammar, regular expression is probably enough to match include directives.虽然技术上不正确,因为源文件具有非常规语法,但正则表达式可能足以匹配包含指令。

You could try to use file method for collecting all the files you need to build, for example:您可以尝试使用file方法来收集您需要构建的所有文件,例如:

file(GLOB SRCS "*.cpp")
file(GLOB HDRS "*.h")

add_executable(${PROJECT_NAME} ${HDRS} ${SRCS})

UPD: By so you can only collect any files no matter what their names are. UPD:这样你就只能收集任何文件,不管它们的名字是什么。 You'd better to change filenames through some script.你最好通过一些脚本来改变文件名。

Changing capitalization manually for the entire project might not be hard if you're using an editor that allows you to find and replace for the entire project.如果您使用的编辑器允许您查找和替换整个项目,则手动更改整个项目的大小写可能并不难。

There are examples like Visual Studio 2017 and Atom .有像Visual Studio 2017Atom这样的例子。

Just try to press ctrl + shift + H.只需尝试按 ctrl + shift + H。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM