4

I have a project with two CMakeLists.txt files: CMakeLists.txt (default) and CMakeLists.2.txt. So my directory tree looks like project |---- CMakeLists.txt |---- CMakeLists.2.txt |---- main.cpp |---- otherfile.cpp I build like: mkdir build cd build cmake .. make

This uses the default CMakeLists.txt file. How can I specify to build using the CMakeLists.2.txt cmake file?

mkuse
  • 2,250
  • 4
  • 32
  • 61

1 Answers1

3

You cannot change the file name of "CMakeLists.txt".

However, if you need different build configuration for one project, you should use the option in cmake:

option(BUILD_STATIC_LIBS "Build the static library" ON)
option(BUILD_SHARED_LIBS "Build the shared library" ON)
option(BUILD_TESTS "Build test programs" OFF)

And build like this:

cmake -D DBUILD_SHARED_LIBS=ON DBUILD_STATIC_LIBS=OFF DBUILD_TESTS=ON ..
Wei Guo
  • 544
  • 3
  • 15
  • 1
    you mean have separate Cmakefiles and call each with an IF? – mkuse Nov 02 '18 at 06:45
  • No, i mean one CMakeLists.txt and separate the different configuration with the cmake `option` cmd. Use like this: https://stackoverflow.com/questions/22481647/cmake-if-else-with-option. And, of couse, you can also combine the two method: option1, include(CMakeList1.txt); option2, include(CMakeList2.txt) in CMakeLists.txt. – Wei Guo Nov 02 '18 at 06:55
  • I think it should be "cmake -DBUILD_SHARED_LIBS=ON...". – Binh Nguyen Jan 31 '22 at 00:54