Skip to content

cmake: Show error instead of invoking cross-compiled mpgen binary #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ include(GNUInstallDirs)
# to avoid "error: Import failed: /mp/proxy.capnp" failures from capnproto.
set_property(GLOBAL PROPERTY MP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")

# Set MP_NO_GENERATE as a global property if cross compiling and
# MPGEN_EXECUTABLE not set and cross compiled executables can not run. This
# should trigger a more readable attempting to run a cross compiled executable.
if(CMAKE_CROSSCOMPILING AND NOT MPGEN_EXECUTABLE)
include(CheckCXXSourceRuns)
check_cxx_source_runs("int main() { return 0; }" EXECUTABLES_CAN_RUN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. While looking for something like this, I stumbled upon try_run which takes CMAKE_CROSSCOMPILING into account, which is why I suggested just testing against the var itself. But it seems check_cxx_source_runs is more sane.

if(NOT EXECUTABLES_CAN_RUN)
set_property(GLOBAL PROPERTY MP_NO_GENERATE TRUE)
endif()
endif()

# Set a convenience variable for subdirectories.
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(MP_STANDALONE TRUE)
Expand Down
27 changes: 21 additions & 6 deletions cmake/TargetCapnpSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,29 @@ function(target_capnp_sources target include_prefix)
endif()

get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
get_property(mp_no_generate GLOBAL PROPERTY MP_NO_GENERATE)
set(generated_headers "")
foreach(capnp_file IN LISTS TCS_UNPARSED_ARGUMENTS)
add_custom_command(
OUTPUT ${capnp_file}.c++ ${capnp_file}.h ${capnp_file}.proxy-client.c++ ${capnp_file}.proxy-types.h ${capnp_file}.proxy-server.c++ ${capnp_file}.proxy-types.c++ ${capnp_file}.proxy.h
COMMAND ${MPGEN_BINARY} ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${mp_include_dir}
DEPENDS ${capnp_file}
VERBATIM
)
set(output_files ${capnp_file}.c++ ${capnp_file}.h ${capnp_file}.proxy-client.c++ ${capnp_file}.proxy-types.h ${capnp_file}.proxy-server.c++ ${capnp_file}.proxy-types.c++ ${capnp_file}.proxy.h)
if (mp_no_generate)
add_custom_command(
OUTPUT ${output_files}
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "ERROR: Cannot run cross-compiled ${MPGEN_BINARY} code generator on this system."
COMMAND ${CMAKE_COMMAND} -E echo "Please specify path to a native mpgen tool with MPGEN_EXECUTABLE option."
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E false
VERBATIM
)
else()
add_custom_command(
OUTPUT ${output_files}
COMMAND ${MPGEN_BINARY} ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${mp_include_dir}
DEPENDS ${capnp_file}
VERBATIM
)
endif()

target_sources(${target} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.c++
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-client.c++
Expand Down