8

Is there a way to specify to CMake that I want to use a different file than CMakeLists.txt? I can't seem to find anything.

The problem I'm facing is that I am not allowed to check in changes made to CMakeLists.txt. I also switch branches often.

I want to modify a few build preferences for my development. If I edit CMakeLists.txt, git will not allow me to switch branches.

If I had CMyMakeLists.txt that cmake could use, then it would solve this problem. Is there a way to do this?

Mochan
  • 1,329
  • 1
  • 13
  • 27
  • 3
    Possible duplicate of [Can CMake recognize CMakeLists.txt with another name (CMakeLists\_nightly.txt)?](https://stackoverflow.com/questions/7249225/can-cmake-recognize-cmakelists-txt-with-another-name-cmakelists-nightly-txt) – GoodDeeds Oct 30 '18 at 16:46
  • What do you mean by "I want to modify a few build preferences for my development"? Is it just stuff like the `CMAKE_CXX_STANDARD`, `BUILD_TYPE`, etc? Or more complex changes? Or project structure / project setup changes? – Justin Oct 30 '18 at 16:49
  • Related: https://cmake.org/pipermail/cmake/2007-August/016037.html – GoodDeeds Oct 30 '18 at 16:49
  • @Justin I want to add different flags for debug for different files. I also disable building of certain executable that are already built on the server. Also have a custom testing flow by only running the test I'm working on instead of everything. – Mochan Oct 30 '18 at 17:31
  • If you can add the flags to every file, that's easily configurable on the commandline. For disabling building of certain executables, the generated build system can often be told to only build certain targets (`make only_my_target`). For only running certain tests instead of everything, ctest can be told what tests to run – Justin Oct 30 '18 at 17:44
  • @Justin I can't modify the CMakeLists.txt file. – Mochan Oct 30 '18 at 18:03
  • @Mochan Exactly. Everything I mentioned can be done without touching the CMakeLists.txt – Justin Oct 30 '18 at 18:10
  • 2
    If you're simply modifying a few build preferences for *your* development, why do you need to check it in? Also, what's stopping you from making a local branch and committing the changes? Not sure what "git *will not* allow me to switch branches" means. You make a local branch *first*, *then* you commit the changes. – Chris Oct 30 '18 at 18:18
  • @Justin. It still builds the libraries that depend on program I want to build. I don't want it to do that, just use pre-built ones. Also, can't build with certain with optimizations off flag so that I can debug without lots of optimized out variables. I should be able to run only the test I want but it was not working. We have a slightly different test flow script and I'll try and figure out how to get around it. – Mochan Oct 30 '18 at 20:07
  • @Chris I need the changes to work on my branch. If I don't check it in, git will not let me switch branches without stashing. I can stash and unstash at each change in branch, it adds a lot of overhead of not forgetting to stage the right files and double check that I'm stashing the right files. It's a huge repo with lots of dependencies. – Mochan Oct 30 '18 at 20:11
  • @Mochan Make your branch **first**. Copy and paste your current changes (your CMakeLists.txt file and whatever other files you need) somewhere on your desktop or something and then reset all of your changes. Go to the revision you want to work off of.. Create a branch off of that revision. Your new local branch should be checked out at this point. Copy and paste your changes to this new branch that you've created. Commit your changes... – Chris Oct 30 '18 at 20:16

1 Answers1

1

What I ended up doing was making a sub-directory called mymake and then copying the CMakeLists.txt file on to there. I then changed all the file references by prepending ..\ to them.

I then made the changes to the cmake file that I needed.

I couldn't find a way to get CMake to change directory one step up. It was a pain adding all the files to have ..\ but it solves the problem for me for the time being.

Mochan
  • 1,329
  • 1
  • 13
  • 27