Skip to content
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

Embed camera definition files for Yuneec camera #479

Merged
merged 9 commits into from
Aug 7, 2018
Merged
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
[submodule "json11"]
path = plugins/mission/third_party/json11
url = https://github.com/dronecore/json11
[submodule "third_party/cpp_rsc"]
path = third_party/cpp_rsc
url = https://github.com/orex/cpp_rsc.git
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ include(cmake/curl.cmake)
include(cmake/tinyxml2.cmake)
include(cmake/zlib.cmake)

if(NOT MSVC)
include(third_party/cpp_rsc/cmake/modules/cpp_resource.cmake)
if(NOT ANDROID AND NOT IOS)
# If not cross-compiling, we can build cpp_rsc.
add_subdirectory(third_party/cpp_rsc/src)
else()
# For cross-compilation, re-use the binary from default.
set_property(GLOBAL PROPERTY CPPRSC_CMD ${CMAKE_CURRENT_BINARY_DIR}/../default/third_party/cpp_rsc/src/cpp_rsc)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't get where that is used :/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. And add_resource and link_resource_file come from cpp_rsc as well.

endif()
endif()

if(BUILD_TESTS AND (IOS OR ANDROID))
message(STATUS "Building for iOS or Android: forcing BUILD_TESTS to FALSE...")
set(BUILD_TESTS OFF)
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,36 @@ all: default
default:
$(call cmake-build)

ios: ios_curl
ios: ios_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=iOS.cmake \
-DIOS_PLATFORM:STRING=OS)

ios_simulator: ios_curl
ios_simulator: ios_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=iOS.cmake \
-DIOS_PLATFORM:STRING=SIMULATOR)

android_x86: android_curl
android_x86: android_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_TOOLCHAIN_CMAKE) \
-DANDROID_STL:STRING=c++_static \
-DANDROID_ABI=x86)

android_x86_64: android_curl
android_x86_64: android_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_TOOLCHAIN_CMAKE) \
-DANDROID_STL:STRING=c++_static \
-DANDROID_ABI=x86_64)

android_armeabi-v7a: android_curl
android_armeabi-v7a: android_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_TOOLCHAIN_CMAKE) \
-DANDROID_STL:STRING=c++_static \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_PLATFORM=android-16)

android_arm64-v8a: android_curl
android_arm64-v8a: android_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_TOOLCHAIN_CMAKE) \
-DANDROID_STL:STRING=c++_static \
Expand Down
27 changes: 27 additions & 0 deletions cmake/embed_files.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Compilation step for static resources
# Taken from:
# https://beesbuzz.biz/code/4399-Embedding-binary-resources-with-CMake-and-C-11
function(ADD_RESOURCES out_var)
set(result)
foreach(in_f ${ARGN})
set(out_f "${CMAKE_CURRENT_BINARY_DIR}/${in_f}.o")
file(RELATIVE_PATH rel_path_with_file ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${in_f})
get_filename_component(rel_path ${rel_path_with_file} DIRECTORY)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${rel_path})

if (APPLE)
set(binary_options -sectcreate binary)
else()
set(binary_options -b binary)
endif()

add_custom_command(OUTPUT ${out_f}
COMMAND ld -r ${binary_options} -o ${out_f} ${CMAKE_CURRENT_SOURCE_DIR}/${in_f}
DEPENDS ${in_f}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Adding resource ${in_f}"
VERBATIM)
list(APPEND result ${out_f})
endforeach()
set(${out_var} "${result}" PARENT_SCOPE)
endfunction()
15 changes: 14 additions & 1 deletion plugins/camera/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
if(NOT MSVC)
add_resource(camera_definition_files)
link_resource_file(camera_definition_files FILE ${CMAKE_CURRENT_SOURCE_DIR}/camera_definition_files/e90.xml VARIABLE e90xml TEXT)
link_resource_file(camera_definition_files FILE ${CMAKE_CURRENT_SOURCE_DIR}/camera_definition_files/e50.xml VARIABLE e50xml TEXT)
link_resource_file(camera_definition_files FILE ${CMAKE_CURRENT_SOURCE_DIR}/camera_definition_files/cgoet.xml VARIABLE cgoetxml TEXT)

get_property(RSC_CPP_FILE TARGET camera_definition_files PROPERTY _AR_SRC_FILE)
get_property(RSC_H_DIR TARGET camera_definition_files PROPERTY _AR_H_DIR)

include_directories(${RSC_H_DIR})
endif()

add_library(dronecode_sdk_camera ${PLUGIN_LIBRARY_TYPE}
camera.cpp
camera_impl.cpp
camera_definition.cpp
${RSC_CPP_FILE}
)

target_link_libraries(dronecode_sdk_camera
Expand All @@ -28,7 +41,7 @@ install(TARGETS dronecode_sdk_camera
DESTINATION ${dronecode_sdk_install_lib_dir}
)

target_include_directories(dronecode_sdk_camera
target_include_directories(dronecode_sdk_camera
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE
Expand Down
Loading