Meysam
Meysam

Reputation: 18117

CMake: How to link two different versions of a library (32bit and 64bit) based on the system?

I've got two different versions of the same library, one should be linked for 32bit and one for 64bit systems. Currently, I manually modify the CMake file to change the linked library according the system on which I am making. Is it possible to make this an automated task? Can CMake itself decide which lib to use based on the system?

target_link_libraries(${PRODUCT}
                        #lib32
                        lib64)

Upvotes: 1

Views: 610

Answers (1)

Fraser
Fraser

Reputation: 78270

You should be able to use CMAKE_SIZEOF_VOID_P

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  set(MyLib lib64)
else()
  set(MyLib lib32)
endif()
target_link_libraries(${PRODUCT} ${MyLib})

Upvotes: 4

Related Questions