--- a/stdlib/CMakeLists.txt +++ b/stdlib/CMakeLists.txt @@ -1,15 +1,26 @@ -add_executable(to_c_array EXCLUDE_FROM_ALL to_c_array.cpp) -configure_target_cc_props(to_c_array) +if(CMAKE_CROSSCOMPILING) + # build time generator, built for the build host + set(HOST_CXX c++ CACHE STRING "C++ compiler for build time tools") + set(TO_C_ARRAY "${CMAKE_CURRENT_BINARY_DIR}/to_c_array.host") + add_custom_command( + COMMAND ${HOST_CXX} -o "${TO_C_ARRAY}" "${CMAKE_CURRENT_SOURCE_DIR}/to_c_array.cpp" + OUTPUT "${TO_C_ARRAY}" + DEPENDS to_c_array.cpp) +else() + add_executable(to_c_array EXCLUDE_FROM_ALL to_c_array.cpp) + configure_target_cc_props(to_c_array) + set(TO_C_ARRAY to_c_array) +endif() add_custom_command( COMMENT "Packing std.jsonnet into std.jsonnet.h" COMMAND - to_c_array + ${TO_C_ARRAY} "${CMAKE_CURRENT_SOURCE_DIR}/std.jsonnet" "${CMAKE_CURRENT_BINARY_DIR}/std.jsonnet.h" OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/std.jsonnet.h" MAIN_DEPENDENCY std.jsonnet - DEPENDS to_c_array) + DEPENDS ${TO_C_ARRAY}) add_library(stdlib_h INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/std.jsonnet.h") target_include_directories(stdlib_h INTERFACE "${CMAKE_CURRENT_BINARY_DIR}")