0

I have a cmake project and I want to do the following :

set_directory_property(DIRECTORY glfw BUILD_SHARED_LIBS ON)
add_subdirectory(glfw)

I want to force the BUILD_SHARED_LIBS to be ON, but only in the scope of the 'glfw' sub directory. Without touching the glfw cmake files.

Is it possible ?

There is no set_directory_property, only a get_directory_property :-(

Thanks

CDZ
  • 813
  • 1
  • 11
  • 27
  • 1
    There is command [set_directory_properties](https://cmake.org/cmake/help/v3.7/command/set_directory_properties.html) – Tsyvarev Feb 01 '18 at 09:09
  • Possible duplicate of [Passing variables down to subdirectory only](https://stackoverflow.com/questions/30985215/passing-variables-down-to-subdirectory-only) – Florian Feb 01 '18 at 09:10

2 Answers2

2

The BUILD_SHARED_LIBS is a variable not a directory property. And the VARIABLES directory property is read-only.

So in your case you just do:

set(BUILD_SHARED_LIBS ON)
add_subdirectory(glfw)
unset(BUILD_SHARED_LIBS)
Florian
  • 39,996
  • 9
  • 133
  • 149
  • Thanks but it does not work. It seems cmake still interpret BUILD_SHARED_LIBS at OFF ! – CDZ Feb 01 '18 at 10:02
0

I found a solution, I had to use the following :

set(BUILD_SHARED_LIBS ON CACHE "" INTERNAL FORCE)
add_subdirectory(glfw)
set(BUILD_SHARED_LIBS OFF CACHE "" INTERNAL FORCE)

Thanks for your help !

CDZ
  • 813
  • 1
  • 11
  • 27