OK weirdly, tested again, this also works and is a little more simplified (although more confusing, since now we're intermixing non-cache and cache variables with the same name; behavior is not exactly clear, or well-defined.
if( BUILD_VERSION ) set( BUILD_VERSION ${BUILD_VERSION} ) unset( BUILD_VERSION CACHE ) else() set( BUILD_VERSION 7.1.1.2 ) endif() On Mon, Apr 10, 2017 at 1:32 PM, Robert Dailey <rcdailey.li...@gmail.com> wrote: > Actually this seems to work: > > if( BUILD_VERSION ) > > set( version_override ${BUILD_VERSION} ) > unset( BUILD_VERSION CACHE ) > set( BUILD_VERSION ${version_override} ) > unset( version_override ) > > else() > > set( BUILD_VERSION 7.1.1.2 ) > > endif() > > It's a bit messy but gets the job done, and doesn't require > configure_file(). Maybe there is a way to clean this up even more? > > I noticed that unset( BUILD_VERSION CACHE ) actually unsets non-cache > versions of a variable too, so I had to use the temporary variable to > transfer the value. > > On Mon, Apr 10, 2017 at 1:15 PM, Robert Dailey <rcdailey.li...@gmail.com> > wrote: >> Sorry you're right, this isn't working because -D creates a cache >> entry for the variable, which breaks it. >> >> So maybe more ideas on the configure_file() solution would be ideal... >> unsetting the cache variable might work as well, I have to toy around >> with this. >> >> On Mon, Apr 10, 2017 at 12:48 PM, Bruce Stephens >> <bruce.r.steph...@gmail.com> wrote: >>> On Mon, Apr 10, 2017 at 5:04 PM, Robert Dailey <rcdailey.li...@gmail.com> >>> wrote: >>>> Actually I think your idea does work. Why do you think it won't? I'm >>>> using it right now and so far it seems OK. >>> >>> I assumed (without testing, admittedly) is that it would fail if >>> someone used -D to set the value, >>> then changed some CMakeLists.txt file, then executed the build command >>> again. I'd expect that >>> to rerun cmake to update the build files and I'd fear that you'd then >>> get BUILD_VERSION from >>> the CMakeLists.txt file rather than the value explicitly set. >>> >>> However, I haven't tried it, and maybe it works fine (with the >>> generators you care about) even without >>> caching? -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake