From Rafa Gaitan and Jorge Izquierdo, build support for Android NDK.

"- In order to build against GLES1 we execute:
$ mkdir build_android_gles1
$ cd build_android_gles1
$ cmake .. -DOSG_BUILD_PLATFORM_ANDROID=ON -DDYNAMIC_OPENTHREADS=OFF
-DDYNAMIC_OPENSCENEGRAPH=OFF -DANDROID_NDK=<path_to_android_ndk>/
-DOSG_GLES1_AVAILABLE=ON -DOSG_GL1_AVAILABLE=OFF
-DOSG_GL2_AVAILABLE=OFF -DOSG_GL_DISPLAYLISTS_AVAILABLE=OFF -DJ=2
-DOSG_CPP_EXCEPTIONS_AVAILABLE=OFF
$ make
 If all is correct you will have and static OSG inside:
build_android_gles1/bin/ndk/local/armeabi.

- GLES2 is not tested/proved, but I think it could be possible build
it with the correct cmake flags.
- The flag -DJ=2 is used to pass to the ndk-build the number of
processors to speed up the building.
- make install is not yet supported."
This commit is contained in:
Robert Osfield 2011-03-08 16:35:37 +00:00
parent 99aeca003b
commit b24353b12c
21 changed files with 529 additions and 220 deletions

View File

@ -62,6 +62,34 @@ SET(OpenThreads_SOURCE_DIR ${OpenSceneGraph_SOURCE_DIR})
# Maybe this can be used override existing behavior if needed? # Maybe this can be used override existing behavior if needed?
SET(CMAKE_MODULE_PATH "${OpenSceneGraph_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}") SET(CMAKE_MODULE_PATH "${OpenSceneGraph_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
## Option to enable Android build using AndroidNDK
OPTION(OSG_BUILD_PLATFORM_ANDROID OFF)
IF(OSG_BUILD_PLATFORM_ANDROID)
INCLUDE(OsgAndroidMacroUtils)
SET(ANDROID TRUE)
SET(ANDROID_PLATFORM 5)
FIND_PACKAGE(AndroidNDK REQUIRED)
SET(OSG_ANDROID_TEMPLATES "${CMAKE_SOURCE_DIR}/PlatformSpecifics/Android")
SET(J "4" CACHE STRING "how many processes for make -j <J>")
ADD_CUSTOM_COMMAND(
OUTPUT Android-OpenSceneGraph
DEPENDS ${CMAKE_BINARY_DIR}/Android.mk
COMMAND "${ANDROID_NDK}/ndk-build"
ARGS --directory=${CMAKE_BINARY_DIR} NDK_APPLICATION_MK=Application.mk -j${J} NDK_LOG=1
)
ADD_CUSTOM_TARGET(ndk ALL echo
DEPENDS Android-OpenSceneGraph
)
ADD_DEFINITIONS(-DANDROID)
ENDIF()
# Okay, here's the problem: On some platforms, linking against OpenThreads # Okay, here's the problem: On some platforms, linking against OpenThreads
# is not enough and explicit linking to the underlying thread library # is not enough and explicit linking to the underlying thread library
@ -74,7 +102,9 @@ SET(CMAKE_MODULE_PATH "${OpenSceneGraph_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_
# cases. With IRIX, we're going to hope explicit linking to the underlying # cases. With IRIX, we're going to hope explicit linking to the underlying
# library is not necessary. We currently don't case for pthreads on Windows # library is not necessary. We currently don't case for pthreads on Windows
# which might be an issue on things like Cygwin. This may need to be fixed. # which might be an issue on things like Cygwin. This may need to be fixed.
IF(NOT ANDROID)
FIND_PACKAGE(Threads) FIND_PACKAGE(Threads)
ENDIF()
IF(CMAKE_SYSTEM MATCHES IRIX) IF(CMAKE_SYSTEM MATCHES IRIX)
# Erase CMAKE_THREAD_LIBS_INIT and hope it works # Erase CMAKE_THREAD_LIBS_INIT and hope it works
SET(CMAKE_THREAD_LIBS_INIT "" CACHE INTERNAL "") SET(CMAKE_THREAD_LIBS_INIT "" CACHE INTERNAL "")
@ -137,7 +167,7 @@ IF (OSG_MAINTAINER)
ENDIF(OSG_MAINTAINER) ENDIF(OSG_MAINTAINER)
IF(NOT ANDROID)
IF(APPLE) IF(APPLE)
# Trying to get CMake to generate an XCode IPhone project, current efforts are to get iphoneos sdk 3.1 working # Trying to get CMake to generate an XCode IPhone project, current efforts are to get iphoneos sdk 3.1 working
# Added option which needs manually setting to select the IPhone SDK for building. We can only have one of the below # Added option which needs manually setting to select the IPhone SDK for building. We can only have one of the below
@ -182,8 +212,9 @@ ELSE()
# Non-Apple: Find OpenGL # Non-Apple: Find OpenGL
FIND_PACKAGE(OpenGL) FIND_PACKAGE(OpenGL)
ENDIF() ENDIF()
ENDIF()
IF(UNIX) IF(UNIX AND NOT ANDROID)
# Not sure what this will do on Cygwin and Msys # Not sure what this will do on Cygwin and Msys
# Also, remember OS X X11 is a user installed option so it may not exist. # Also, remember OS X X11 is a user installed option so it may not exist.
FIND_PACKAGE(X11) FIND_PACKAGE(X11)
@ -216,7 +247,7 @@ ENDIF()
# Platform specific definitions # Platform specific definitions
IF(WIN32) IF(WIN32 AND NOT ANDROID)
IF(MSVC) IF(MSVC)
# This option is to enable the /MP switch for Visual Studio 2005 and above compilers # This option is to enable the /MP switch for Visual Studio 2005 and above compilers
@ -295,7 +326,7 @@ IF(WIN32)
ENDIF(NOT OSG_MSVC_DEBUG_INCREMENTAL_LINK) ENDIF(NOT OSG_MSVC_DEBUG_INCREMENTAL_LINK)
ENDIF() ENDIF()
ENDIF(MSVC) ENDIF(MSVC)
ENDIF(WIN32) ENDIF(WIN32 AND NOT ANDROID)
######################################################################################################## ########################################################################################################
##### these were settings located in SetupCommon.cmake used in Luigi builds.... find out what are useful ##### these were settings located in SetupCommon.cmake used in Luigi builds.... find out what are useful
@ -395,11 +426,14 @@ OPTION(BUILD_OSG_EXAMPLES "Enable to build OSG Examples" OFF)
################################################################################ ################################################################################
# 3rd Party Dependency Stuff # 3rd Party Dependency Stuff
IF(WIN32) IF(WIN32 AND NOT ANDROID)
INCLUDE(Find3rdPartyDependencies) INCLUDE(Find3rdPartyDependencies)
ENDIF() ENDIF()
# Common to all platforms: IF(ANDROID)
# FIXME: add here any platform find
ELSE()
# Common to all platforms except android:
FIND_PACKAGE(FreeType) FIND_PACKAGE(FreeType)
FIND_PACKAGE(Inventor) FIND_PACKAGE(Inventor)
FIND_PACKAGE(Jasper) FIND_PACKAGE(Jasper)
@ -424,10 +458,12 @@ FIND_PACKAGE(RSVG)
FIND_PACKAGE(GtkGl) FIND_PACKAGE(GtkGl)
FIND_PACKAGE(DirectInput) FIND_PACKAGE(DirectInput)
FIND_PACKAGE(NVTT) FIND_PACKAGE(NVTT)
ENDIF()
# Include macro utilities here # Include macro utilities here
INCLUDE(OsgMacroUtils) INCLUDE(OsgMacroUtils)
IF(NOT ANDROID)
# To select a specific version of QT define DESIRED_QT_VERSION # To select a specific version of QT define DESIRED_QT_VERSION
# via cmake -DDESIRED_QT_VERSION=4 # via cmake -DDESIRED_QT_VERSION=4
IF (DESIRED_QT_VERSION) IF (DESIRED_QT_VERSION)
@ -447,9 +483,9 @@ ELSE()
ENDIF() ENDIF()
ENDIF() ENDIF()
ENDIF(NOT ANDROID)
#optional example related dependencies #optional example related dependencies
IF (BUILD_OSG_EXAMPLES) IF (BUILD_OSG_EXAMPLES AND NOT ANDROID)
FIND_PACKAGE(FLTK) FIND_PACKAGE(FLTK)
@ -459,7 +495,7 @@ IF (BUILD_OSG_EXAMPLES)
SET(wxWidgets_USE_LIBS base core gl net) SET(wxWidgets_USE_LIBS base core gl net)
FIND_PACKAGE(wxWidgets) FIND_PACKAGE(wxWidgets)
ENDIF(BUILD_OSG_EXAMPLES) ENDIF(BUILD_OSG_EXAMPLES AND NOT ANDROID)
# Platform specific: # Platform specific:
@ -476,6 +512,7 @@ ENDIF(BUILD_OSG_EXAMPLES)
# Image readers/writers depend on 3rd party libraries except for OS X which # Image readers/writers depend on 3rd party libraries except for OS X which
# can use Quicktime. # can use Quicktime.
IF(NOT ANDROID)
IF(NOT APPLE) IF(NOT APPLE)
FIND_PACKAGE(GIFLIB) FIND_PACKAGE(GIFLIB)
FIND_PACKAGE(JPEG) FIND_PACKAGE(JPEG)
@ -492,6 +529,7 @@ ELSE()
FIND_PACKAGE(QTKit) FIND_PACKAGE(QTKit)
FIND_PACKAGE(CoreVideo) FIND_PACKAGE(CoreVideo)
ENDIF() ENDIF()
ENDIF()
################################################################################ ################################################################################
# Create bin and lib directories if required # Create bin and lib directories if required
@ -690,7 +728,7 @@ ENDIF()
# OSG Core # OSG Core
ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(src)
IF (BUILD_OSG_APPLICATIONS) IF (BUILD_OSG_APPLICATIONS AND NOT ANDROID)
ADD_SUBDIRECTORY(applications) ADD_SUBDIRECTORY(applications)
ENDIF() ENDIF()
@ -966,3 +1004,12 @@ CONFIGURE_FILE(
IMMEDIATE @ONLY) IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET(uninstall ADD_CUSTOM_TARGET(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
#
IF(ANDROID)
message(STATUS "Creating Android Makefile Master files" )
configure_file("${OSG_ANDROID_TEMPLATES}/Android.mk.master.in" "${CMAKE_BINARY_DIR}/Android.mk")
configure_file("${OSG_ANDROID_TEMPLATES}/Application.mk.master.in" "${CMAKE_BINARY_DIR}/Application.mk")
configure_file("${OSG_ANDROID_TEMPLATES}/AndroidManifest.xml.master.in" "${CMAKE_BINARY_DIR}/AndroidManifest.xml")
ENDIF(ANDROID)

View File

@ -0,0 +1,45 @@
# Locate AndroidNDK
# This module defines
# ANDROID_NDK
# ANDROID_FOUND, if false, do not try to use AndroidNDK
#
FIND_PATH(ANDROID_NDK ndk-build
${ANDROID_NDK}
NO_DEFAULT_PATH
)
IF(NOT ANDROID_NDK)
FIND_PATH(ANDROID_NDK ndk-build
$ENV{ANDROID_NDK}
$ENV{ANDROID_ROOT}
NO_DEFAULT_PATH
)
ENDIF()
IF(NOT ANDROID_NDK)
FIND_PATH(ANDROID_NDK ndk-build
# search for r5b
~/android-ndk-r5b
~/android_develop/android-ndk-r5b
~/ndk-r5b
~/android_develop/ndk-r5b
# search for r5
~/android-ndk-r5
~/android_develop/android-ndk-r5
~/ndk-r5
~/android_develop/ndk-r5
# search for r4-crystax
~/android-ndk-r4-crystax
~/android_develop/android-ndk-r4-crystax
~/ndk-r4
~/android_develop/ndk-r4
)
ENDIF()
SET(ANDROID_FOUND "NO")
IF(ANDROID_NDK)
SET(ANDROID_FOUND "YES")
MESSAGE(STATUS "Android NDK found in: ${ANDROID_NDK}")
ENDIF(ANDROID_NDK)

View File

@ -0,0 +1,55 @@
MACRO(SETUP_ANDROID_LIBRARY LIB_NAME)
foreach(arg ${TARGET_LIBRARIES})
set(MODULE_LIBS "${MODULE_LIBS} -l${arg}")
endforeach(arg ${TARGET_LIBRARIES})
foreach(arg ${TARGET_SRC})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" n_f ${arg})
set(MODULE_SOURCES "${MODULE_SOURCES} ${n_f}")
endforeach(arg ${TARGET_SRC})
#SET(MODULE_INCLUDES "${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/include")
GET_DIRECTORY_PROPERTY(loc_includes INCLUDE_DIRECTORIES)
foreach(arg ${loc_includes})
IF(NOT "${arg}" MATCHES "/usr/include" AND NOT "${arg}" MATCHES "/usr/local/include")
set(MODULE_INCLUDES "${MODULE_INCLUDES} ${arg}")
ENDIF()
endforeach(arg ${loc_includes})
GET_DIRECTORY_PROPERTY(loc_definitions COMPILE_DEFINITIONS)
foreach(arg ${loc_definitions})
set(DEFINITIONS "${DEFINITIONS} -D${arg}")
endforeach(arg ${loc_definitions})
message(STATUS "##############Creating Android Makefile#################")
message(STATUS "name: ${LIB_NAME}")
set(MODULE_NAME ${LIB_NAME})
set(MODULE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(MODULE_FLAGS_C ${DEFINITIONS})
set(MODULE_FLAGS_CPP ${DEFINITIONS})
#TODO: determine if GLES2 or GLES
IF(OSG_GLES1_AVAILABLE)
SET(OPENGLES_LIBRARY -lGLESv1_CM)
ELSEIF(OSG_GLES2_AVAILABLE)
SET(OPENGLES_LIBRARY -lGLESv2)
ENDIF()
set(MODULE_LIBS "${MODULE_LIBS} ${OPENGLES_LIBRARY} -ldl")
if(NOT CPP_EXTENSION)
set(CPP_EXTENSION "cpp")
endif()
IF(NOT MODULE_USER_STATIC_OR_DYNAMIC)
MESSAGE(FATAL_ERROR "Not defined MODULE_USER_STATIC_OR_DYNAMIC")
ENDIF()
IF("MODULE_USER_STATIC_OR_DYNAMIC" MATCHES "STATIC")
SET(MODULE_BUILD_TYPE "\$\(BUILD_STATIC_LIBRARY\)")
ELSE()
SET(MODULE_BUILD_TYPE "\$\(BUILD_DYNAMIC_LIBRARY\)")
ENDIF()
set(ENV{AND_OSG_LIB_NAMES} "$ENV{AND_OSG_LIB_NAMES} ${LIB_NAME}")
set(ENV{AND_OSG_LIB_PATHS} "$ENV{AND_OSG_LIB_PATHS}include ${CMAKE_CURRENT_BINARY_DIR}/Android.mk \n")
configure_file("${OSG_ANDROID_TEMPLATES}/Android.mk.modules.in" "${CMAKE_CURRENT_BINARY_DIR}/Android.mk")
ENDMACRO()

View File

@ -210,7 +210,9 @@ ENDMACRO(SET_OUTPUT_DIR_PROPERTY_260 TARGET_TARGETNAME RELATIVE_OUTDIR)
########################################################################################################## ##########################################################################################################
MACRO(SETUP_LIBRARY LIB_NAME) MACRO(SETUP_LIBRARY LIB_NAME)
IF(ANDROID)
SETUP_ANDROID_LIBRARY(${LIB_NAME})
ELSE()
SET(TARGET_NAME ${LIB_NAME} ) SET(TARGET_NAME ${LIB_NAME} )
SET(TARGET_TARGETNAME ${LIB_NAME} ) SET(TARGET_TARGETNAME ${LIB_NAME} )
@ -236,10 +238,13 @@ MACRO(SETUP_LIBRARY LIB_NAME)
LINK_CORELIB_DEFAULT(${LIB_NAME}) LINK_CORELIB_DEFAULT(${LIB_NAME})
INCLUDE(ModuleInstall OPTIONAL) INCLUDE(ModuleInstall OPTIONAL)
ENDIF()
ENDMACRO(SETUP_LIBRARY LIB_NAME) ENDMACRO(SETUP_LIBRARY LIB_NAME)
MACRO(SETUP_PLUGIN PLUGIN_NAME) MACRO(SETUP_PLUGIN PLUGIN_NAME)
IF(ANDROID)
SETUP_ANDROID_LIBRARY(${TARGET_DEFAULT_PREFIX}${PLUGIN_NAME})
ELSE()
SET(TARGET_NAME ${PLUGIN_NAME} ) SET(TARGET_NAME ${PLUGIN_NAME} )
@ -324,6 +329,7 @@ MACRO(SETUP_PLUGIN PLUGIN_NAME)
ARCHIVE DESTINATION lib${LIB_POSTFIX}/${OSG_PLUGINS} COMPONENT libopenscenegraph-dev ARCHIVE DESTINATION lib${LIB_POSTFIX}/${OSG_PLUGINS} COMPONENT libopenscenegraph-dev
LIBRARY DESTINATION lib${LIB_POSTFIX}/${OSG_PLUGINS} COMPONENT ${PACKAGE_COMPONENT}) LIBRARY DESTINATION lib${LIB_POSTFIX}/${OSG_PLUGINS} COMPONENT ${PACKAGE_COMPONENT})
ENDIF(WIN32) ENDIF(WIN32)
ENDIF()
ENDMACRO(SETUP_PLUGIN) ENDMACRO(SETUP_PLUGIN)

View File

@ -0,0 +1,7 @@
#ANDROID ROOT MAKEFILE
OSG_ROOT := $(call my-dir)
LOCAL_PATH := $(call my-dir)
OSG_ROOT := $(LOCAL_PATH)
OSGInclude := $(OSG_ROOT)/include/OpenThreads \
$(OSG_ROOT)/include/osg
include src/Android.mk

View File

@ -0,0 +1,23 @@
#ANDROID makefile ${MODULE_NAME}
LOCAL_PATH := ${MODULE_DIR}
include $(CLEAR_VARS)
LOCAL_CPP_EXTENSION := ${CPP_EXTENSION}
LOCAL_LDLIBS := ${MODULE_LIBS}
LOCAL_MODULE := ${MODULE_NAME}
LOCAL_SRC_FILES := ${MODULE_SOURCES}
LOCAL_C_INCLUDES := ${MODULE_INCLUDES}
LOCAL_CFLAGS := ${MODULE_FLAGS_C}
LOCAL_CPPFLAGS := ${MODULE_FLAGS_CPP}
#include $(BUILD_STATIC_LIBRARY)
include ${MODULE_BUILD_TYPE}

View File

@ -0,0 +1,17 @@
#ANDROID makefile in src
SERIALIZER_ROOT := $(call my-dir)
LOCAL_PATH := $(call my-dir)
SERIALIZER_ROOT := $(LOCAL_PATH)
#include $(call all-subdir-makefiles)
include $(SERIALIZER_ROOT)/osg/Android.mk
include $(SERIALIZER_ROOT)/osgAnimation/Android.mk
include $(SERIALIZER_ROOT)/osgFX/Android.mk
include $(SERIALIZER_ROOT)/osgManipulator/Android.mk
include $(SERIALIZER_ROOT)/osgParticle/Android.mk
include $(SERIALIZER_ROOT)/osgShadow/Android.mk
include $(SERIALIZER_ROOT)/osgSim/Android.mk
include $(SERIALIZER_ROOT)/osgTerrain/Android.mk
include $(SERIALIZER_ROOT)/osgText/Android.mk
include $(SERIALIZER_ROOT)/osgVolume/Android.mk

View File

@ -0,0 +1,8 @@
#ANDROID makefile in src
SRC_ROOT := $(call my-dir)
LOCAL_PATH := $(call my-dir)
SRC_ROOT := $(LOCAL_PATH)
$ENV{AND_OSG_LIB_PATHS}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.openscenegraph"
android:versionCode="1"
android:versionName="1.0">
</manifest>

View File

@ -0,0 +1,15 @@
#ANDROID APPLICATION MAKEFILE
APP_BUILD_SCRIPT := $(call my-dir)/Android.mk
APP_PROJECT_PATH := $(call my-dir)
APP_OPTIM := release
APP_PLATFORM := android-5
APP_STL := gnustl_static
APP_CPPFLAGS := -fexceptions -frtti
#APP_CPPFLAGS := -Os -mthumb-interwork -fno-short-enums
#APP_CPPFLAGS := -Wl,--no-undefined
APP_ABI := armeabi
#armeabi-v7a
APP_MODULES := $ENV{AND_OSG_LIB_NAMES}

View File

@ -14,6 +14,9 @@ SET(TARGET_COMMON_LIBRARIES
osgText osgText
) )
IF(ANDROID)
# ADD_SUBDIRECTORY(osgandroidsimple)
ELSE(ANDROID)
IF(DYNAMIC_OPENSCENEGRAPH) IF(DYNAMIC_OPENSCENEGRAPH)
@ -246,3 +249,5 @@ ELSE(DYNAMIC_OPENSCENEGRAPH)
ENDIF(DYNAMIC_OPENSCENEGRAPH) ENDIF(DYNAMIC_OPENSCENEGRAPH)
ENDIF(ANDROID)

View File

@ -77,7 +77,7 @@
#if defined(_WIN64) #if defined(_WIN64)
typedef __int64 GLintptr; typedef __int64 GLintptr;
typedef __int64 GLsizeiptr; typedef __int64 GLsizeiptr;
#elif defined(__ia64__) || defined(__x86_64__) #elif defined(__ia64__) || defined(__x86_64__) || defined(ANDROID)
typedef long int GLintptr; typedef long int GLintptr;
typedef long int GLsizeiptr; typedef long int GLsizeiptr;
#else #else

View File

@ -19,7 +19,7 @@
#include <string> #include <string>
#ifdef __CYGWIN__ #if defined(__CYGWIN__) || defined(ANDROID)
namespace std namespace std
{ {
typedef basic_string<wchar_t> wstring; typedef basic_string<wchar_t> wstring;

View File

@ -1,3 +1,7 @@
IF(ANDROID)
SET(MODULE_USER_STATIC_OR_DYNAMIC ${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC})
ENDIF(ANDROID)
#the old construct SUBDIRS( was substituded by ADD_SUBDIRECTORY that is to be preferred according on CMake docs. #the old construct SUBDIRS( was substituded by ADD_SUBDIRECTORY that is to be preferred according on CMake docs.
FOREACH( mylibfolder FOREACH( mylibfolder
OpenThreads OpenThreads
@ -26,7 +30,7 @@ FOREACH( mylibfolder
ENDFOREACH() ENDFOREACH()
IF (QT4_FOUND) IF (QT4_FOUND AND NOT ANDROID)
ADD_SUBDIRECTORY(osgQt) ADD_SUBDIRECTORY(osgQt)
ENDIF() ENDIF()
@ -34,3 +38,7 @@ IF(MSVC80 OR MSVC90)
OPTION(OSG_MSVC_GENERATE_PLUGINS_AND_WRAPPERS_MANIFESTS "Generate or not manifests files under VS8 for dynamically loaded dlls" ON) OPTION(OSG_MSVC_GENERATE_PLUGINS_AND_WRAPPERS_MANIFESTS "Generate or not manifests files under VS8 for dynamically loaded dlls" ON)
ENDIF() ENDIF()
IF(ANDROID)
configure_file("${OSG_ANDROID_TEMPLATES}/Android.mk.src.in" "${CMAKE_CURRENT_BINARY_DIR}/Android.mk")
ENDIF()

View File

@ -9,7 +9,9 @@ SET(OPENTHREADS_SOVERSION 12)
SET(OPENTHREADS_VERSION ${OPENTHREADS_MAJOR_VERSION}.${OPENTHREADS_MINOR_VERSION}.${OPENTHREADS_PATCH_VERSION}) SET(OPENTHREADS_VERSION ${OPENTHREADS_MAJOR_VERSION}.${OPENTHREADS_MINOR_VERSION}.${OPENTHREADS_PATCH_VERSION})
IF(NOT ANDROID)
INCLUDE(CheckAtomicOps) INCLUDE(CheckAtomicOps)
ENDIF()
# User Options # User Options
OPTION(DYNAMIC_OPENTHREADS "Set to ON to build OpenThreads for dynamic linking. Use OFF for static." ON) OPTION(DYNAMIC_OPENTHREADS "Set to ON to build OpenThreads for dynamic linking. Use OFF for static." ON)
@ -62,9 +64,10 @@ SET(OpenThreads_PUBLIC_HEADERS
${OPENTHREADS_CONFIG_HEADER} ${OPENTHREADS_CONFIG_HEADER}
) )
IF(NOT ANDROID)
# Use our modified version of FindThreads.cmake which has Sproc hacks. # Use our modified version of FindThreads.cmake which has Sproc hacks.
FIND_PACKAGE(Threads) FIND_PACKAGE(Threads)
ENDIF()
# Do we have sproc? # Do we have sproc?
IF(CMAKE_SYSTEM MATCHES IRIX) IF(CMAKE_SYSTEM MATCHES IRIX)
IF(CMAKE_USE_SPROC_INIT) IF(CMAKE_USE_SPROC_INIT)
@ -83,7 +86,9 @@ IF(QT4_FOUND)
ENDIF() ENDIF()
# Maybe we should be using the FindThreads.cmake module? # Maybe we should be using the FindThreads.cmake module?
IF(QT4_FOUND AND BUILD_OPENTHREADS_WITH_QT) IF(ANDROID)
SUBDIRS(pthreads)
ELSEIF(QT4_FOUND AND BUILD_OPENTHREADS_WITH_QT)
SUBDIRS(qt) SUBDIRS(qt)
ELSEIF(WIN32) ELSEIF(WIN32)
# So I think Cygwin wants to use pthreads # So I think Cygwin wants to use pthreads

View File

@ -6,11 +6,9 @@ INCLUDE (CheckSymbolExists)
INCLUDE (CheckCXXSourceCompiles) INCLUDE (CheckCXXSourceCompiles)
SET(LIB_NAME OpenThreads) SET(LIB_NAME OpenThreads)
SET(LIB_PUBLIC_HEADERS ${OpenThreads_PUBLIC_HEADERS}) SET(TARGET_H ${OpenThreads_PUBLIC_HEADERS})
ADD_LIBRARY(${LIB_NAME} SET(TARGET_SRC
${OPENTHREADS_USER_DEFINED_DYNAMIC_OR_STATIC}
${LIB_PUBLIC_HEADERS}
PThread.cpp PThread.cpp
PThreadBarrier.cpp PThreadBarrier.cpp
PThreadBarrierPrivateData.h PThreadBarrierPrivateData.h
@ -22,14 +20,18 @@ ADD_LIBRARY(${LIB_NAME}
../common/Version.cpp ../common/Version.cpp
../common/Atomic.cpp ../common/Atomic.cpp
) )
IF(ANDROID)
ADD_DEFINITIONS(-D_GNU_SOURCE)
SET(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE")
SET(MODULE_USER_STATIC_OR_DYNAMIC ${OPENTHREADS_USER_DEFINED_DYNAMIC_OR_STATIC})
#SET(CPP_EXTENSION "c++")
SETUP_ANDROID_LIBRARY(${LIB_NAME})
ELSE()
IF(OPENTHREADS_SONAMES) # should check?
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${OPENTHREADS_VERSION} SOVERSION ${OPENTHREADS_SOVERSION}) ADD_DEFINITIONS(-DHAVE_PTHREAD_TESTCANCEL)
ENDIF() ADD_DEFINITIONS(-DHAVE_PTHREAD_CANCEL)
ADD_DEFINITIONS(-DHAVE_PTHREAD_SETCANCELSTATE)
SET(CMAKE_REQUIRED_LIBRARIES_SAFE "${CMAKE_REQUIRED_LIBRARIES}")
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
CHECK_FUNCTION_EXISTS(pthread_yield HAVE_PTHREAD_YIELD) CHECK_FUNCTION_EXISTS(pthread_yield HAVE_PTHREAD_YIELD)
IF(HAVE_PTHREAD_YIELD) IF(HAVE_PTHREAD_YIELD)
@ -108,6 +110,20 @@ int main() {
ENDIF() ENDIF()
ENDIF() ENDIF()
SET(CMAKE_REQUIRED_LIBRARIES_SAFE "${CMAKE_REQUIRED_LIBRARIES}")
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
ADD_LIBRARY(${LIB_NAME}
${OPENTHREADS_USER_DEFINED_DYNAMIC_OR_STATIC}
${TARGET_H}
${TARGET_SRC}
)
IF(OPENTHREADS_SONAMES)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${OPENTHREADS_VERSION} SOVERSION ${OPENTHREADS_SOVERSION})
ENDIF()
SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_SAFE}") SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_SAFE}")
TARGET_LINK_LIBRARIES(${LIB_NAME} TARGET_LINK_LIBRARIES(${LIB_NAME}
@ -144,4 +160,5 @@ ELSE()
INSTALL_NAME_DIR "${OSG_COMPILE_FRAMEWORKS_INSTALL_NAME_DIR}" INSTALL_NAME_DIR "${OSG_COMPILE_FRAMEWORKS_INSTALL_NAME_DIR}"
) )
ENDIF() ENDIF()
ENDIF()
#commented out# INCLUDE(ModuleInstall OPTIONAL) #commented out# INCLUDE(ModuleInstall OPTIONAL)

View File

@ -23,12 +23,14 @@
#include <pthread.h> #include <pthread.h>
#include <limits.h> #include <limits.h>
#if defined __linux || defined __sun || defined __APPLE__ #if defined __linux || defined __sun || defined __APPLE__ || ANDROID
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#if !defined ANDROID
#include <sys/unistd.h> #include <sys/unistd.h>
#endif #endif
#endif
#if defined(__sgi) #if defined(__sgi)
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -44,6 +46,12 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
#if defined(ANDROID)
#ifndef PAGE_SIZE
#define PAGE_SIZE 0x400
#endif
#endif
#include <OpenThreads/Thread> #include <OpenThreads/Thread>
#include "PThreadPrivateData.h" #include "PThreadPrivateData.h"
@ -723,7 +731,7 @@ int Thread::join()
// //
int Thread::testCancel() int Thread::testCancel()
{ {
#if defined(HAVE_PTHREAD_TESTCANCEL)
PThreadPrivateData *pd = static_cast<PThreadPrivateData *> (_prvData); PThreadPrivateData *pd = static_cast<PThreadPrivateData *> (_prvData);
if(pthread_self() != pd->tid) if(pthread_self() != pd->tid)
@ -732,7 +740,9 @@ int Thread::testCancel()
pthread_testcancel(); pthread_testcancel();
return 0; return 0;
#else
return 0;
#endif
} }
@ -744,7 +754,7 @@ int Thread::testCancel()
// //
int Thread::cancel() int Thread::cancel()
{ {
#if defined(HAVE_PTHREAD_CANCEL)
PThreadPrivateData *pd = static_cast<PThreadPrivateData *> (_prvData); PThreadPrivateData *pd = static_cast<PThreadPrivateData *> (_prvData);
if (pd->isRunning) if (pd->isRunning)
{ {
@ -753,6 +763,9 @@ int Thread::cancel()
return status; return status;
} }
return 0; return 0;
#else
return 0;
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -763,9 +776,11 @@ int Thread::cancel()
// //
int Thread::setCancelModeDisable() int Thread::setCancelModeDisable()
{ {
#if defined(HAVE_PTHREAD_SETCANCELSTATE)
return pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, 0 ); return pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, 0 );
#else
return 0;
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -776,10 +791,14 @@ int Thread::setCancelModeDisable()
// //
int Thread::setCancelModeAsynchronous() { int Thread::setCancelModeAsynchronous() {
#if defined(HAVE_PTHREAD_SETCANCELSTATE)
int status = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0); int status = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
if(status != 0) return status; if(status != 0) return status;
return pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0); return pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0);
#else
return 0;
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -790,11 +809,14 @@ int Thread::setCancelModeAsynchronous() {
// //
int Thread::setCancelModeDeferred() { int Thread::setCancelModeDeferred() {
#if defined(HAVE_PTHREAD_SETCANCELSTATE)
int status = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, 0); int status = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, 0);
if(status != 0) return status; if(status != 0) return status;
return pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0); return pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, 0);
#else
return 0;
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -947,7 +969,12 @@ int Thread::YieldCurrentThread()
// //
int Thread::microSleep(unsigned int microsec) int Thread::microSleep(unsigned int microsec)
{ {
#if !defined(ANDROID)
return ::usleep(microsec); return ::usleep(microsec);
#else
::usleep(microsec);
return 0;
#endif
} }

View File

@ -166,7 +166,9 @@ ADD_SUBDIRECTORY(obj)
ADD_SUBDIRECTORY(pic) ADD_SUBDIRECTORY(pic)
ADD_SUBDIRECTORY(stl) ADD_SUBDIRECTORY(stl)
IF(NOT ANDROID)
ADD_SUBDIRECTORY(3ds) ADD_SUBDIRECTORY(3ds)
ENDIF()
ADD_SUBDIRECTORY(ac) ADD_SUBDIRECTORY(ac)
ADD_SUBDIRECTORY(pov) ADD_SUBDIRECTORY(pov)
@ -203,7 +205,7 @@ ENDIF()
# ADD_SUBDIRECTORY(OpenAL) # ADD_SUBDIRECTORY(OpenAL)
# ENDIF() # ENDIF()
IF(APPLE) IF(APPLE AND NOT ANDROID)
ADD_SUBDIRECTORY(imageio) ADD_SUBDIRECTORY(imageio)
ENDIF() ENDIF()

View File

@ -9,6 +9,7 @@
#include "memory.h" #include "memory.h"
#include "BITSET.h" #include "BITSET.h"
#include <cstring>
bool BITSET::Init(int numberOfBits) bool BITSET::Init(int numberOfBits)
{ {

View File

@ -47,11 +47,19 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
STRING(REGEX REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") STRING(REGEX REPLACE "-pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ENDIF() ENDIF()
SET(TARGET_LIBRARIES_VARS SET(TARGET_LIBRARIES
QT_QTCORE_LIBRARY ${TARGET_LIBRARIES}
QT_QTGUI_LIBRARY ${QT_QTCORE_LIBRARY}
QT_QTOPENGL_LIBRARY ${QT_QTGUI_LIBRARY}
${QT_QTOPENGL_LIBRARY}
) )
# FIXME: This should work but something with the LINK_WITH_VARIABLES macro is not working
#SET(TARGET_LIBRARIES_VARS
# QT_QTCORE_LIBRARY
# QT_QTGUI_LIBRARY
# QT_QTOPENGL_LIBRARY
#)
INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR})
SETUP_LIBRARY(${LIB_NAME}) SETUP_LIBRARY(${LIB_NAME})

View File

@ -70,9 +70,13 @@ ELSE()
SET(OSG_WINDOWING_SYSTEM "Carbon" CACHE STRING "Windowing system type for graphics window creation, options Carbon, Cocoa or X11.") SET(OSG_WINDOWING_SYSTEM "Carbon" CACHE STRING "Windowing system type for graphics window creation, options Carbon, Cocoa or X11.")
ENDIF() ENDIF()
ELSE()
IF(ANDROID)
SET(OSG_WINDOWING_SYSTEM "None" CACHE STRING "None Windowing system type for graphics window creation.")
ELSE() ELSE()
SET(OSG_WINDOWING_SYSTEM "X11" CACHE STRING "Windowing system type for graphics window creation. options only X11") SET(OSG_WINDOWING_SYSTEM "X11" CACHE STRING "Windowing system type for graphics window creation. options only X11")
ENDIF() ENDIF()
ENDIF()
IF(${OSG_WINDOWING_SYSTEM} STREQUAL "Cocoa") IF(${OSG_WINDOWING_SYSTEM} STREQUAL "Cocoa")
ADD_DEFINITIONS(-DUSE_DARWIN_COCOA_IMPLEMENTATION) ADD_DEFINITIONS(-DUSE_DARWIN_COCOA_IMPLEMENTATION)
@ -156,7 +160,7 @@ ELSE()
SET(LIB_EXTRA_LIBS ${COCOA_LIBRARY} ${LIB_EXTRA_LIBS}) SET(LIB_EXTRA_LIBS ${COCOA_LIBRARY} ${LIB_EXTRA_LIBS})
ELSE() ELSEIF(${OSG_WINDOWING_SYSTEM} STREQUAL "x11")
# X11 for everybody else # X11 for everybody else
INCLUDE(FindPkgConfig OPTIONAL) INCLUDE(FindPkgConfig OPTIONAL)
IF(PKG_CONFIG_FOUND) IF(PKG_CONFIG_FOUND)
@ -217,6 +221,8 @@ ELSE()
SET(LIB_EXTRA_LIBS ${X11_X11_LIB} ${LIB_EXTRA_LIBS}) SET(LIB_EXTRA_LIBS ${X11_X11_LIB} ${LIB_EXTRA_LIBS})
ENDIF(APPLE) ENDIF(APPLE)
ELSE()
MESSAGE(STATUS "Windowing system not supported")
ENDIF() ENDIF()
ENDIF() ENDIF()