Skip to content

Commit 2a8fee0

Browse files
authored
Merge branch 'hyperion-project:master' into Refactor
2 parents fac9d28 + 4e91bb8 commit 2a8fee0

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed
File renamed without changes.

cmake/HelperMacros.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,14 @@ macro(FIRSTSUBDIR result curdir)
2222
endforeach()
2323
set(${result} ${dirlist})
2424
endmacro()
25+
26+
macro(getTargetImportedLocation result target)
27+
if(TARGET ${target})
28+
foreach(prop IMPORTED_LOCATION IMPORTED_LOCATION_NOCONFIG IMPORTED_LOCATION_DEBUG IMPORTED_LOCATION_RELEASE)
29+
get_target_property (${result} ${target} ${prop})
30+
if(NOT ("${${result}}" STREQUAL "${result}-NOTFOUND"))
31+
break()
32+
endif()
33+
endforeach()
34+
endif()
35+
endmacro()

dependencies/CMakeLists.txt

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ if(ENABLE_DEV_USB_HID OR ENABLE_DEV_FTDI)
3232
endif()
3333

3434
if(NOT USE_SYSTEM_LIBUSB_LIBS)
35+
include(ExternalProject)
3536
ExternalProject_Add(libusb
3637
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/libusb-cmake
3738
BUILD_ALWAYS ON
@@ -43,6 +44,9 @@ if(ENABLE_DEV_USB_HID OR ENABLE_DEV_FTDI)
4344
-DLIBUSB_BUILD_EXAMPLES:BOOL=OFF # Disable build of libusb examples
4445
-DLIBUSB_INSTALL_TARGETS:BOOL=ON # Install libusb targets
4546
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
47+
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
48+
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
49+
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
4650
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
4751
-DCMAKE_STATIC_LIBRARY_PREFIX:STRING=lib
4852
-DCMAKE_WARN_DEPRECATED:BOOL=OFF # Suppress warnings about "Compatibility with CMake < 3.5 will be removed from a future version of CMake"
@@ -101,10 +105,11 @@ if(ENABLE_DEV_FTDI)
101105
# Pass LibUSB include directory and library location to LibFTDI
102106
get_build_interface_include_directory(TARGET usb-1.0 OUTPUT LIBUSB_INCLUDE_DIR)
103107
set(LIBUSB_INCLUDE_DIR ${LIBUSB_INCLUDE_DIR} CACHE INTERNAL "")
104-
get_target_property(LIBUSB_LIBRARIES usb-1.0 IMPORTED_LOCATION)
108+
getTargetImportedLocation(LIBUSB_LIBRARIES usb-1.0)
105109
set(LIBUSB_LIBRARIES ${LIBUSB_LIBRARIES} CACHE INTERNAL "")
106110

107111
find_package(Git REQUIRED)
112+
include(ExternalProject)
108113
ExternalProject_Add(libftdi1
109114
DEPENDS usb-1.0
110115
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/libftdi1
@@ -118,6 +123,8 @@ if(ENABLE_DEV_FTDI)
118123
-DLIBUSB_INCLUDE_DIR:PATH=${LIBUSB_INCLUDE_DIR} # LibUSB include directory
119124
-DLIBUSB_LIBRARIES:PATH=${LIBUSB_LIBRARIES} # LibUSB library location
120125
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
126+
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
127+
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
121128
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
122129
-DCMAKE_STATIC_LIBRARY_PREFIX_C:STRING=lib
123130
-DCMAKE_WARN_DEPRECATED:BOOL=OFF # Suppress warnings about "Compatibility with CMake < 3.5 will be removed from a future version of CMake"
@@ -273,7 +280,7 @@ if(ENABLE_FLATBUF_SERVER OR ENABLE_FLATBUF_CONNECT)
273280
)
274281
elseif(TARGET flatbuffers::flatc)
275282
add_executable(flatc IMPORTED GLOBAL)
276-
get_target_property(FLATC_EXECUTABLE flatbuffers::flatc IMPORTED_LOCATION_RELEASE)
283+
getTargetImportedLocation(FLATC_EXECUTABLE flatbuffers::flatc)
277284
set_target_properties(flatc PROPERTIES IMPORTED_LOCATION ${FLATC_EXECUTABLE})
278285
endif()
279286
endif()
@@ -289,13 +296,15 @@ if(ENABLE_FLATBUF_SERVER OR ENABLE_FLATBUF_CONNECT)
289296
# Define the flatc import option
290297
set(IMPORT_FLATC "" CACHE STRING "Import the Flatbuffers compiler (flatc_export.cmake) from a native build")
291298

299+
if(CMAKE_CROSSCOMPILING)
300+
# Disable Flatbuffers Compiler
301+
set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "Enable the build of the flatbuffers compiler")
302+
endif()
303+
292304
# Add Flatbuffers directory to the build
293305
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/external/flatbuffers")
294306

295307
if(CMAKE_CROSSCOMPILING)
296-
# Disable Flatbuffers Compiler (import or build nativly)
297-
set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "Enable the build of the flatbuffers compiler")
298-
299308
if(IMPORT_FLATC)
300309
# Import the Flatbuffers Compiler from a native build ...
301310
include(${IMPORT_FLATC})
@@ -312,14 +321,12 @@ if(ENABLE_FLATBUF_SERVER OR ENABLE_FLATBUF_CONNECT)
312321
-DFLATBUFFERS_INSTALL:BOOL=OFF
313322
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
314323
-DFLATBUFFERS_BUILD_TESTS:BOOL=${FLATBUFFERS_BUILD_TESTS}
315-
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
316-
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
317324
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
318325
-Wno-dev # We don't want to be warned over unused variables
319326
BUILD_BYPRODUCTS <BINARY_DIR>/flatc${CMAKE_EXECUTABLE_SUFFIX}
320327
)
321328

322-
add_executable(flatc IMPORTED GOBAL)
329+
add_executable(flatc IMPORTED GLOBAL)
323330
ExternalProject_Get_Property(flatc-host BINARY_DIR)
324331
set_target_properties(flatc PROPERTIES
325332
IMPORTED_LOCATION ${BINARY_DIR}/flatc${CMAKE_EXECUTABLE_SUFFIX}
@@ -332,19 +339,24 @@ if(ENABLE_FLATBUF_SERVER OR ENABLE_FLATBUF_CONNECT)
332339
endif()
333340
endif()
334341

335-
if(TARGET flatbuffers::flatbuffers OR TARGET FlatBuffers::FlatBuffers)
342+
if(TARGET flatbuffers::flatbuffers OR TARGET flatbuffers::flatbuffers_shared OR TARGET FlatBuffers::FlatBuffers)
336343
if(NOT TARGET FlatBuffers)
337344
add_library(FlatBuffers INTERFACE IMPORTED GLOBAL)
338345
if(TARGET flatbuffers::flatbuffers)
339346
target_link_libraries(FlatBuffers INTERFACE flatbuffers::flatbuffers)
340347
get_build_interface_include_directory(TARGET flatbuffers::flatbuffers OUTPUT FLATBUFFERS_INCLUDE_DIR)
348+
elseif(TARGET flatbuffers::flatbuffers_shared)
349+
target_link_libraries(FlatBuffers INTERFACE flatbuffers::flatbuffers_shared)
350+
get_build_interface_include_directory(TARGET flatbuffers::flatbuffers_shared OUTPUT FLATBUFFERS_INCLUDE_DIR)
341351
else()
342352
target_link_libraries(FlatBuffers INTERFACE FlatBuffers::FlatBuffers)
343353
get_build_interface_include_directory(TARGET FlatBuffers::FlatBuffers OUTPUT FLATBUFFERS_INCLUDE_DIR)
344354
endif()
355+
else()
356+
get_build_interface_include_directory(TARGET FlatBuffers OUTPUT FLATBUFFERS_INCLUDE_DIR)
345357
endif()
346358

347-
# static flatbuffers version detection from: https://github.com/hyperledger-archives/iroha-ametsuchi/blob/master/cmake/Modules/Findflatbuffers.cmake
359+
# flatbuffers version detection from: https://github.com/hyperledger-archives/iroha-ametsuchi/blob/master/cmake/Modules/Findflatbuffers.cmake
348360
if(FLATBUFFERS_INCLUDE_DIR AND EXISTS "${FLATBUFFERS_INCLUDE_DIR}/flatbuffers/base.h")
349361
file(STRINGS "${FLATBUFFERS_INCLUDE_DIR}/flatbuffers/base.h" flatbuffers_version_str REGEX "#define FLATBUFFERS_VERSION_[A-Z]+ ")
350362
string(REGEX REPLACE ".*#define FLATBUFFERS_VERSION_MAJOR ([0-9]+).*" "\\1" flatbuffers_MAJOR_VERSION "${flatbuffers_version_str}")
@@ -405,7 +417,7 @@ if(ENABLE_PROTOBUF_SERVER)
405417
)
406418
elseif(TARGET protobuf::protoc)
407419
add_executable(protoc IMPORTED GLOBAL)
408-
get_target_property(PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE)
420+
getTargetImportedLocation(PROTOC_EXECUTABLE protobuf::protoc)
409421
set_target_properties(protoc PROPERTIES IMPORTED_LOCATION ${PROTOC_EXECUTABLE})
410422
endif()
411423
endif()
@@ -441,13 +453,15 @@ if(ENABLE_PROTOBUF_SERVER)
441453
# Define the protoc import option
442454
set(IMPORT_PROTOC "" CACHE STRING "Import the Protobuf compiler (protoc_export.cmake) from a native build")
443455

456+
if(CMAKE_CROSSCOMPILING)
457+
# Disable Protobuf Compiler
458+
set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Build protobuf libraries and protoc compiler")
459+
endif()
460+
444461
# Add Protobuf directory to the build
445462
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf")
446463

447464
if(CMAKE_CROSSCOMPILING)
448-
# Disable Protobuf Compiler (import or build nativly)
449-
set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Build protobuf libraries and protoc compiler")
450-
451465
if(IMPORT_PROTOC)
452466
# Import the Protobuf Compiler from a native build ...
453467
include(${IMPORT_FLATC})
@@ -466,8 +480,6 @@ if(ENABLE_PROTOBUF_SERVER)
466480
-Dprotobuf_BUILD_SHARED_LIBS:BOOL=${protobuf_BUILD_SHARED_LIBS}
467481
-Dprotobuf_WITH_ZLIB:BOOL=${protobuf_WITH_ZLIB}
468482
-DABSL_PROPAGATE_CXX_STD:BOOL=${ABSL_PROPAGATE_CXX_STD}
469-
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
470-
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
471483
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
472484
-Wno-dev # We don't want to be warned over unused variables
473485
BUILD_BYPRODUCTS <BINARY_DIR>/protoc${CMAKE_EXECUTABLE_SUFFIX}

0 commit comments

Comments
 (0)