Rather than using the command line and the -D
flag to set variables, I've been using set()
inside the CMakeLists.txt for my simple "learner" one-directory project. The advantage is not having to remember and/or copy and paste long directory names every time I call cmake -DVARIABLE_NAME=path/to/infinity/and/beyond ..
My question is what is the functional difference between the two methods, and what are some simple use cases where I might not want to use set
instead of the command line -D
flag?
Related Questions
This answer talks about scope of variables in cmake, and may contain the answer to my question, but it is too convoluted for me to follow: What's the CMake syntax to set and use variables?
This answer provides a use case where the two methods are not the same, but is for some specific variable and library I have no knowledge of so can't relate to: Setting "-D" variables inside CMake
Note: My question does not have a specific context but was inspired by following this pytorch tutorial to setup my first C++ project and use pytorch.