What is CMakeCache.txt and why it overrides my variables

前端 未结 2 1528
温柔的废话
温柔的废话 2021-02-12 15:49

As I am using cmake after editing CMakeLists.txt some variables wouldn\'t be loaded. If I had something defined with CACHE STRING it wouldn\'t let me to change it without forcin

2条回答
  •  情歌与酒
    2021-02-12 16:03

    Motivating example

    This is basically what https://stackoverflow.com/a/42160304/895245 mentions, but with a more explicit example to make it easier to understand.

    Consider this use case:

    git clone project
    cd project
    # Options ddfined with "option(" in CMakeLists.txt.
    cmake -DOPT1=ON -DOPT2=OFF -DOPT3=ON .
    make
    # Create bugs (edit code).
    make
    

    Then, a few days later, a new directory is added to the project.

    This means CMakeLists.txt was changed with a new add_subdirectory, and so we have to run cmake again to update our make files.

    If we didn't have CMakeCache.txt, we would have to remember and type all options again:

    git pull
    cmake -DOPT1=ON -DOPT2=OFF -DOPT3=ON .
    make
    

    But because of the cache, we can do just:

    cmake .
    make
    

提交回复
热议问题