3

I would like to output my library into different folder based on the platform/compiler/architecture/configuration, so it should look like this :

platform(arch)-compiler(version)-configuration

A few examples would be:

win32-vc12.0-debug
win32-vc12.0-release
win64-vc14.0-debug
win64-vc14.0-release

unix-gcc6.1-debug
unix-gcc6.1-release
unix-clang3.8-debug
unix-clang3.8-release

I actually have no idea how to generate those, could anyone guide me ? Thank you

Alex
  • 55
  • 1
  • 4

1 Answers1

3

One way would be to set the bin directories for the project:

math(EXPR platform_bits "${CMAKE_SIZEOF_VOID_P} * 8")
set(platform_dir ${CMAKE_SYSTEM_NAME}${platform_bits}-${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION})

foreach(config DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)

    foreach(var CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${config} CMAKE_LIBRARY_OUTPUT_DIRECTORY_${config} CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config})
        set(${var} "${CMAKE_BINARY_DIR}/${platform_dir}-${config}")
        string(TOLOWER "${${var}}" ${var})
    endforeach()

endforeach()

This won't give you the exact directory names you are looking for, but is a good start. You can look at the CMake variables list for a list of platform specific configuration information. You would then need to apply some logic that will transform the CMake defined values into the specific ones you are looking for.

Community
  • 1
  • 1
Adam Bowen
  • 10,820
  • 6
  • 36
  • 41
  • Wow, this is very great ! I thank you very much, it works very great – Alex Aug 06 '16 at 08:26
  • 1
    I didn't have CMake installed on my laptop, so I hadn't checked the syntax and there were a couple of small mistakes - I've fixed them now! – Adam Bowen Aug 06 '16 at 08:53