Compiling 32-bit vs 64-bit project using CMake

后端 未结 4 1159
日久生厌
日久生厌 2020-12-24 11:54

How do I specify that CMake should use a different link_directories value depending on whether the target is 32-bit or 64-bit? For example, 32-bit binaries need

4条回答
  •  执笔经年
    2020-12-24 12:38

    I know it's quite old question. But it's still on top when you search with Google "cmake 32 64". I have answer similar to user434507's answer but a little bit more readable in my opinion (I don't like if-else construction in cmake, it looks ugly):

    math(EXPR BITS "8*${CMAKE_SIZEOF_VOID_P}")
    set(BOOST_LIBRARY "/boost/win${BITS}/lib")
    set(CMAKE_EXE_LINKER_FLAGS ${BOOST_LIBRARY})
    

    This will point BOOST_LIBRARY path to /boost/win32/lib or /boost/win64/lib, depending on your architecture.

提交回复
热议问题