How can I pass arguments to ranlib using cmake?

2019-07-16 04:24发布

问题:

How can I pass an argument to ranlib when compiling a static library with CMake?

I tried:

set_target_properties(myLibrary STATIC_LIBRARY_FLAGS "--plugin /usr/lib/gcc/x86_64-linux-gnu/4.9/liblto_plugin.so")

and this worked for ar but not for the subsequent ranlib command.

回答1:

Have you tried this?

SET(CMAKE_C_ARCHIVE_FINISH   "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")

On the Mac, this is how I pass the "-no_warning_for_no_symbols" flag to ranlib.

Note: The SET commands don't modify the ranlib command used as part of an installation by running "make install." CMake's installer code does not generate installation scripts that allow for options to be added to ranlib.



回答2:

Adding

set_property(
    TARGET myLibrary
    APPEND
    PROPERTY STATIC_LIBRARY_FLAGS "-no_warning_for_no_symbols"
)

worked for me.