diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e97ea13..7613242e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,14 @@ endif() set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules") +if(CMAKE_CROSSCOMPILING) + set(not_crosscompiling OFF) +else() + set(not_crosscompiling ON) +endif() + +option(BUILD_IDLCXX "Build IDL preprocessor" ${not_crosscompiling}) + # Make it easy to enable MSVC, Clang's/gcc's analyzers set(ANALYZER "" CACHE STRING "Analyzer to enable on the build.") if(ANALYZER) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index fb5d89fb..f9a079fd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -11,6 +11,8 @@ # set(CMAKE_INSTALL_EXAMPLESDIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/examples") +include("${CMAKE_SOURCE_DIR}/src/idlcxx/Generate.cmake") + install( FILES helloworld/publisher.cpp helloworld/subscriber.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index abf9ac74..71fba519 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,5 +9,7 @@ # # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # -add_subdirectory(idlcxx) +if (BUILD_IDLCXX) + add_subdirectory(idlcxx) +endif() add_subdirectory(ddscxx) diff --git a/src/idlcxx/Generate.cmake b/src/idlcxx/Generate.cmake index e64b22ec..35652b28 100644 --- a/src/idlcxx/Generate.cmake +++ b/src/idlcxx/Generate.cmake @@ -15,6 +15,28 @@ function(IDLCXX_GENERATE) cmake_parse_arguments( IDLCXX "" "${one_value_keywords}" "${multi_value_keywords}" "" ${ARGN}) + if (CMAKE_CROSSCOMPILING) + find_program(_idlc_executable idlc NO_CMAKE_FIND_ROOT_PATH REQUIRED) + find_library(_idlcxx_shared_lib cycloneddsidlcxx NO_CMAKE_FIND_ROOT_PATH REQUIRED) + + if (_idlc_executable) + set(_idlc_depends "") + else() + message(FATAL_ERROR "Cannot find idlc executable") + endif() + + if (_idlcxx_shared_lib) + set(_idlcxx_depends "") + else() + message(FATAL_ERROR "Cannot find idlcxx shared library") + endif() + else() + set(_idlc_executable CycloneDDS::idlc) + set(_idlc_depends CycloneDDS::idlc) + set(_idlcxx_shared_lib "$") + set(_idlcxx_depends CycloneDDS-CXX::idlcxx) + endif() + if(NOT IDLCXX_TARGET AND NOT IDLCXX_FILES) # assume deprecated invocation: TARGET FILE [FILE..] list(GET IDLCXX_UNPARSED_ARGUMENTS 0 IDLCXX_TARGET) @@ -55,9 +77,9 @@ function(IDLCXX_GENERATE) list(APPEND _headers "${_header}") add_custom_command( OUTPUT "${_header}" - COMMAND CycloneDDS::idlc - ARGS -l $ ${IDLCXX_ARGS} ${_file} - DEPENDS ${_files} CycloneDDS::idlc CycloneDDS-CXX::idlcxx) + COMMAND ${_idlc_executable} + ARGS -l ${_idlcxx_shared_lib} ${IDLCXX_ARGS} ${_file} + DEPENDS ${_files} ${_idlc_depends} ${_idlcxx_depends}) endforeach() add_custom_target("${_target}_generate" DEPENDS ${_headers})