0

I'm trying to have different CMakeLists.txt for different platforms with some stuff pre-configured, such as CMake variables that will control arbitrary parameters during the build. For example: for this platform enable static build and do not build that source directory. I'd like to have a structure similar to this:

root\
  projects\
    win32\CMakeList.txt
    Android\CMakeList.txt
    VAX\CMakeList.txt
  cmake\cmake_scripts.cmake
  src\
    library\

I'm not sure how to configure this "the right way". I've seen some solutions with a script configuring variables and such before opening the CMakeList.txt file, but I feel that adding a 3rd step to build is wrong.

I've tried to add the parent directory with add_subdirectory but cmake complains that root is not a subdirectory of win32, which is true. I've tried to include root\CMakeList.txt from a leaf, but some paths are not right, so I've resorted to set CMAKE_SOURCE_DIR which broke most of cmake scripts.

Seriously, the scripting equivalent is something like

cd ../..
change_working_directory('.')
exec('foo')
Eric
  • 19,525
  • 19
  • 84
  • 147
  • Include leaves from root CMakeLists.txt, instead. Or just write a single CMakeLists.txt and perform all the checks there. – arrowd Feb 14 '18 at 06:29
  • This question looks like a "suggestion" one, which is not suited for Stack Overflow as "primarily opinion base". Any approach listed by you may work. Choose one, try to use it, and ask a **specific question**. My suggestion: If the project's `CMakeLists.txt` is **fully configurable** by itself (that is, you may pass parameter via `-D` option which disables building some library), for every target you may have *preload script* with `set()` commands, and pass it with `-C` option to cmake. – Tsyvarev Feb 14 '18 at 07:53
  • Can you please give an example of what you are doing in those platform specific files? Would the following be a solution: ["Modern way to set compiler flags in cross-platform cmake project"](https://stackoverflow.com/questions/45955272/modern-way-to-set-compiler-flags-in-cross-platform-cmake-project)? – Florian Feb 19 '18 at 20:05

0 Answers0