Discussion:
[CMake] Globally Set Target Properties
Schuchard, Matthew
2011-11-07 15:15:26 UTC
Permalink
I am trying to globally set target properties for an entire configuration.
Specifically, I need to remove the prefix "lib" from all statically linked libraries I build.

I already used CMAKE_STATIC_LIBRARY_PREFIX "" such that all libraries I explicitly link to will not have CMake search for libraries of format "libfoo.a" but rather "foo.a" when I specify "foo."

However, I cannot seem to globally specify that all target libraries which are statically linked which I build have the prefix removed.

I have tried set_target_properties with Unix wildcards to no avail.
I have also tried set_property(GLOBAL PROPERTY PREFIX "") and set_property(TARGET PROPERTY PREFIX "") which were both unsuccessful (or maybe I needed to force the cache, but cache was already an argument in the usage statement providing other functionality so I assumed its normal functionality as an argument was unavailable).
Could not find any help on Google either.

There is also the possibility this is impossible to do with CMake, so if someone can verify that I would also be appreciative.
Michael Wild
2011-11-07 15:22:10 UTC
Permalink
Post by Schuchard, Matthew
I am trying to globally set target properties for an entire configuration.
Specifically, I need to remove the prefix “lib” from all statically
linked libraries I build.
I already used CMAKE_STATIC_LIBRARY_PREFIX “” such that all libraries I
explicitly link to will not have CMake search for libraries of format
“libfoo.a” but rather “foo.a” when I specify “foo.”
However, I cannot seem to globally specify that all target libraries
which are statically linked which I build have the prefix removed.
I have tried set_target_properties with Unix wildcards to no avail.
I have also tried set_property(GLOBAL PROPERTY PREFIX “”) and
set_property(TARGET PROPERTY PREFIX “”) which were both unsuccessful (or
maybe I needed to force the cache, but cache was already an argument in
the usage statement providing other functionality so I assumed its
normal functionality as an argument was unavailable).
Could not find any help on Google either.
There is also the possibility this is impossible to do with CMake, so if
someone can verify that I would also be appreciative.
These properties apply to targets *create* by CMake, that's not what you
want. In your case, simply specify the absolute path to the library
file. E.g.

target_link_libraries(bar /usr/lib/foo.a)

If you want to use find_library to find these libraries, have a look at
CMAKE_FIND_LIBRARY_PREFIXES.

HTH

Michael
Schuchard, Matthew
2011-11-07 16:14:51 UTC
Permalink
Thanks for the response.

Actually, that is what I want to do:

"> Specifically, I need to remove the prefix "lib" from all statically
linked libraries I build."
Also, I do not have to specify full paths to libraries I link to because of the CMAKE_STATIC_LIBRARY_PREFIX command I had mentioned in the initial message.
Do you know if is possible to set global properties of targets like I am trying to?

From: Schuchard, Matthew
Sent: Monday, November 07, 2011 11:06 AM
To: Schuchard, Matthew
Subject: Globally Set Target Properties
I am trying to globally set target properties for an entire configuration.
Specifically, I need to remove the prefix "lib" from all statically
linked libraries I build.
I already used CMAKE_STATIC_LIBRARY_PREFIX "" such that all libraries I
explicitly link to will not have CMake search for libraries of format
"libfoo.a" but rather "foo.a" when I specify "foo."
However, I cannot seem to globally specify that all target libraries
which are statically linked which I build have the prefix removed.
I have tried set_target_properties with Unix wildcards to no avail.
I have also tried set_property(GLOBAL PROPERTY PREFIX "") and
set_property(TARGET PROPERTY PREFIX "") which were both unsuccessful (or
maybe I needed to force the cache, but cache was already an argument in
the usage statement providing other functionality so I assumed its
normal functionality as an argument was unavailable).
Could not find any help on Google either.
There is also the possibility this is impossible to do with CMake, so if
someone can verify that I would also be appreciative.
From: Michael Wild themiwi at gmail.com <mailto:cmake%40cmake.org?Subject=Re%3A%20%5BCMake%5D%20Globally%20Set%20Target%20Properties&In-Reply-To=%3C4EB7F7A2.50903%40gmail.com%3E>
Sent: Monday, November 07, 2011 10:56 AM
To: Schuchard, Matthew
Subject: Globally Set Target Properties

These properties apply to targets *create* by CMake, that's not what you
want. In your case, simply specify the absolute path to the library
file. E.g.

target_link_libraries(bar /usr/lib/foo.a)

If you want to use find_library to find these libraries, have a look at
CMAKE_FIND_LIBRARY_PREFIXES.

HTH

Michael
Michael Hertling
2011-11-08 00:21:25 UTC
Permalink
Post by Schuchard, Matthew
Thanks for the response.
"> Specifically, I need to remove the prefix "lib" from all statically
linked libraries I build."
Also, I do not have to specify full paths to libraries I link to because of the CMAKE_STATIC_LIBRARY_PREFIX command I had mentioned in the initial message.
Do you know if is possible to set global properties of targets like I am trying to?
AFAIK, that's not possible, but you might use a tailored version of
ADD_LIBRARY(), e.g. ADD_STATIC_LIBRARY(), that cares about PREFIX:

FUNCTION(ADD_STATIC_LIBARY TARGET)
ADD_LIBRARY(${TARGET} STATIC ${ARGN})
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES PREFIX "")
ENDFUNCTION()

You might even overwrite the ADD_LIBRARY() command itself:

FUNCTION(ADD_LIBRARY)
_ADD_LIBRARY(${ARGN})
IF(ARGV1 STREQUAL "STATIC")
SET_TARGET_PROPERTIES(${ARGV0} PROPERTIES PREFIX "")
ENDIF()
ENDFUNCTION()

If you use the latter, note than one can build a static library without
passing the STATIC flag to ADD_LIBRARY(), refer to BUILD_SHARED_LIBS.
Furthermore, overwriting a CMake built-in function only works once.

'hope that helps.

Regards,

Michael
Post by Schuchard, Matthew
From: Schuchard, Matthew
Sent: Monday, November 07, 2011 11:06 AM
To: Schuchard, Matthew
Subject: Globally Set Target Properties
I am trying to globally set target properties for an entire configuration.
Specifically, I need to remove the prefix "lib" from all statically
linked libraries I build.
I already used CMAKE_STATIC_LIBRARY_PREFIX "" such that all libraries I
explicitly link to will not have CMake search for libraries of format
"libfoo.a" but rather "foo.a" when I specify "foo."
However, I cannot seem to globally specify that all target libraries
which are statically linked which I build have the prefix removed.
I have tried set_target_properties with Unix wildcards to no avail.
I have also tried set_property(GLOBAL PROPERTY PREFIX "") and
set_property(TARGET PROPERTY PREFIX "") which were both unsuccessful (or
maybe I needed to force the cache, but cache was already an argument in
the usage statement providing other functionality so I assumed its
normal functionality as an argument was unavailable).
Could not find any help on Google either.
There is also the possibility this is impossible to do with CMake, so if
someone can verify that I would also be appreciative.
From: Michael Wild themiwi at gmail.com <mailto:cmake%40cmake.org?Subject=Re%3A%20%5BCMake%5D%20Globally%20Set%20Target%20Properties&In-Reply-To=%3C4EB7F7A2.50903%40gmail.com%3E>
Sent: Monday, November 07, 2011 10:56 AM
To: Schuchard, Matthew
Subject: Globally Set Target Properties
These properties apply to targets *create* by CMake, that's not what you
want. In your case, simply specify the absolute path to the library
file. E.g.
target_link_libraries(bar /usr/lib/foo.a)
If you want to use find_library to find these libraries, have a look at
CMAKE_FIND_LIBRARY_PREFIXES.
HTH
Michael
Michael Wild
2011-11-08 05:33:34 UTC
Permalink
Sorry, I misread your message. The following works for me:

--------<8----------
cmake_minimum_required(VERSION 2.8)
project(static)

set(CMAKE_STATIC_LIBRARY_PREFIX)

add_library(a STATIC a.c)
add_library(b STATIC b.c)
-------->8----------


Michael
Post by Schuchard, Matthew
Thanks for the response.
“> Specifically, I need to remove the prefix “lib” from all statically
linked libraries I build.”
Also, I do not have to specify full paths to libraries I link to because
of the CMAKE_STATIC_LIBRARY_PREFIX command I had mentioned in the
initial message.
Do you know if is possible to set global properties of targets like I am trying to?
*From:*Schuchard, Matthew
*Sent:* Monday, November 07, 2011 11:06 AM
*To:* Schuchard, Matthew
*Subject:* Globally Set Target Properties
/I am trying to globally set target properties for an entire
configuration. /
//
/Specifically, I need to remove the prefix “lib” from all statically /
/linked libraries I build. /
//
/ /
//
/I already used CMAKE_STATIC_LIBRARY_PREFIX “” such that all libraries I /
/explicitly link to will not have CMake search for libraries of format /
/“libfoo.a” but rather “foo.a” when I specify “foo.” /
//
/ /
//
/However, I cannot seem to globally specify that all target libraries /
/which are statically linked which I build have the prefix removed. /
//
/ /
//
/I have tried set_target_properties with Unix wildcards to no avail. /
//
/I have also tried set_property(GLOBAL PROPERTY PREFIX “”) and /
/set_property(TARGET PROPERTY PREFIX “”) which were both unsuccessful (or /
/maybe I needed to force the cache, but cache was already an argument in /
/the usage statement providing other functionality so I assumed its /
/normal functionality as an argument was unavailable). /
//
/Could not find any help on Google either. /
//
/ /
//
/There is also the possibility this is impossible to do with CMake, so if /
/someone can verify that I would also be appreciative. /
//
*From:**Michael Wild* themiwi at gmail.com
<mailto:cmake%40cmake.org?Subject=Re%3A%20%5BCMake%5D%20Globally%20Set%20Target%20Properties&In-Reply-To=%3C4EB7F7A2.50903%40gmail.com%3E>
*Sent:* Monday, November 07, 2011 10:56 AM
*To:* Schuchard, Matthew
*Subject:* Globally Set Target Properties
These properties apply to targets *create* by CMake, that's not what you
want. In your case, simply specify the absolute path to the library
file. E.g.
target_link_libraries(bar /usr/lib/foo.a)
If you want to use find_library to find these libraries, have a look at
CMAKE_FIND_LIBRARY_PREFIXES.
HTH
Michael
Schuchard, Matthew
2011-11-08 12:36:53 UTC
Permalink
Thanks, I think I must be doing something wrong elsewhere then, because I follow the same syntax as what you wrote.
However, it is not working for me which means my error must be somewhere else.
I had thought, based on a stack overflow link, that CMAKE_STATIC_LIBRARY_PREFIX was only for linking to libraries, but I see now it is also for linking built libraries.

-----Original Message-----
From: Michael Wild [mailto:***@gmail.com]
Sent: Tuesday, November 08, 2011 12:34 AM
To: Schuchard, Matthew
Cc: ***@cmake.org
Subject: Re: Globally Set Target Properties

Sorry, I misread your message. The following works for me:

--------<8----------
cmake_minimum_required(VERSION 2.8)
project(static)

set(CMAKE_STATIC_LIBRARY_PREFIX)

add_library(a STATIC a.c)
add_library(b STATIC b.c)
-------->8----------


Michael
Post by Schuchard, Matthew
Thanks for the response.
"> Specifically, I need to remove the prefix "lib" from all statically
linked libraries I build."
Also, I do not have to specify full paths to libraries I link to
because of the CMAKE_STATIC_LIBRARY_PREFIX command I had mentioned in
the initial message.
Do you know if is possible to set global properties of targets like I am trying to?
*From:*Schuchard, Matthew
*Sent:* Monday, November 07, 2011 11:06 AM
*To:* Schuchard, Matthew
*Subject:* Globally Set Target Properties
/I am trying to globally set target properties for an entire
configuration. /
//
/Specifically, I need to remove the prefix "lib" from all statically /
/linked libraries I build. /
//
/ /
//
/I already used CMAKE_STATIC_LIBRARY_PREFIX "" such that all libraries
I /
/explicitly link to will not have CMake search for libraries of format /
/"libfoo.a" but rather "foo.a" when I specify "foo." /
//
/ /
//
/However, I cannot seem to globally specify that all target libraries /
/which are statically linked which I build have the prefix removed. /
//
/ /
//
/I have tried set_target_properties with Unix wildcards to no avail. /
//
/I have also tried set_property(GLOBAL PROPERTY PREFIX "") and /
/set_property(TARGET PROPERTY PREFIX "") which were both unsuccessful
(or /
/maybe I needed to force the cache, but cache was already an argument in /
/the usage statement providing other functionality so I assumed its /
/normal functionality as an argument was unavailable). /
//
/Could not find any help on Google either. /
//
/ /
//
/There is also the possibility this is impossible to do with CMake, so if /
/someone can verify that I would also be appreciative. /
//
*From:**Michael Wild* themiwi at gmail.com
<mailto:cmake%40cmake.org?Subject=Re%3A%20%5BCMake%5D%20Globally%20Set
%20Target%20Properties&In-Reply-To=%3C4EB7F7A2.50903%40gmail.com%3E>
*Sent:* Monday, November 07, 2011 10:56 AM
*To:* Schuchard, Matthew
*Subject:* Globally Set Target Properties
These properties apply to targets *create* by CMake, that's not what you
want. In your case, simply specify the absolute path to the library
file. E.g.
target_link_libraries(bar /usr/lib/foo.a)
If you want to use find_library to find these libraries, have a look at
CMAKE_FIND_LIBRARY_PREFIXES.
HTH
Michael
Michael Hertling
2011-11-08 13:38:11 UTC
Permalink
Post by Schuchard, Matthew
Thanks, I think I must be doing something wrong elsewhere then, because I follow the same syntax as what you wrote.
However, it is not working for me which means my error must be somewhere else.
Could you provide a minimal but complete exemplary project in order
to show what does not work and what you would like to see instead?

Regards,

Michael
Post by Schuchard, Matthew
I had thought, based on a stack overflow link, that CMAKE_STATIC_LIBRARY_PREFIX was only for linking to libraries, but I see now it is also for linking built libraries.
-----Original Message-----
Sent: Tuesday, November 08, 2011 12:34 AM
To: Schuchard, Matthew
Subject: Re: Globally Set Target Properties
--------<8----------
cmake_minimum_required(VERSION 2.8)
project(static)
set(CMAKE_STATIC_LIBRARY_PREFIX)
add_library(a STATIC a.c)
add_library(b STATIC b.c)
-------->8----------
Michael
Post by Schuchard, Matthew
Thanks for the response.
"> Specifically, I need to remove the prefix "lib" from all statically
linked libraries I build."
Also, I do not have to specify full paths to libraries I link to
because of the CMAKE_STATIC_LIBRARY_PREFIX command I had mentioned in
the initial message.
Do you know if is possible to set global properties of targets like I am trying to?
*From:*Schuchard, Matthew
*Sent:* Monday, November 07, 2011 11:06 AM
*To:* Schuchard, Matthew
*Subject:* Globally Set Target Properties
/I am trying to globally set target properties for an entire
configuration. /
//
/Specifically, I need to remove the prefix "lib" from all statically /
/linked libraries I build. /
//
/ /
//
/I already used CMAKE_STATIC_LIBRARY_PREFIX "" such that all libraries
I /
/explicitly link to will not have CMake search for libraries of format /
/"libfoo.a" but rather "foo.a" when I specify "foo." /
//
/ /
//
/However, I cannot seem to globally specify that all target libraries /
/which are statically linked which I build have the prefix removed. /
//
/ /
//
/I have tried set_target_properties with Unix wildcards to no avail. /
//
/I have also tried set_property(GLOBAL PROPERTY PREFIX "") and /
/set_property(TARGET PROPERTY PREFIX "") which were both unsuccessful
(or /
/maybe I needed to force the cache, but cache was already an argument in /
/the usage statement providing other functionality so I assumed its /
/normal functionality as an argument was unavailable). /
//
/Could not find any help on Google either. /
//
/ /
//
/There is also the possibility this is impossible to do with CMake, so if /
/someone can verify that I would also be appreciative. /
//
*From:**Michael Wild* themiwi at gmail.com
<mailto:cmake%40cmake.org?Subject=Re%3A%20%5BCMake%5D%20Globally%20Set
%20Target%20Properties&In-Reply-To=%3C4EB7F7A2.50903%40gmail.com%3E>
*Sent:* Monday, November 07, 2011 10:56 AM
*To:* Schuchard, Matthew
*Subject:* Globally Set Target Properties
These properties apply to targets *create* by CMake, that's not what you
want. In your case, simply specify the absolute path to the library
file. E.g.
target_link_libraries(bar /usr/lib/foo.a)
If you want to use find_library to find these libraries, have a look at
CMAKE_FIND_LIBRARY_PREFIXES.
HTH
Michael
Continue reading on narkive:
Loading...