Skip to content

cmake: Prefer using a well-defined variable

The first time I tried to build the source I defined this variables and I go error about dynamic libs:

This variable is mentioned multiple times in Cmake documentation: https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html / https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html and tutorial

I expect other user to expect the same thing so I did the switch. I inverted the if/set and tried hard to be as back ward compatible:

  • old user that doesn't set ENABLE_STATIC -> warning one time and no warning next time
  • old user that set ENABLE_STATIC -> if compatible to new variable only a warning until it stop to set it or fail if conflicting value
  • new user that expect BUILD_SHARED_LIBS -> just works

Merge request reports