Search code examples
cmake

How do you rename a library filename in CMake?


Some libraries follow different conventions for their filenames, such as the PAM libs -- pam_unix.so, not libpam_unix.so.

How do you override the target library filename in CMake to get something like new_thing.so instead of the default libnew_thing.so?


Solution

  • You can change the Prefix, Output Name and Suffix using the set_target_properties() function and the PREFIX / OUTPUT_NAME / SUFFIX property in the following way:

    Prefix:

        set_target_properties(new_thing PROPERTIES PREFIX "")
    

    Output Name:

        set_target_properties(new_thing PROPERTIES OUTPUT_NAME "better_name")
    

    Suffix:

        set_target_properties(new_thing PROPERTIES SUFFIX ".so.1")