-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
559 changed files
with
101,800 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
cmake_minimum_required(VERSION 2.6) | ||
project("Pangolin") | ||
set(PANGOLIN_VERSION_MAJOR 0) | ||
set(PANGOLIN_VERSION_MINOR 5) | ||
set(PANGOLIN_VERSION ${PANGOLIN_VERSION_MAJOR}.${PANGOLIN_VERSION_MINOR}) | ||
|
||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/") | ||
|
||
# Platform configuration vars | ||
include(SetPlatformVars) | ||
|
||
SET(CPACK_GENERATOR "DEB") | ||
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Steven Lovegrove") | ||
SET(CPACK_PACKAGE_VERSION_MAJOR ${PANGOLIN_VERSION_MAJOR}) | ||
SET(CPACK_PACKAGE_VERSION_MINOR ${PANGOLIN_VERSION_MINOR}) | ||
SET(CPACK_PACKAGE_VERSION_PATCH "0") | ||
include(CPack) | ||
|
||
option( BUILD_EXAMPLES "Build Examples" ON ) | ||
option( BUILD_TESTS "Build Tests" ON ) | ||
|
||
if(_WIN_) | ||
option( BUILD_SHARED_LIBS "Build Shared Library" OFF) | ||
option( BUILD_EXTERN_GLEW "Automatically download, build and compile GLEW" ON) | ||
option( BUILD_EXTERN_LIBPNG "Automatically download, build and compile libpng" ON) | ||
option( BUILD_EXTERN_LIBJPEG "Automatically download, build and compile libjpeg" ON) | ||
option( MSVC_USE_STATIC_CRT "Use static C Runtime with MSVC, /MT instead of /MD" ON) | ||
|
||
# Make sure there are no erroneous C Runtime flags | ||
list(APPEND FLAG_VARS | ||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO | ||
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO | ||
) | ||
if(MSVC_USE_STATIC_CRT) | ||
foreach(FLAG_VAR ${FLAG_VARS}) | ||
string(REGEX REPLACE "/MD" "/MT" NEW_FLAGS "${${FLAG_VAR}}") | ||
set(${FLAG_VAR} "${NEW_FLAGS}" CACHE STRING "" FORCE) | ||
endforeach() | ||
else() | ||
foreach(FLAG_VAR ${FLAG_VARS}) | ||
string(REGEX REPLACE "/MT" "/MD" NEW_FLAGS "${${FLAG_VAR}}") | ||
set(${FLAG_VAR} "${NEW_FLAGS}" CACHE STRING "" FORCE) | ||
endforeach() | ||
endif() | ||
else() | ||
option( BUILD_SHARED_LIBS "Build Shared Library" ON) | ||
endif() | ||
|
||
if(NOT MSVC) | ||
set( CMAKE_CXX_FLAGS "-std=c++14 -Wall -Wextra ${CMAKE_CXX_FLAGS} -fPIC" ) # modified for python binding (add " -fPIC") | ||
if(_CLANG_) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -fPIC") # modified for python binding (add " -fPIC") | ||
endif() | ||
endif() | ||
|
||
if(ANDROID) | ||
set(ANDROID_PACKAGE_NAME "com.github.stevenlovegrove.pangolin") | ||
include(AndroidUtils) | ||
endif() | ||
|
||
if(ANDROID OR IOS) | ||
set(HAVE_GLES 1) | ||
option(BUILD_FOR_GLES_2 "Build for OpenGL ES 2 instead of ES 1" ON ) | ||
if(BUILD_FOR_GLES_2) | ||
set(HAVE_GLES_2 1) | ||
endif() | ||
endif() | ||
|
||
if(_OSX_) | ||
set(CMAKE_MACOSX_RPATH ON) | ||
endif() | ||
|
||
# Overide with cmake -DCMAKE_BUILD_TYPE=Debug {dir} | ||
if( NOT CMAKE_BUILD_TYPE AND NOT _WIN_ ) | ||
message("Build type not set (defaults to release)") | ||
message("-DCMAKE_BUILD_TYPE=Debug for debug") | ||
set( CMAKE_BUILD_TYPE Release ) | ||
endif() | ||
|
||
string(TOLOWER _${PROJECT_NAME} LIBRARY_NAME) # modified for python binding (add "_" to avoid naming conflict with python library "pangolin") | ||
|
||
# make an uninstall target | ||
configure_file( | ||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" | ||
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" | ||
IMMEDIATE @ONLY | ||
) | ||
|
||
add_custom_target(uninstall | ||
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") | ||
|
||
add_subdirectory("external") | ||
add_subdirectory("src") | ||
add_subdirectory("python") | ||
|
||
if(BUILD_TESTS) | ||
add_subdirectory("test") | ||
endif() | ||
|
||
if(BUILD_EXAMPLES) | ||
set(Pangolin_DIR ${Pangolin_BINARY_DIR}/src) | ||
add_subdirectory(examples) | ||
add_subdirectory(tools) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
if(NOT ANDROID_PACKAGE_NAME) | ||
set(ANDROID_PACKAGE_NAME "com.github.stevenlovegrove.pangolin") | ||
endif() | ||
|
||
if(NOT ANDROID_DEFERRED_ENTRY_SO) | ||
set(ANDROID_DEFERRED_ENTRY_SO "libpangolin.so") | ||
endif() | ||
|
||
# Configure build environment to automatically generate APK's instead of executables. | ||
if(ANDROID AND NOT TARGET apk) | ||
# virtual targets which we'll add apks and push actions to. | ||
add_custom_target( apk ) | ||
add_custom_target( push ) | ||
add_custom_target( run ) | ||
|
||
# Reset output directories to be in binary folder (rather than source) | ||
set(LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_CURRENT_BINARY_DIR}) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}) | ||
|
||
macro( create_android_manifest_xml filename prog_name package_name activity_name) | ||
file( WRITE ${filename} | ||
"<?xml version=\"1.0\" encoding=\"utf-8\"?> | ||
<!-- BEGIN_INCLUDE(manifest) --> | ||
<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" | ||
package=\"${package_name}.${prog_name}\" | ||
android:versionCode=\"1\" | ||
android:versionName=\"1.0\"> | ||
<!-- This is the platform API where NativeActivity was introduced. --> | ||
<uses-sdk android:minSdkVersion=\"14\" /> | ||
<uses-feature android:glEsVersion=\"0x00020000\" /> | ||
<uses-feature android:name=\"android.hardware.camera\" /> | ||
<uses-permission android:name=\"android.permission.CAMERA\"/> | ||
<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/> | ||
<uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\"/> | ||
<!-- This .apk has no Java code itself, so set hasCode to false. --> | ||
<application android:label=\"${activity_name}\" android:hasCode=\"false\"> | ||
<!-- Our activity is the built-in NativeActivity framework class. | ||
This will take care of integrating with our NDK code. --> | ||
<activity android:name=\"android.app.NativeActivity\" | ||
android:label=\"${activity_name}\" | ||
android:screenOrientation=\"landscape\" | ||
android:configChanges=\"orientation|keyboard|keyboardHidden\" | ||
android:theme=\"@android:style/Theme.NoTitleBar.Fullscreen\" | ||
> | ||
<!-- Tell NativeActivity the name of our .so --> | ||
<meta-data android:name=\"android.app.lib_name\" | ||
android:value=\"${prog_name}_start\" /> | ||
<intent-filter> | ||
<action android:name=\"android.intent.action.MAIN\" /> | ||
<category android:name=\"android.intent.category.LAUNCHER\" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> | ||
<!-- END_INCLUDE(manifest) -->" ) | ||
endmacro() | ||
|
||
macro( create_bootstrap_library prog_name package_name) | ||
set(bootstrap_cpp "${CMAKE_CURRENT_BINARY_DIR}/${prog_name}_start.cpp" ) | ||
file( WRITE ${bootstrap_cpp} | ||
"#include <android/native_activity.h> | ||
#include <android/log.h> | ||
#include <dlfcn.h> | ||
#include <errno.h> | ||
#include <stdlib.h> | ||
#include <cstdio> | ||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, \"AndroidUtils.cmake\", __VA_ARGS__)) | ||
#define LIB_PATH \"/data/data/${package_name}.${prog_name}/lib/\" | ||
void * load_lib(const char * l) { | ||
void * handle = dlopen(l, RTLD_NOW | RTLD_GLOBAL); | ||
if (!handle) LOGE( \"dlopen('%s'): %s\", l, strerror(errno) ); | ||
return handle; | ||
} | ||
void ANativeActivity_onCreate(ANativeActivity * app, void * ud, size_t udsize) { | ||
#include \"${prog_name}_shared_load.h\" | ||
// Look for standard entrypoint in user lib | ||
void (*stdentrypoint)(ANativeActivity*, void*, size_t); | ||
*(void **) (&stdentrypoint) = dlsym(load_lib( LIB_PATH \"lib${prog_name}.so\"), \"ANativeActivity_onCreate\"); | ||
if (stdentrypoint) { | ||
(*stdentrypoint)(app, ud, udsize); | ||
}else{ | ||
// Look for deferred load entry point | ||
void (*exdentrypoint)(ANativeActivity*, void*, size_t, const char*); | ||
*(void **) (&exdentrypoint) = dlsym(load_lib( LIB_PATH \"lib${prog_name}.so\"), \"DeferredNativeActivity_onCreate\"); | ||
if (!exdentrypoint) { | ||
// Look in specific shared lib | ||
*(void **) (&exdentrypoint) = dlsym(load_lib( LIB_PATH \"${ANDROID_DEFERRED_ENTRY_SO}\"), \"DeferredNativeActivity_onCreate\"); | ||
} | ||
if(exdentrypoint) { | ||
(*exdentrypoint)(app, ud, udsize, LIB_PATH \"lib${prog_name}.so\" ); | ||
}else{ | ||
LOGE( \"Unable to find compatible entry point\" ); | ||
} | ||
} | ||
}" ) | ||
add_library( "${prog_name}_start" SHARED ${bootstrap_cpp} ) | ||
target_link_libraries( "${prog_name}_start" android log ) | ||
add_dependencies( ${prog_name} "${prog_name}_start" ) | ||
endmacro() | ||
|
||
macro( android_update android_project_name) | ||
# Find which android platforms are available. | ||
execute_process( | ||
COMMAND android list targets -c | ||
OUTPUT_VARIABLE android_target_list | ||
) | ||
|
||
# Pick first platform from this list. | ||
string(REGEX MATCH "^[^\n]+" android_target "${android_target_list}" ) | ||
message(STATUS "Android Target: ${android_target}") | ||
|
||
if( NOT "${android_target}" STREQUAL "" ) | ||
# Generate ant build scripts for making APK | ||
execute_process( | ||
COMMAND android update project --name ${android_project_name} --path . --target ${android_target} --subprojects | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
else() | ||
message( FATAL_ERROR "No Android SDK platforms found. Please install an Android platform SDK. On Linux, run 'android'." ) | ||
endif() | ||
endmacro() | ||
|
||
# Override add_executable to build android .so instead! | ||
macro( add_executable prog_name) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME}) | ||
add_library( ${prog_name} SHARED ${ARGN} ) | ||
|
||
# Add required link libs for android | ||
target_link_libraries(${prog_name} log android ) | ||
|
||
# Create manifest required for APK | ||
create_android_manifest_xml( | ||
"${CMAKE_CURRENT_BINARY_DIR}/AndroidManifest.xml" "${prog_name}" | ||
"${ANDROID_PACKAGE_NAME}" "${prog_name}" | ||
) | ||
|
||
# Create library that will launch this program and load shared libs | ||
create_bootstrap_library( ${prog_name} ${ANDROID_PACKAGE_NAME} ) | ||
|
||
# Generate ant build system for APK | ||
android_update( ${prog_name} ) | ||
|
||
# Target to invoke ant build system for APK | ||
set( APK_FILE "${CMAKE_CURRENT_BINARY_DIR}/bin/${prog_name}-debug.apk" ) | ||
add_custom_command( | ||
OUTPUT ${APK_FILE} | ||
COMMAND ant debug | ||
DEPENDS ${prog_name} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
|
||
# Target to install on device | ||
add_custom_target( ${prog_name}-apk | ||
DEPENDS ${APK_FILE} | ||
) | ||
add_dependencies(apk ${prog_name}-apk) | ||
|
||
# Target to install on device | ||
add_custom_target( ${prog_name}-push | ||
COMMAND adb install -r ${APK_FILE} | ||
DEPENDS ${APK_FILE} | ||
) | ||
add_dependencies(push ${prog_name}-push) | ||
|
||
# install and run on device | ||
add_custom_target( ${prog_name}-run | ||
COMMAND adb shell am start -n ${ANDROID_PACKAGE_NAME}.${prog_name}/android.app.NativeActivity | ||
DEPENDS ${prog_name}-push | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
add_dependencies(run ${prog_name}-run) | ||
|
||
# Flag to package dependent libs | ||
set_property(TARGET ${prog_name} APPEND PROPERTY MAKE_APK 1 ) | ||
|
||
# Clear shared library loading header | ||
file( WRITE "${CMAKE_CURRENT_BINARY_DIR}/${prog_name}_shared_load.h" "") | ||
endmacro() | ||
|
||
macro( package_with_target prog_name lib_path ) | ||
# Mark lib_path as dependent of prog_name | ||
set_property(TARGET ${prog_name} APPEND PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE ${lib_path} ) | ||
|
||
# If prog_name is to be packaged, add file copy command to package .so's. | ||
get_target_property( package_dependent_libs ${prog_name} MAKE_APK ) | ||
if( package_dependent_libs ) | ||
get_filename_component(target_filename ${lib_path} NAME) | ||
file( APPEND ${depend_file} "load_lib(LIB_PATH \"${target_filename}\" );\n") | ||
add_custom_command(TARGET ${prog_name} POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
${lib_path} "${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME}/" | ||
) | ||
endif() | ||
endmacro() | ||
|
||
macro( add_to_depend_libs prog_name depend_file lib_name ) | ||
# Recursively Process dependents of lib_name | ||
get_target_property(TARGET_LIBS ${lib_name} IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE) | ||
if(NOT TARGET_LIBS) | ||
get_target_property(TARGET_LIBS ${lib_name} IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG) | ||
endif() | ||
if(NOT TARGET_LIBS) | ||
get_target_property(TARGET_LIBS ${lib_name} IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG) | ||
endif() | ||
|
||
foreach(SUBLIB ${TARGET_LIBS}) | ||
if(SUBLIB) | ||
add_to_depend_libs( ${prog_name} ${depend_file} ${SUBLIB} ) | ||
endif() | ||
endforeach() | ||
|
||
# Check if lib itself is an external shared library | ||
if("${lib_name}" MATCHES "\\.so$") | ||
package_with_target( ${prog_name} ${lib_name} ) | ||
endif() | ||
|
||
# Check if lib itself is an internal shared library | ||
get_target_property(TARGET_LIB ${lib_name} LOCATION) | ||
if("${TARGET_LIB}" MATCHES "\\.so$") | ||
package_with_target( ${prog_name} ${TARGET_LIB} ) | ||
endif() | ||
endmacro() | ||
|
||
macro( target_link_libraries prog_name) | ||
# _target_link_libraries corresponds to original | ||
_target_link_libraries( ${prog_name} ${ARGN} ) | ||
|
||
# Recursively process dependencies | ||
set(depend_file "${CMAKE_CURRENT_BINARY_DIR}/${prog_name}_shared_load.h" ) | ||
foreach( LIB ${ARGN} ) | ||
add_to_depend_libs( ${prog_name} ${depend_file} ${LIB} ) | ||
endforeach() | ||
endmacro() | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
macro( CreateMethodCallFile filename namespace function symbols) | ||
file(WRITE ${filename} "// CMake generated file. Do Not Edit.\n\n#pragma once\n\nnamespace ${namespace} {\n\n") | ||
foreach( symbol ${symbols} ) | ||
file(APPEND ${filename} "void ${symbol}();\n") | ||
endforeach() | ||
file(APPEND ${filename} "\ninline bool ${function}()\n{\n") | ||
foreach( symbol ${symbols} ) | ||
file(APPEND ${filename} " ${symbol}();\n") | ||
endforeach() | ||
file(APPEND ${filename} " return true;\n}\n\n} // ${namespace}\n") | ||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Creates C resources file from files in given directory | ||
# Based on http://stackoverflow.com/a/27206982 | ||
function(embed_binary_files file_glob output) | ||
# Collect input files | ||
file(GLOB bins ${file_glob}) | ||
# Stop when output file is newer than all binary files | ||
set(output_newer_than_bins 1) | ||
foreach(bin ${bins}) | ||
if(bin IS_NEWER_THAN output) | ||
set(output_newer_than_bins 0) | ||
break() | ||
endif() | ||
endforeach() | ||
if(output_newer_than_bins) | ||
return() | ||
endif() | ||
# Create empty output file | ||
file(WRITE ${output} "") | ||
# Iterate through input files | ||
foreach(bin ${bins}) | ||
# Get short filename | ||
string(REGEX MATCH "([^/]+)$" filename ${bin}) | ||
# Replace filename spaces & extension separator for C compatibility | ||
string(REGEX REPLACE "\\.| " "_" filename ${filename}) | ||
# Read hex data from file | ||
file(READ ${bin} filedata HEX) | ||
# Convert hex data for C compatibility | ||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata}) | ||
# Append data to output file | ||
file(APPEND ${output} "const unsigned char ${filename}[] = {${filedata}};\nconst unsigned ${filename}_size = sizeof(${filename});\n") | ||
endforeach() | ||
endfunction() |
Oops, something went wrong.