Reputation: 2458
I have a Meson project for a shared library. It uses a CMake subproject, which supplies a static library:
cmake = import('cmake')
sub_prj = cmake_subproject('some_subproject-1.0.0')
sub_dep = sub_prj.dependency('static_sublib')
...
my_lib = library('my_lib', ..., dependencies : sub_dep)
Meson gives me the following error:
ERROR: Can't link non-PIC static library 'cm_gsl' into shared library 'toolbox'. Use the 'pic' option to static_library to build with PIC.
How can I tell the CMake module that the static library must have position independent code?
Upvotes: 1
Views: 2464
Reputation: 21
It should be possible using the following code:
cmake = import('cmake')
cmake_opts = cmake.subproject_options()
cmake_opts.add_cmake_defines({'CMAKE_POSITION_INDEPENDENT_CODE': true})
sub_proj = cmake.subproject('projectname', options: cmake_opts)
my_lib = sub_proj.dependency('lib-target')
The documentation for the configuration options for CMake subprojects can be found here: https://mesonbuild.com/CMake-module.html#configuration-options
Upvotes: 2