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?
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
# 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
# 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.
FIND_PACKAGE(Threads)
IF(NOT ANDROID)
FIND_PACKAGE(Threads)
ENDIF()
IF(CMAKE_SYSTEM MATCHES IRIX)
# Erase CMAKE_THREAD_LIBS_INIT and hope it works
SET(CMAKE_THREAD_LIBS_INIT "" CACHE INTERNAL "")
@ -137,7 +167,7 @@ IF (OSG_MAINTAINER)
ENDIF(OSG_MAINTAINER)
IF(NOT ANDROID)
IF(APPLE)
# 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
@ -182,8 +212,9 @@ ELSE()
# Non-Apple: Find OpenGL
FIND_PACKAGE(OpenGL)
ENDIF()
ENDIF()
IF(UNIX)
IF(UNIX AND NOT ANDROID)
# 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.
FIND_PACKAGE(X11)
@ -216,7 +247,7 @@ ENDIF()
# Platform specific definitions
IF(WIN32)
IF(WIN32 AND NOT ANDROID)
IF(MSVC)
# 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()
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
@ -395,61 +426,66 @@ OPTION(BUILD_OSG_EXAMPLES "Enable to build OSG Examples" OFF)
################################################################################
# 3rd Party Dependency Stuff
IF(WIN32)
IF(WIN32 AND NOT ANDROID)
INCLUDE(Find3rdPartyDependencies)
ENDIF()
# Common to all platforms:
FIND_PACKAGE(FreeType)
FIND_PACKAGE(Inventor)
FIND_PACKAGE(Jasper)
FIND_PACKAGE(OpenEXR)
FIND_PACKAGE(COLLADA)
FIND_PACKAGE(FBX)
FIND_PACKAGE(ZLIB)
FIND_PACKAGE(Xine)
FIND_PACKAGE(OpenVRML)
FIND_PACKAGE(Performer)
FIND_PACKAGE(GDAL)
FIND_PACKAGE(CURL)
FIND_PACKAGE(ITK)
FIND_PACKAGE(LibVNCServer)
FIND_PACKAGE(OurDCMTK)
FIND_PACKAGE(OpenAL)
FIND_PACKAGE(FFmpeg)
FIND_PACKAGE(DirectShow)
FIND_PACKAGE(SDL)
FIND_PACKAGE(Poppler-glib)
FIND_PACKAGE(RSVG)
FIND_PACKAGE(GtkGl)
FIND_PACKAGE(DirectInput)
FIND_PACKAGE(NVTT)
IF(ANDROID)
# FIXME: add here any platform find
ELSE()
# Common to all platforms except android:
FIND_PACKAGE(FreeType)
FIND_PACKAGE(Inventor)
FIND_PACKAGE(Jasper)
FIND_PACKAGE(OpenEXR)
FIND_PACKAGE(COLLADA)
FIND_PACKAGE(FBX)
FIND_PACKAGE(ZLIB)
FIND_PACKAGE(Xine)
FIND_PACKAGE(OpenVRML)
FIND_PACKAGE(Performer)
FIND_PACKAGE(GDAL)
FIND_PACKAGE(CURL)
FIND_PACKAGE(ITK)
FIND_PACKAGE(LibVNCServer)
FIND_PACKAGE(OurDCMTK)
FIND_PACKAGE(OpenAL)
FIND_PACKAGE(FFmpeg)
FIND_PACKAGE(DirectShow)
FIND_PACKAGE(SDL)
FIND_PACKAGE(Poppler-glib)
FIND_PACKAGE(RSVG)
FIND_PACKAGE(GtkGl)
FIND_PACKAGE(DirectInput)
FIND_PACKAGE(NVTT)
ENDIF()
# Include macro utilities here
INCLUDE(OsgMacroUtils)
IF(NOT ANDROID)
# To select a specific version of QT define DESIRED_QT_VERSION
# via cmake -DDESIRED_QT_VERSION=4
IF (DESIRED_QT_VERSION)
IF (DESIRED_QT_VERSION)
IF (DESIRED_QT_VERSION MATCHES 4)
FIND_PACKAGE(Qt4)
ELSE()
FIND_PACKAGE(Qt3)
ENDIF()
IF (DESIRED_QT_VERSION MATCHES 4)
FIND_PACKAGE(Qt4)
ELSE()
FIND_PACKAGE(Qt3)
FIND_PACKAGE(Qt4)
IF (NOT QT4_FOUND)
FIND_PACKAGE(Qt3)
ENDIF()
ENDIF()
ELSE()
FIND_PACKAGE(Qt4)
IF (NOT QT4_FOUND)
FIND_PACKAGE(Qt3)
ENDIF()
ENDIF()
ENDIF(NOT ANDROID)
#optional example related dependencies
IF (BUILD_OSG_EXAMPLES)
IF (BUILD_OSG_EXAMPLES AND NOT ANDROID)
FIND_PACKAGE(FLTK)
@ -459,7 +495,7 @@ IF (BUILD_OSG_EXAMPLES)
SET(wxWidgets_USE_LIBS base core gl net)
FIND_PACKAGE(wxWidgets)
ENDIF(BUILD_OSG_EXAMPLES)
ENDIF(BUILD_OSG_EXAMPLES AND NOT ANDROID)
# Platform specific:
@ -476,21 +512,23 @@ ENDIF(BUILD_OSG_EXAMPLES)
# Image readers/writers depend on 3rd party libraries except for OS X which
# can use Quicktime.
IF(NOT APPLE)
FIND_PACKAGE(GIFLIB)
FIND_PACKAGE(JPEG)
FIND_PACKAGE(PNG)
FIND_PACKAGE(TIFF)
IF(NOT ANDROID)
IF(NOT APPLE)
FIND_PACKAGE(GIFLIB)
FIND_PACKAGE(JPEG)
FIND_PACKAGE(PNG)
FIND_PACKAGE(TIFF)
# QuickTime is required for OS X, but optional for Windows.
IF(WIN32)
# QuickTime is required for OS X, but optional for Windows.
IF(WIN32)
FIND_PACKAGE(QuickTime)
ENDIF()
ELSE()
FIND_PACKAGE(QuickTime)
FIND_PACKAGE(QTKit)
FIND_PACKAGE(CoreVideo)
ENDIF()
ELSE()
FIND_PACKAGE(QuickTime)
FIND_PACKAGE(QTKit)
FIND_PACKAGE(CoreVideo)
ENDIF()
################################################################################
@ -690,7 +728,7 @@ ENDIF()
# OSG Core
ADD_SUBDIRECTORY(src)
IF (BUILD_OSG_APPLICATIONS)
IF (BUILD_OSG_APPLICATIONS AND NOT ANDROID)
ADD_SUBDIRECTORY(applications)
ENDIF()
@ -966,3 +1004,12 @@ CONFIGURE_FILE(
IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET(uninstall
"${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,36 +210,41 @@ ENDMACRO(SET_OUTPUT_DIR_PROPERTY_260 TARGET_TARGETNAME RELATIVE_OUTDIR)
##########################################################################################################
MACRO(SETUP_LIBRARY LIB_NAME)
IF(ANDROID)
SETUP_ANDROID_LIBRARY(${LIB_NAME})
ELSE()
SET(TARGET_NAME ${LIB_NAME} )
SET(TARGET_TARGETNAME ${LIB_NAME} )
SET(TARGET_NAME ${LIB_NAME} )
SET(TARGET_TARGETNAME ${LIB_NAME} )
ADD_LIBRARY(${LIB_NAME}
${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC}
${TARGET_H}
${TARGET_SRC}
)
ADD_LIBRARY(${LIB_NAME}
${OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC}
${TARGET_H}
${TARGET_SRC}
)
IF(TARGET_LABEL)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "${TARGET_LABEL}")
ENDIF(TARGET_LABEL)
IF(TARGET_LABEL)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "${TARGET_LABEL}")
ENDIF(TARGET_LABEL)
IF(TARGET_LIBRARIES)
LINK_INTERNAL(${LIB_NAME} ${TARGET_LIBRARIES})
IF(TARGET_LIBRARIES)
LINK_INTERNAL(${LIB_NAME} ${TARGET_LIBRARIES})
ENDIF()
IF(TARGET_EXTERNAL_LIBRARIES)
LINK_EXTERNAL(${LIB_NAME} ${TARGET_EXTERNAL_LIBRARIES})
ENDIF()
IF(TARGET_LIBRARIES_VARS)
LINK_WITH_VARIABLES(${LIB_NAME} ${TARGET_LIBRARIES_VARS})
ENDIF(TARGET_LIBRARIES_VARS)
LINK_CORELIB_DEFAULT(${LIB_NAME})
INCLUDE(ModuleInstall OPTIONAL)
ENDIF()
IF(TARGET_EXTERNAL_LIBRARIES)
LINK_EXTERNAL(${LIB_NAME} ${TARGET_EXTERNAL_LIBRARIES})
ENDIF()
IF(TARGET_LIBRARIES_VARS)
LINK_WITH_VARIABLES(${LIB_NAME} ${TARGET_LIBRARIES_VARS})
ENDIF(TARGET_LIBRARIES_VARS)
LINK_CORELIB_DEFAULT(${LIB_NAME})
INCLUDE(ModuleInstall OPTIONAL)
ENDMACRO(SETUP_LIBRARY LIB_NAME)
MACRO(SETUP_PLUGIN PLUGIN_NAME)
IF(ANDROID)
SETUP_ANDROID_LIBRARY(${TARGET_DEFAULT_PREFIX}${PLUGIN_NAME})
ELSE()
SET(TARGET_NAME ${PLUGIN_NAME} )
@ -324,6 +329,7 @@ MACRO(SETUP_PLUGIN PLUGIN_NAME)
ARCHIVE DESTINATION lib${LIB_POSTFIX}/${OSG_PLUGINS} COMPONENT libopenscenegraph-dev
LIBRARY DESTINATION lib${LIB_POSTFIX}/${OSG_PLUGINS} COMPONENT ${PACKAGE_COMPONENT})
ENDIF(WIN32)
ENDIF()
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
)
IF(ANDROID)
# ADD_SUBDIRECTORY(osgandroidsimple)
ELSE(ANDROID)
IF(DYNAMIC_OPENSCENEGRAPH)
@ -246,3 +249,5 @@ ELSE(DYNAMIC_OPENSCENEGRAPH)
ENDIF(DYNAMIC_OPENSCENEGRAPH)
ENDIF(ANDROID)

View File

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

View File

@ -19,7 +19,7 @@
#include <string>
#ifdef __CYGWIN__
#if defined(__CYGWIN__) || defined(ANDROID)
namespace std
{
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.
FOREACH( mylibfolder
OpenThreads
@ -26,7 +30,7 @@ FOREACH( mylibfolder
ENDFOREACH()
IF (QT4_FOUND)
IF (QT4_FOUND AND NOT ANDROID)
ADD_SUBDIRECTORY(osgQt)
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)
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})
INCLUDE(CheckAtomicOps)
IF(NOT ANDROID)
INCLUDE(CheckAtomicOps)
ENDIF()
# User Options
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}
)
IF(NOT ANDROID)
# Use our modified version of FindThreads.cmake which has Sproc hacks.
FIND_PACKAGE(Threads)
FIND_PACKAGE(Threads)
ENDIF()
# Do we have sproc?
IF(CMAKE_SYSTEM MATCHES IRIX)
IF(CMAKE_USE_SPROC_INIT)
@ -83,7 +86,9 @@ IF(QT4_FOUND)
ENDIF()
# 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)
ELSEIF(WIN32)
# So I think Cygwin wants to use pthreads

View File

@ -6,12 +6,10 @@ INCLUDE (CheckSymbolExists)
INCLUDE (CheckCXXSourceCompiles)
SET(LIB_NAME OpenThreads)
SET(LIB_PUBLIC_HEADERS ${OpenThreads_PUBLIC_HEADERS})
SET(TARGET_H ${OpenThreads_PUBLIC_HEADERS})
ADD_LIBRARY(${LIB_NAME}
${OPENTHREADS_USER_DEFINED_DYNAMIC_OR_STATIC}
${LIB_PUBLIC_HEADERS}
PThread.cpp
SET(TARGET_SRC
PThread.cpp
PThreadBarrier.cpp
PThreadBarrierPrivateData.h
PThreadCondition.cpp
@ -22,126 +20,145 @@ ADD_LIBRARY(${LIB_NAME}
../common/Version.cpp
../common/Atomic.cpp
)
IF(OPENTHREADS_SONAMES)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${OPENTHREADS_VERSION} SOVERSION ${OPENTHREADS_SOVERSION})
ENDIF()
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)
IF(HAVE_PTHREAD_YIELD)
ADD_DEFINITIONS(-DHAVE_PTHREAD_YIELD)
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()
# sched_yield appears not in libc, pthreads or whatever on some systems
CHECK_FUNCTION_EXISTS(sched_yield HAVE_SCHED_YIELD)
IF(NOT HAVE_SCHED_YIELD)
CHECK_LIBRARY_EXISTS(rt sched_yield "" HAVE_SCHED_YIELD)
IF(HAVE_SCHED_YIELD)
SET(CMAKE_THREAD_LIBS_INIT "${CMAKE_THREAD_LIBS_INIT} -lrt")
# should check?
ADD_DEFINITIONS(-DHAVE_PTHREAD_TESTCANCEL)
ADD_DEFINITIONS(-DHAVE_PTHREAD_CANCEL)
ADD_DEFINITIONS(-DHAVE_PTHREAD_SETCANCELSTATE)
CHECK_FUNCTION_EXISTS(pthread_yield HAVE_PTHREAD_YIELD)
IF(HAVE_PTHREAD_YIELD)
ADD_DEFINITIONS(-DHAVE_PTHREAD_YIELD)
ELSE()
# sched_yield appears not in libc, pthreads or whatever on some systems
CHECK_FUNCTION_EXISTS(sched_yield HAVE_SCHED_YIELD)
IF(NOT HAVE_SCHED_YIELD)
CHECK_LIBRARY_EXISTS(rt sched_yield "" HAVE_SCHED_YIELD)
IF(HAVE_SCHED_YIELD)
SET(CMAKE_THREAD_LIBS_INIT "${CMAKE_THREAD_LIBS_INIT} -lrt")
ENDIF()
ENDIF()
IF(HAVE_SCHED_YIELD)
ADD_DEFINITIONS(-DHAVE_SCHED_YIELD)
ENDIF()
ENDIF()
ENDIF()
IF(HAVE_SCHED_YIELD)
ADD_DEFINITIONS(-DHAVE_SCHED_YIELD)
ENDIF()
ENDIF()
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# need to have that for pthread_setaffinity_np on linux
ADD_DEFINITIONS(-D_GNU_SOURCE)
SET(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE")
ENDIF()
CHECK_FUNCTION_EXISTS(pthread_setconcurrency HAVE_PTHREAD_SETCONCURRENCY)
IF(HAVE_PTHREAD_SETCONCURRENCY)
ADD_DEFINITIONS(-DHAVE_PTHREAD_SETCONCURRENCY)
ENDIF()
CHECK_FUNCTION_EXISTS(pthread_getconcurrency HAVE_PTHREAD_GETCONCURRENCY)
IF(HAVE_PTHREAD_GETCONCURRENCY)
ADD_DEFINITIONS(-DHAVE_PTHREAD_GETCONCURRENCY)
ENDIF()
CHECK_FUNCTION_EXISTS(pthread_setaffinity_np HAVE_PTHREAD_SETAFFINITY_NP)
IF(HAVE_PTHREAD_SETAFFINITY_NP)
# double check that pthread_setaffinity_np is available as FreeBSD header doesn't contain required function
CHECK_CXX_SOURCE_COMPILES("
#include <pthread.h>
int main() {
cpu_set_t cpumask;
CPU_ZERO( &cpumask );
CPU_SET( 0, &cpumask );
pthread_setaffinity_np( pthread_self(), sizeof(cpumask), &cpumask);
return 0;
}" COMPILES_PTHREAD_SETAFFINITY_NP)
IF (NOT COMPILES_PTHREAD_SETAFFINITY_NP)
SET(HAVE_PTHREAD_SETAFFINITY_NP OFF)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# need to have that for pthread_setaffinity_np on linux
ADD_DEFINITIONS(-D_GNU_SOURCE)
SET(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE")
ENDIF()
ENDIF()
IF(HAVE_PTHREAD_SETAFFINITY_NP)
ADD_DEFINITIONS(-DHAVE_PTHREAD_SETAFFINITY_NP)
ELSE()
CHECK_CXX_SOURCE_COMPILES("
#include <sched.h>
int main() {
cpu_set_t cpumask;
sched_setaffinity( 0, sizeof(cpumask), &cpumask );
return 0;
}" HAVE_THREE_PARAM_SCHED_SETAFFINITY)
IF(HAVE_THREE_PARAM_SCHED_SETAFFINITY)
ADD_DEFINITIONS(-DHAVE_THREE_PARAM_SCHED_SETAFFINITY)
ELSE()
CHECK_CXX_SOURCE_COMPILES("
#include <sched.h>
int main() {
cpu_set_t cpumask;
sched_setaffinity( 0, &cpumask );
return 0;
}" HAVE_TWO_PARAM_SCHED_SETAFFINITY)
IF(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
ADD_DEFINITIONS(-DHAVE_TWO_PARAM_SCHED_SETAFFINITY)
CHECK_FUNCTION_EXISTS(pthread_setconcurrency HAVE_PTHREAD_SETCONCURRENCY)
IF(HAVE_PTHREAD_SETCONCURRENCY)
ADD_DEFINITIONS(-DHAVE_PTHREAD_SETCONCURRENCY)
ENDIF()
ENDIF()
ENDIF()
SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_SAFE}")
CHECK_FUNCTION_EXISTS(pthread_getconcurrency HAVE_PTHREAD_GETCONCURRENCY)
IF(HAVE_PTHREAD_GETCONCURRENCY)
ADD_DEFINITIONS(-DHAVE_PTHREAD_GETCONCURRENCY)
ENDIF()
TARGET_LINK_LIBRARIES(${LIB_NAME}
${CMAKE_THREAD_LIBS_INIT}
)
CHECK_FUNCTION_EXISTS(pthread_setaffinity_np HAVE_PTHREAD_SETAFFINITY_NP)
IF(HAVE_PTHREAD_SETAFFINITY_NP)
# double check that pthread_setaffinity_np is available as FreeBSD header doesn't contain required function
CHECK_CXX_SOURCE_COMPILES("
#include <pthread.h>
int main() {
cpu_set_t cpumask;
CPU_ZERO( &cpumask );
CPU_SET( 0, &cpumask );
pthread_setaffinity_np( pthread_self(), sizeof(cpumask), &cpumask);
return 0;
}" COMPILES_PTHREAD_SETAFFINITY_NP)
# Since we're building different platforms binaries in
# their respective directories, we need to set the
# link directory so it can find this location.
LINK_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
)
IF (NOT COMPILES_PTHREAD_SETAFFINITY_NP)
SET(HAVE_PTHREAD_SETAFFINITY_NP OFF)
ENDIF()
ENDIF()
INSTALL(
TARGETS OpenThreads
ARCHIVE DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads-dev
LIBRARY DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads
RUNTIME DESTINATION bin COMPONENT libopenthreads
)
IF(HAVE_PTHREAD_SETAFFINITY_NP)
ADD_DEFINITIONS(-DHAVE_PTHREAD_SETAFFINITY_NP)
ELSE()
CHECK_CXX_SOURCE_COMPILES("
#include <sched.h>
int main() {
cpu_set_t cpumask;
sched_setaffinity( 0, sizeof(cpumask), &cpumask );
return 0;
}" HAVE_THREE_PARAM_SCHED_SETAFFINITY)
IF(HAVE_THREE_PARAM_SCHED_SETAFFINITY)
ADD_DEFINITIONS(-DHAVE_THREE_PARAM_SCHED_SETAFFINITY)
ELSE()
CHECK_CXX_SOURCE_COMPILES("
#include <sched.h>
int main() {
cpu_set_t cpumask;
sched_setaffinity( 0, &cpumask );
return 0;
}" HAVE_TWO_PARAM_SCHED_SETAFFINITY)
IF(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
ADD_DEFINITIONS(-DHAVE_TWO_PARAM_SCHED_SETAFFINITY)
ENDIF()
ENDIF()
ENDIF()
IF(NOT OSG_COMPILE_FRAMEWORKS)
INSTALL(
FILES ${OpenThreads_PUBLIC_HEADERS}
DESTINATION include/OpenThreads
COMPONENT libopenthreads-dev
)
SET(CMAKE_REQUIRED_LIBRARIES_SAFE "${CMAKE_REQUIRED_LIBRARIES}")
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
ELSE()
MESSAGE("Will compile OpenThreads.framework!")
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION ${OPENTHREADS_SOVERSION}
PUBLIC_HEADER "${OpenThreads_PUBLIC_HEADERS}"
INSTALL_NAME_DIR "${OSG_COMPILE_FRAMEWORKS_INSTALL_NAME_DIR}"
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}")
TARGET_LINK_LIBRARIES(${LIB_NAME}
${CMAKE_THREAD_LIBS_INIT}
)
# Since we're building different platforms binaries in
# their respective directories, we need to set the
# link directory so it can find this location.
LINK_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
)
INSTALL(
TARGETS OpenThreads
ARCHIVE DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads-dev
LIBRARY DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads
RUNTIME DESTINATION bin COMPONENT libopenthreads
)
IF(NOT OSG_COMPILE_FRAMEWORKS)
INSTALL(
FILES ${OpenThreads_PUBLIC_HEADERS}
DESTINATION include/OpenThreads
COMPONENT libopenthreads-dev
)
ELSE()
MESSAGE("Will compile OpenThreads.framework!")
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION ${OPENTHREADS_SOVERSION}
PUBLIC_HEADER "${OpenThreads_PUBLIC_HEADERS}"
INSTALL_NAME_DIR "${OSG_COMPILE_FRAMEWORKS_INSTALL_NAME_DIR}"
)
ENDIF()
ENDIF()
#commented out# INCLUDE(ModuleInstall OPTIONAL)

View File

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

View File

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

View File

@ -9,6 +9,7 @@
#include "memory.h"
#include "BITSET.h"
#include <cstring>
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}")
ENDIF()
SET(TARGET_LIBRARIES_VARS
QT_QTCORE_LIBRARY
QT_QTGUI_LIBRARY
QT_QTOPENGL_LIBRARY
SET(TARGET_LIBRARIES
${TARGET_LIBRARIES}
${QT_QTCORE_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})
SETUP_LIBRARY(${LIB_NAME})

View File

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