This is a follow-up to Need CMake M Plugin help: Single target, Single source, multiple objects, multiples libraries.
Briefly, I have one source file, and I need to make two object files.
Our original code looks like this:
set(CMAKE_M_COMPILE_OBJECT "LC_ALL=\"${LC_ALL}\" ydb_chset=\"${ydb_chset}\" ydb_icu_version=\"${icu_version}\" <CMAKE_M_COMPILER> -object=<OBJECT>")
Our current strategy involves setting these environment variables separately for two CMake invocations in order to produce two different object files. We don’t want to do that, but rather we would rather have a single CMake invocation.
I wrote what is desired as a macro, but the macro does not get called at the right times if I use it directly.
macro(M_COMPILE)
foreach(source_file ${ARGN})
message("--> " ${source_file})
get_filename_component(output_file ${source_file} NAME_WE)
add_custom_command(
OUTPUT ${output_file}
COMMAND ${CMAKE_M_COMPILER} LC_ALL=\"${LC_ALL}\" ydb_chset=\"M\" <CMAKE_M_COMPILER> -object=${output_file}.o ${M_FLAGS}
COMMAND ${CMAKE_M_COMPILER} LC_ALL=\"${LC_ALL}\" ydb_chset=\"UTF-8\" <CMAKE_M_COMPILER> -object={output_file}_utf8.o ${M_FLAGS}
DEPENDS ${source_file}
)
endforeach()
endmacro()