1

I am using CMake 3.10.2 in Windows.

When I set the variable using CACHE like this

SET(ABAQUS_MAJORVERSION 2016)
SET(ABAQUS_MAJORVERSION ${ABAQUS_MAJORVERSION} CACHE STRING "" )

When I change the ABAQUS_MAJORVERSION variable to 2014 in GUI, this change is not updated in CMake. It keeps generating for 2016 version.

Please help in this regard. Thanks in Advance

Edit1:

This is the project structure:

|CMakeLists.txt
|FindABAQUS.cmake
|-project1
|---source1.cpp
|---CMakeLists.txt which has SET(ABAQUS_MAJORVERSION 2016 CACHE STRING "")  
|-project2
|---source2.cpp
|---CMakeLists.txt which has SET(ABAQUS_MAJORVERSION 2016 CACHE STRING "")

I changed the ABAQUS_MAJORVERSION to 2014 in GUI. The ABAQUS_MAJORVERSION became 2014 in CMakeCache.txt file. But when printed with message(${ABAQUS_MAJORVERSION }) it shows 2016

Solution:

example: SET(MAJORVERSION 2016 CACHE STRING "")

One might need to unset all the Include paths and library paths, to take effect of the new version Include path and library paths.

example: UNSET(INCLUDE_PATH CACHE)
         UNSET(LIBRARY_PATH CACHE)
arun
  • 43
  • 8
  • Local variable hides the cached variable declaration. – Florian Apr 16 '18 at 14:19
  • 1
    I could not understand. Can you please explain in further detail or post a link relevant to this. Thanks – arun Apr 16 '18 at 14:23
  • The linked Q&A does describe it in detail. Your first command sets a local variable `ABAQUS_MAJORVERSION`. You second command sets a cached variable `ABAQUS_MAJORVERSION`. The local variable supersedes the cached variable. If you just wanted to have a default merge both commands into `SET(ABAQUS_MAJORVERSION 2016 CACHE STRING "")`. – Florian Apr 16 '18 at 14:36
  • 1
    @Florian: The referenced question and the answer doesn't describe such hiding. So it is hardly a duplicate. – Tsyvarev Apr 16 '18 at 14:37
  • @Tsyvarev You're right. Sorry, have to add it there. But I'm pretty sure we covered that already in some other Q&A. Do you have a fitting duplicate? – Florian Apr 16 '18 at 14:42
  • @Florian Thanks for the reply! I still face the same problem. I think I am missing something... I used `SET(ABAQUS_MAJORVERSION 2016 CACHE STRING "")` , but still could not change it in GUI – arun Apr 16 '18 at 14:52
  • @Arun Just take a look into the `CMakeCache.txt` file in your binary output directory. If it says "2014" the change was successful. Then add a `variable_watch(ABAQUS_MAJORVERSION)` to your main `CMakeLists.txt` to see if some other code part is overwriting your setting. – Florian Apr 16 '18 at 15:05
  • @Florian: That question - https://stackoverflow.com/questions/7294269/how-do-i-add-a-configuration-variable-to-my-cmake-script - looks more suitable as a duplicate. However, it is strange that it doesn't work for the question's author. @Arun: When you use [approach suggested by the Florian](https://stackoverflow.com/questions/49859504/modifying-cache-variable-in-cmake-is-not-working?noredirect=1#comment86734741_49859504), have you removed the first `set()` command? – Tsyvarev Apr 16 '18 at 17:20
  • Please take a look at the edit1. Thanks – arun Apr 17 '18 at 09:41
  • @Arun I have to admit I've never heard of an `EXTERNAL` cache variable type and I can't find a reference in [CMake's documentation](https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry). Is this an undocumented feature and - if so - what exactly does it do? – Florian May 06 '18 at 19:06
  • @Florian Apologize my misunderstanding. There is no EXTERNAL cache variable in CMake. The dereferencing variables by using UNSET(INCLUDE_PATH CACHE) only updated the newly entered CACHE variables. Without unset, I need to delete the CMakeCache.txt to update. I have corrected the error. – arun May 07 '18 at 10:02
  • @arun You shouldn't edit your question in order to answer it. Instead, please [answer your own question!](https://stackoverflow.blog/2011/07/01/its-ok-to-ask-and-answer-your-own-questions/) – user60561 May 21 '19 at 17:51

0 Answers0