Re: [CMake] How to add a target link library, but only for a custom configuration ?

2011-05-06 Thread Glenn Coombs
On 6 May 2011 01:12, Michael Hertling mhertl...@online.de wrote:


 Yes, absolutely. Although setups with libraries which are needed in some
 configurations only are quite rare, AFAIK, your case shows that this may
 well happen. ;-) Possible - and more appropriate - solutions could be:

 - New target properties, say, EXTRA_LINK_LIBRARIES[_CONFIG] that
  are just added to the respective targets' link command lines.
 - Permission of empty or absent IMPORTED_LOCATION[_CONFIG]
  properties; with these, you might just have said

 ADD_LIBRARY(pthreads SHARED IMPORTED)
 SET_TARGET_PROPERTIES(pthreads PROPERTIES
 IMPORTED_LOCATION_DEBUGPTHREADS ${PTHREADS_LIBRARIES})
 TARGET_LINK_LIBRARIES(myLib pthreads)

 and that's it. Perhaps, this would be worth a feature request.

 Regards,

 Michael


I've filed a report on the bug tracker:

http://public.kitware.com/Bug/view.php?id=12124

so hopefully something may get done about it sometime.

--
Glenn
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] How to add a target link library, but only for a custom configuration ?

2011-05-05 Thread Glenn Coombs
Thanks for that link Michael.  It doesn't please me, but I can confirm that
it does work :-)  It's a nice hack around a deficiency in cmake.  I ended up
using this code:

# First create a dummy library to hang the pthreads
# dependency on via the IMPORTED_LINK_INTERFACE_LIBRARIES property.
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pthreads_dummy.c )
add_library(pthreads_dummy STATIC
${CMAKE_CURRENT_BINARY_DIR}/pthreads_dummy.c)

# make sure the dummy library gets built
add_dependencies(systemc pthreads_dummy)

# export the dummy library so we can include it as an imported target
export(TARGETS pthreads_dummy NAMESPACE imported FILE
importedpthreads_dummy.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/importedpthreads_dummy.cmake)

# use the imported target to add pthread dependency for the DEBUGPTHREADS
config
set_target_properties(importedpthreads_dummy
PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUGPTHREADS ${PTHREADS_LIBRARIES})

target_link_libraries(myLib importedpthreads_dummy)

which is a lot of extra lines when all I really want is something like this:

target_link_libraries(myLib CONFIG DebugPthreads pthreads)

--
Glenn


On 26 April 2011 15:15, Michael Hertling mhertl...@online.de wrote:


 There is a possibility with an intermediate empty static library which
 gets reimported into the project and equipped with the target property
 IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG, but I don't know if that
 approach will please you... ;) Anyway, see [1] for the details.

 Regards,

 Michael

 [1] http://www.mail-archive.com/cmake@cmake.org/msg34680.html

 PS: Empty static libraries aren't allowed on Windows; use

 FILE(WRITE ${CMAKE_BINARY_DIR}/dummy.c )
 ADD_LIBRARY(dummy STATIC dummy.c)

 to satisfy the Visual Studio tools.
 ___
 Powered by www.kitware.com

 Visit other Kitware open-source projects at
 http://www.kitware.com/opensource/opensource.html

 Please keep messages on-topic and check the CMake FAQ at:
 http://www.cmake.org/Wiki/CMake_FAQ

 Follow this link to subscribe/unsubscribe:
 http://www.cmake.org/mailman/listinfo/cmake

___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] How to add a target link library, but only for a custom configuration ?

2011-05-05 Thread Michael Hertling
On 05/05/2011 12:51 PM, Glenn Coombs wrote:
 Thanks for that link Michael.  It doesn't please me, but I can confirm that
 it does work :-)  It's a nice hack around a deficiency in cmake.  I ended up
 using this code:
 
 # First create a dummy library to hang the pthreads
 # dependency on via the IMPORTED_LINK_INTERFACE_LIBRARIES property.
 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pthreads_dummy.c )
 add_library(pthreads_dummy STATIC
 ${CMAKE_CURRENT_BINARY_DIR}/pthreads_dummy.c)
 
 # make sure the dummy library gets built
 add_dependencies(systemc pthreads_dummy)
 
 # export the dummy library so we can include it as an imported target
 export(TARGETS pthreads_dummy NAMESPACE imported FILE
 importedpthreads_dummy.cmake)
 include(${CMAKE_CURRENT_BINARY_DIR}/importedpthreads_dummy.cmake)
 
 # use the imported target to add pthread dependency for the DEBUGPTHREADS
 config
 set_target_properties(importedpthreads_dummy
 PROPERTIES
 IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUGPTHREADS ${PTHREADS_LIBRARIES})
 
 target_link_libraries(myLib importedpthreads_dummy)
 
 which is a lot of extra lines when all I really want is something like this:
 
 target_link_libraries(myLib CONFIG DebugPthreads pthreads)

Yes, absolutely. Although setups with libraries which are needed in some
configurations only are quite rare, AFAIK, your case shows that this may
well happen. ;-) Possible - and more appropriate - solutions could be:

- New target properties, say, EXTRA_LINK_LIBRARIES[_CONFIG] that
  are just added to the respective targets' link command lines.
- Permission of empty or absent IMPORTED_LOCATION[_CONFIG]
  properties; with these, you might just have said

ADD_LIBRARY(pthreads SHARED IMPORTED)
SET_TARGET_PROPERTIES(pthreads PROPERTIES
IMPORTED_LOCATION_DEBUGPTHREADS ${PTHREADS_LIBRARIES})
TARGET_LINK_LIBRARIES(myLib pthreads)

and that's it. Perhaps, this would be worth a feature request.

Regards,

Michael

 On 26 April 2011 15:15, Michael Hertling mhertl...@online.de wrote:
 

 There is a possibility with an intermediate empty static library which
 gets reimported into the project and equipped with the target property
 IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG, but I don't know if that
 approach will please you... ;) Anyway, see [1] for the details.

 Regards,

 Michael

 [1] http://www.mail-archive.com/cmake@cmake.org/msg34680.html

 PS: Empty static libraries aren't allowed on Windows; use

 FILE(WRITE ${CMAKE_BINARY_DIR}/dummy.c )
 ADD_LIBRARY(dummy STATIC dummy.c)

 to satisfy the Visual Studio tools.
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


[CMake] How to add a target link library, but only for a custom configuration ?

2011-04-26 Thread Glenn Coombs
I am using cmake 2.8.2 and I have added a custom configuration to my project
like this:

# Add configuration for debug pthreads builds based on the debug
configuration
#
=
set(CMAKE_C_FLAGS_DEBUGPTHREADS${CMAKE_C_FLAGS_DEBUG}
CACHE STRING Flags used by the compiler during DebugPthreads
builds)
set(CMAKE_CXX_FLAGS_DEBUGPTHREADS${CMAKE_CXX_FLAGS_DEBUG}
CACHE STRING Flags used by the compiler during DebugPthreads
builds)
set(CMAKE_EXE_LINKER_FLAGS_DEBUGPTHREADS
${CMAKE_EXE_LINKER_FLAGS_DEBUG}CACHE STRING Flags used by the
linker for executables during DebugPthreads builds)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUGPTHREADS
${CMAKE_SHARED_LINKER_FLAGS_DEBUG}CACHE STRING Flags used by the linker
for shared libraries during DebugPthreads builds)
set(CMAKE_MODULE_LINKER_FLAGS_DEBUGPTHREADS
${CMAKE_MODULE_LINKER_FLAGS_DEBUG}CACHE STRING Flags used by the linker
for loadable modules during DebugPthreads builds)

# add in the details specific to this configuration
set(CMAKE_C_FLAGS_DEBUGPTHREADS${CMAKE_C_FLAGS_DEBUGPTHREADS}
/DSC_USE_PTHREADS)
set(CMAKE_CXX_FLAGS_DEBUGPTHREADS${CMAKE_CXX_FLAGS_DEBUGPTHREADS}
/DSC_USE_PTHREADS)

mark_as_advanced(
CMAKE_C_FLAGS_DEBUGPTHREADS
CMAKE_CXX_FLAGS_DEBUGPTHREADS
CMAKE_EXE_LINKER_FLAGS_DEBUGPTHREADS
CMAKE_SHARED_LINKER_FLAGS_DEBUGPTHREADS
CMAKE_MODULE_LINKER_FLAGS_DEBUGPTHREADS
)

# This variable is only set for multi-config IDE generators like MSVC
if(CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES DebugPthreads)
list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES}
CACHE STRING Semicolon separated list of supported configuration
types [Debug|Release|MinSizeRel|RelWithDebInfo|DebugPthreads]
FORCE)
endif()

This works and inside Visual Studio 2008 I now get a DebugPthreads
configuration in addition to the normal 4.  As part of my project I build a
library which I now want to add a target dependency for, but only in the
DebugPthreads configuration.  Something like this:

add_library(myLib ${sources})

if (activeConfig is DebugPthreads)
target_link_libraries(myLib ${FULL_PATH_TO_PTHREADS_LIB})
endif()

There doesn't seem to be a way to specify target_link_libraries() for
selected configurations.  I see that it can be specified for all debug or
all release configurations but that isn't what I need.  The Debug and
Release versions of myLib do not depend on the pthreads library but the
DebugPthreads version of myLib does.

Googling for answers has revealed several people with the similar problems
but no clear answers.  I have seen recommendations to use an imported
library and the IMPORTED_LOCATION and IMPORTED_CONFIGURATIONS properties.  I
tried this code:

add_library(my_pthreads STATIC IMPORTED)
set_target_properties(my_pthreads PROPERTIES
IMPORTED_CONFIGURATIONSDebugPthreads
IMPORTED_LOCATION_DEBUGPTHREADS${PTHREADS_LIBRARIES}
)
target_link_libraries(myLib my_pthreads)

but that includes the pthreads library as a target dependency in all
configurations.  If I omit the IMPORTED_CONFIGURATIONS options then I get
the correct result for the DebugPthreads configuration but all other
configurations are trying to find a library called my_pthreads-NOTFOUND.

Is there a way to do what I want in cmake ?

--
Glenn
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] How to add a target link library, but only for a custom configuration ?

2011-04-26 Thread Michael Hertling
On 04/26/2011 03:40 PM, Glenn Coombs wrote:
 I am using cmake 2.8.2 and I have added a custom configuration to my project
 like this:
 
 # Add configuration for debug pthreads builds based on the debug
 configuration
 #
 =
 set(CMAKE_C_FLAGS_DEBUGPTHREADS${CMAKE_C_FLAGS_DEBUG}
 CACHE STRING Flags used by the compiler during DebugPthreads
 builds)
 set(CMAKE_CXX_FLAGS_DEBUGPTHREADS${CMAKE_CXX_FLAGS_DEBUG}
 CACHE STRING Flags used by the compiler during DebugPthreads
 builds)
 set(CMAKE_EXE_LINKER_FLAGS_DEBUGPTHREADS
 ${CMAKE_EXE_LINKER_FLAGS_DEBUG}CACHE STRING Flags used by the
 linker for executables during DebugPthreads builds)
 set(CMAKE_SHARED_LINKER_FLAGS_DEBUGPTHREADS
 ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}CACHE STRING Flags used by the linker
 for shared libraries during DebugPthreads builds)
 set(CMAKE_MODULE_LINKER_FLAGS_DEBUGPTHREADS
 ${CMAKE_MODULE_LINKER_FLAGS_DEBUG}CACHE STRING Flags used by the linker
 for loadable modules during DebugPthreads builds)
 
 # add in the details specific to this configuration
 set(CMAKE_C_FLAGS_DEBUGPTHREADS${CMAKE_C_FLAGS_DEBUGPTHREADS}
 /DSC_USE_PTHREADS)
 set(CMAKE_CXX_FLAGS_DEBUGPTHREADS${CMAKE_CXX_FLAGS_DEBUGPTHREADS}
 /DSC_USE_PTHREADS)
 
 mark_as_advanced(
 CMAKE_C_FLAGS_DEBUGPTHREADS
 CMAKE_CXX_FLAGS_DEBUGPTHREADS
 CMAKE_EXE_LINKER_FLAGS_DEBUGPTHREADS
 CMAKE_SHARED_LINKER_FLAGS_DEBUGPTHREADS
 CMAKE_MODULE_LINKER_FLAGS_DEBUGPTHREADS
 )
 
 # This variable is only set for multi-config IDE generators like MSVC
 if(CMAKE_CONFIGURATION_TYPES)
 list(APPEND CMAKE_CONFIGURATION_TYPES DebugPthreads)
 list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
 set(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES}
 CACHE STRING Semicolon separated list of supported configuration
 types [Debug|Release|MinSizeRel|RelWithDebInfo|DebugPthreads]
 FORCE)
 endif()
 
 This works and inside Visual Studio 2008 I now get a DebugPthreads
 configuration in addition to the normal 4.  As part of my project I build a
 library which I now want to add a target dependency for, but only in the
 DebugPthreads configuration.  Something like this:
 
 add_library(myLib ${sources})
 
 if (activeConfig is DebugPthreads)
 target_link_libraries(myLib ${FULL_PATH_TO_PTHREADS_LIB})
 endif()
 
 There doesn't seem to be a way to specify target_link_libraries() for
 selected configurations.  I see that it can be specified for all debug or
 all release configurations but that isn't what I need.  The Debug and
 Release versions of myLib do not depend on the pthreads library but the
 DebugPthreads version of myLib does.
 
 Googling for answers has revealed several people with the similar problems
 but no clear answers.  I have seen recommendations to use an imported
 library and the IMPORTED_LOCATION and IMPORTED_CONFIGURATIONS properties.  I
 tried this code:
 
 add_library(my_pthreads STATIC IMPORTED)
 set_target_properties(my_pthreads PROPERTIES
 IMPORTED_CONFIGURATIONSDebugPthreads
 IMPORTED_LOCATION_DEBUGPTHREADS${PTHREADS_LIBRARIES}
 )
 target_link_libraries(myLib my_pthreads)
 
 but that includes the pthreads library as a target dependency in all
 configurations.  If I omit the IMPORTED_CONFIGURATIONS options then I get
 the correct result for the DebugPthreads configuration but all other
 configurations are trying to find a library called my_pthreads-NOTFOUND.
 
 Is there a way to do what I want in cmake ?
 
 --
 Glenn

There is a possibility with an intermediate empty static library which
gets reimported into the project and equipped with the target property
IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG, but I don't know if that
approach will please you... ;) Anyway, see [1] for the details.

Regards,

Michael

[1] http://www.mail-archive.com/cmake@cmake.org/msg34680.html

PS: Empty static libraries aren't allowed on Windows; use

FILE(WRITE ${CMAKE_BINARY_DIR}/dummy.c )
ADD_LIBRARY(dummy STATIC dummy.c)

to satisfy the Visual Studio tools.
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake