Warm tip: This article is reproduced from serverfault.com, please click

CMake cannot find source file, but file was not specified in CMakeLists.txt, in TFS build definition

发布于 2020-12-11 15:50:32

I'm porting a large project to linux. I wrote all the CMakeLists.txt files, and everything compiles in my machine.

For whatever reason we still use TFS. The old version, not git with TFS.

I'm working in my own branch, but that branch has no build definition for linux. Before I check in, I want to be sure that everything compiles on the server too. So I need to merge my branch to another one, and submit that shelve set to the build job.

In my machine everything compiles fine. But when I run the build in the server, applying a shelveset to the branch that has a linux build definition, I get an error from the build, saying

CMake Error at 
/myproject/subproject/CMakeLists.txt:165 (add_library):
  Cannot find source file:

/myproject/subproject/IInternalTransactionManager.h

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx

Indeed, that file is not there. Cmake complains about the file not being in the sources directory, which is true, because it is in another directory. But the fact is that I'm not asking for it either! My CMakeFiles.txt file does not include that file. That file is a header which is used in a few files, contains only classes definitions (no implementations), and the directory in which myHeader.h resides has been defined in include_directories. My CMakeLists.txt looks something like this:

set(PROJECT_NAME project)
project(${PROJECT_NAME})
include_directories(
  ../_include
)

set(source_files
  main.cpp
  file_that_includes_myHeader.cpp
)

add_library( ${PROJECT_NAME} STATIC ${source_files} )

and my file structure is something like:

/myproject/subproject/main.cpp
/myproject/subproject/file_that_includes_myHeader.cpp
/myproject/subproject/CMakeLists.txt
/myproject/_include/myHeader.h

So, why should cmake complaining about a missing file, if such file is not included in the CMakeLists.txt file? And why would this happen only the build in TFS? My guess is that there is something wrong when applying the shelvetset and is not related to my code, but I cannot prove it.

I compared the code after the shelveset is applyied, and still in that version the CMakeLists.txt does not mention myHeader.h

Or, there is some rule about including headers in CMakeLists.txt files which I'm not aware of.

Questioner
cauchy
Viewed
0
cauchy 2020-12-17 05:48:31

So, after expending too much debuging I contacted the team in charge of the build process. And as it turns out, the building process in the TFS building definition was definetly NOT what I expected. And of course this was not documented.

Our development is mostly in windows (by far). The linux build has a step before building: a script is launched which parses each Visual Studio project file, gets the included files, and substitutes the source files in the CMakeLists.txt files with the one parsed from VS. Right or wrong, is just the way it is.

I could build the linux build in my local machine because everything was done correctly. The windows build worked too, even though the VS project files sometimes included some files which were not in the source directory but in some header only directory, and somehow that compiled. I guess because the directory was defined in the include directory. But When the CMakeLists.txt files were updated, cmake complained (rightly so) about not finding the files.

So, if anybody experiences similar issues, contact your devops team or whoever is in charge of such things.