Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you rename a library filename in CMake?

Tags:

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?

like image 677
CivFan Avatar asked Jun 24 '15 23:06

CivFan


People also ask

What is a .CMake file?

A CMAKE file is a project file created by the open-source, cross-platform tool CMake. It contains source script in the CMake language for the entire program. CMake tool uses programming scripts, known as CMakeLists, to generate build files for a specific environment such as makefiles Unix machine.

What does Target_link_libraries do in CMake?

Specify libraries or flags to use when linking a given target and/or its dependents. Usage requirements from linked library targets will be propagated. Usage requirements of a target's dependencies affect compilation of its own sources.

What is CMakeLists txt?

CMakeLists. txt file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both). When you create a new project, CLion generates CMakeLists. txt file automatically and places it in the project root directory.


2 Answers

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") 
like image 124
tamas.kenez Avatar answered Oct 05 '22 12:10

tamas.kenez


Since this has to do with the filename, you might think to look at install for the answer. (And sure enough, there's a RENAME clause, but that's a red herring.)

Instead, change the target, using the set_target_properties command.

Library targets have the built-in property, PREFIX. The other relevant one is SUFFIX. These two properties get tacked on to the target name to decide the final filename at install.

For the OQ:

# By default, the library filename will be `libnew_thing.so` add_library(new_thing ${NEW_THING_SRCS})  # This changes the filename to `new_thing.so` set_target_properties(new_thing PROPERTIES PREFIX "") 

Let's say you also wanted the filename to have the version:

# This then changes the filename to `new_thing.so.1`, # if the version is set to "1". set_target_properties(new_thing         PROPERTIES PREFIX ""                    SUFFIX ".so.${NEW_THING_VER}"         ) 
like image 23
CivFan Avatar answered Oct 05 '22 14:10

CivFan