How to get current configuration (Release / Debug) in CMake for Visual Studio

I am on Visual Studio 2013, CMake 3.5.1, Windows 10. I am trying to copy some files through CMake, as shown below:

file(COPY ${IMAGES} DESTINATION ${CMAKE_BINARY_DIR}/bin/Release)

Is it possible to replace "Release" with a variable that represents a configuration such as:

file(COPY ${IMAGES} DESTINATION ${CMAKE_BINARY_DIR}/bin/${Variable})

I tried

file(COPY ${IMAGES} DESTINATION ${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})

but CMAKE_BUILD_TYPE is an empty string, when I use a message to print it, I also tried

file(COPY ${IMAGES} DESTINATION ${CMAKE_BINARY_DIR}/bin/$<CONFIGURATION>)

but for some reason, the file command cannot decrypt $<CONFIGURATION>, whereas the command is kind of

add_custom_target(run COMMAND ${CMAKE_BINARY_DIR}/bin/$<CONFIGURATION>/Test.exe)

can. What is the correct way to extract Visual Studio currently in Release or Debug in CMake?

+4
source share
1

file CMake, (.. VS.).

, (, $<CONFIG>) , .
(: , CMake, ).

, ${CMAKE_BUILD_TYPE} , , , , CMake:

cmake -DCMAKE_BUILD_TYPE=Debug ..

, Debug. , .

: - , add_custom_target ( add_custom_command).

"" , post-pre-build pre-link add_custom_command.

COMMAND add_custom_command:

COMMAND . , . DEPENDS .

:

add_custom_command(TARGET myTarget POST_BUILD
                   COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${IMAGE1}" "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/"
                   COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${IMAGE2}" "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/"
)
+4

Source: https://habr.com/ru/post/1653380/


All Articles