[CMake] libraryname decoration

Michael Wild themiwi at gmail.com
Fri Jul 30 08:38:07 EDT 2010


On 30. Jul, 2010, at 14:16 , John Drescher wrote:

>> Please do explain. How would this work? What would the API be? And now it suddenly sounds like CMake isn't supposed to do everything automagically anymore. If that is the case, please RTFM and look into the OUTPUT_NAME target property. It offers exactly what you want!
>> 
> 
> Or the prefix variables.
> 
> I have the following in a file called NamingConvention.cmake.
> 
> IF(MSVC)
> 	
> 	IF(MSVC90)
> 		SET(CMAKE_DEBUG_POSTFIX "_d_2008")
> 		SET(CMAKE_RELEASE_POSTFIX "_2008")
> 		SET(CMAKE_RELWITHDEBINFO_POSTFIX "_2008")
> 	ENDIF(MSVC90)
> 	
> 	IF(MSVC80)
> 		SET(CMAKE_DEBUG_POSTFIX "_d_2005")
> 		SET(CMAKE_RELEASE_POSTFIX "_2005")
> 		SET(CMAKE_RELWITHDEBINFO_POSTFIX "_2005")
> 	ENDIF(MSVC80)
> 	
> 	IF(MSVC71)
> 		SET(CMAKE_DEBUG_POSTFIX "_d_2003")
> 		SET(CMAKE_RELEASE_POSTFIX "_2003")
> 		SET(CMAKE_RELWITHDEBINFO_POSTFIX "_2003")
> 	ENDIF(MSVC71)
> 	
> 	IF(MSVC70)
> 		SET(CMAKE_DEBUG_POSTFIX "_d_2002")
> 		SET(CMAKE_RELEASE_POSTFIX "_2002")
> 		SET(CMAKE_RELWITHDEBINFO_POSTFIX "_2002")
> 	ENDIF(MSVC70)
> 	
> 	IF(MSVC60)
> 		SET(CMAKE_DEBUG_POSTFIX "_d_vc6")
> 		SET(CMAKE_RELEASE_POSTFIX "_vc6")
> 		SET(CMAKE_RELWITHDEBINFO_POSTFIX "_vc6")
> 	ENDIF(MSVC60)
> 	
> 	#Name 64bit libaraies differenly
> 	IF(CMAKE_SIZEOF_VOID_P MATCHES 8)
> 		SET(CMAKE_DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}_x64")
> 		SET(CMAKE_RELEASE_POSTFIX "${CMAKE_RELEASE_POSTFIX}_x64")
> 		SET(CMAKE_RELWITHDEBINFO_POSTFIX "${CMAKE_RELWITHDEBINFO_POSTFIX}_x64")
> 		
> 		IF(DETECT_64BIT_PORTABILITY)
> 			SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wp64")
> 		ENDIF(DETECT_64BIT_PORTABILITY)
> 	ENDIF(CMAKE_SIZEOF_VOID_P MATCHES 8)
> 		
> ENDIF(MSVC)
> 
> To activate the naming convention for any of my projects I just call
> include(CMake\NamingConvention.cmake) in the top of my CMakeLists.txt
> and my libraries all have decorated names that distinguish between
> compiler name and 32/64 bit. If I wanted I could spend 5 minutes and
> add gcc and other defined compilers to this.
> 
> John

Thanks, finally. Olaf, do you see how simple it is? And this code could be shortened by a mile:

if(MSVC90)
  set(comp_suffix _2008)
elseif(MSVC80)
  set(comp_suffix _2005)
elseif(MSVC71)
  set(comp_suffix _2003)
elseif(MSVC70)
  set(comp_suffix _2002)
elseif(MSVC60)
  set(comp_suffix _vc6)
endif()
set(arch_suffix)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  set(arch_suffix _x64)
  # THIS IS SPECIFIC TO JOHN'S PROJECT
  if(DETECT_64BIT_PORTABILITY)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wp64")
  endif()
endif()
set(CMAKE_DEBUG_POSTFIX          _d${comp_suffix}${arch_suffix})
set(CMAKE_RELEASE_POSTFIX          ${comp_suffix}${arch_suffix})
set(CMAKE_RELWITHDEBINFO_POSTFIX   ${comp_suffix}${arch_suffix})
set(CMAKE_MINSIZEREL_POSTFIX       ${comp_suffix}${arch_suffix})

You can extend this to your hearts content...


More information about the CMake mailing list