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


i on visual studio 2013, cmake 3.5.1, windows 10. trying copy files via cmake below:

file(copy ${images} destination ${cmake_binary_dir}/bin/release) 

is possible replace "release" variable represents configuration like:

file(copy ${images} destination ${cmake_binary_dir}/bin/${variable}) 

i attempted

file(copy ${images} destination ${cmake_binary_dir}/bin/${cmake_build_type}) 

but cmake_build_type empty string when use message print out, attempted

file(copy ${images} destination ${cmake_binary_dir}/bin/$<configuration>) 

but reason file command cannot decipher $<configuration> whereas command

add_custom_target(run command ${cmake_binary_dir}/bin/$<configuration>/test.exe) 

can. right way extract whether visual studio built in release or debug in cmake?

the file command executed during cmake runtime, not during build time (i.e. vs runtime).

this means, generator expressions (e.g. $<config>) can not used, these evaluated during build time.
(hint: long there no explicit reference use of generator expressions particular command in cmake docu, not supported command).

the reason, why ${cmake_build_type} empty, due reason haven't specified on invocation of cmake:

cmake -dcmake_build_type=debug .. 

however, using that, mean build files generated debug configuration. that's not want.

to solve problem: using generator expressions right way, you've figured out use of add_custom_target (or add_custom_command).

you can use custom commands dependencies other "real" targets , can specify post-/pre-build , pre-link commands specific target via add_custom_command.

as docu states command argument of add_custom_command:

arguments command may use generator expressions. references target names in generator expressions imply target-level dependencies, not file-level dependencies. list target names depends option add file-level dependencies.

to copy file after successful build of target:

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>/" ) 

Comments