1

I'm working on a CMake module which, at some point, invokes try_run(). The file I'm compiling is not really part of the project's sources - it's not used anywhere. It's only ever useful for CMake, to determine some hardware-related setting.

Now, the module is under cmake/Modules/. Where, in my repository's folder hierarchy, should I put the source file?

Note: One option I'm considering is having it in a string within the module and generating a file within CMakeFiles/; but I don't know how to do that.

2
  • Where, in my repository's folder hierarchy, should I put the source file? -- Where it is most convenient? Commented Mar 13, 2019 at 18:16
  • @RobertHarvey: It's the most convenient to not mention any path and let CMake put it where it wants. But that doesn't seem like a reasonable thing to do. Commented Mar 13, 2019 at 18:45

1 Answer 1

1

Regarding the "generate from string" option your are considering: CMakeFiles is internal to CMake and not intended for projects to access manually, but nothing prevents you from using file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/whatever contents) to dump the file somewhere into the binary directory and try_run() it from there.

If you disagree with my first point and want to put the file into CMakeFiles (and you're willing to accept that you'll be relying on apparently stable, but undocumented and not guaranteed CMake behaviour), you can instead write the file into ${CMAKE_BINARY_DIR}/CMakeFiles/whatever.

And if you decide to keep it as an actual file, since as you say it's local to the CMake module, I'd be inclined to put it alongside the module itself: into cmake/Modules.

4
  • Why would I put temporary files in ${CMAKE_CURRENT_BINARY_DIR}? Commented Mar 13, 2019 at 18:45
  • @einpoklum Where else? The file you describe is part of the build process; from my point of view, it's similar to an intermediary artifact like an object file. These go into the binary directory. Commented Mar 13, 2019 at 18:47
  • Intermediary artifacts go under CMakeFiles/. Commented Mar 13, 2019 at 18:48
  • @einpoklum ... which is inside the binary directory. You can create your own "intermediary" directory there. Or if you're fine with relying on stable, but not guaranteed CMake behaviour, put them into ${CMAKE_BINARY_DIRECTORY}/CMakeFiles. Commented Mar 13, 2019 at 18:49

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.