How can I pass arguments to ranlib using cmake?
Asked Answered
M

2

4

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.

Molloy answered 31/8, 2015 at 20:22 Comment(0)
M
2

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.

Massasoit answered 11/10, 2015 at 16:0 Comment(0)
B
1

For CMake 3.13+, use STATIC_LIBRARY_OPTIONS:

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

For older versions of CMake, use STATIC_LIBRARY_FLAGS:

set_property(
    TARGET myLibrary
    APPEND
    PROPERTY STATIC_LIBRARY_FLAGS "-no_warning_for_no_symbols"
)
Balkanize answered 1/9, 2018 at 3:34 Comment(2)
this did not work for meUndershoot
Since CMake 3.13, there is STATIC_LIBRARY_OPTIONS. I modified my answer to reflect this.Balkanize

© 2022 - 2024 — McMap. All rights reserved.