diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..8d383752cc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,834 @@ +cmake_minimum_required(VERSION 2.8.8) +project(PPSSPP) + +if(ANDROID OR BLACKBERRY) + set(HEADLESS OFF) +endif() + +if(ANDROID_ABI) + set(ANDROID ON) + if(ARMEABI OR ARMEABI_V7A) + set(ARM ON) + endif() +endif() + +if(BLACKBERRY) + set(ARM ON) +endif() + +# User-editable options (go into CMakeCache.txt) +option(ARM "Set to ON if targeting an ARM processor" ${ARM}) +option(ANDROID "Set to ON if targeting an Android phone" ${ANDROID}) +option(BLACKBERRY "Set to ON if targeting a Blackberry phone" ${BLACKBERRY}) +option(HEADLESS "Set to OFF to not generate the PPSSPPHeadless target" ${HEADLESS}) + +if(ANDROID) + if(NOT ANDROID_ABI) + message(FATAL_ERROR +"CMAKE_TOOLCHAIN_FILE was not set!! +Delete the CMakeCache.txt file and CMakeFiles directory. +Rerun ${CMAKE_COMMAND} with the +\"-DCMAKE_TOOLCHAIN_FILE=${CMAKE_SOURCE_DIR}/android/android.toolchain.cmake\" +argument") + endif() + set(CoreLibName ppsspp_jni) + set(CoreLinkType SHARED) +else() + set(CoreLibName Core) + set(CoreLinkType STATIC) +endif() + +#find_package(Qt5Widgets) +if(ANDROID OR BLACKBERRY) + set(OPENGL_LIBRARIES GLESv2) + set(OPENSL_LIBRARIES OpenSLES) +else() + include(FindOpenGL REQUIRED) +endif() +include(FindSDL) +include(FindThreads) + +# needed for Globals.h +include_directories("${CMAKE_SOURCE_DIR}") + +# TODO: Rely on compiler define instead. __BLACKBERRY__ ? +if(BLACKBERRY) + add_definitions(-DBLACKBERRY) + if(BLACKBERRY VERSION_GREATER 10) + add_definitions(-DBLACKBERRY10) + endif() +endif() + +if(ANDROID) + add_definitions(-DANDROID) +endif() + +if(ARM) + add_definitions(-DARM) +endif() + +#add_definitions(-Wno-multichar) +#add_definitions(-fno-strict-aliasing) +#add_definitions(-DUSE_PROFILER) + +if(NOT MSVC) + add_definitions(-D_XOPEN_SOURCE=600 -D__BSD_VISIBLE=1) + add_definitions(-D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64) + + if(BLACKBERRY) + add_definitions(-D_QNX_SOURCE=1 -D_C99=1) + endif() + + if(NOT ARM) # ASSUMES x86!! + # enable sse2 code generation + add_definitions(-msse2) + endif() + + if(CMAKE_COMPILER_IS_GNUCXX AND + CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.0) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + endif() +endif() + +if(MSVC) + # disable warnings about MS-specific _s variants of libc functions + add_definitions(-D_CRT_SECURE_NO_WARNINGS) +endif() + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") + +if(ANDROID) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/android/libs/${ANDROID_ABI}") +endif() + +# This sets up the MSVC project dirs according to the physical project dirs +macro(setup_target_project TargetName ProjectDir) + get_property(TargetSources TARGET "${TargetName}" PROPERTY SOURCES) + foreach(Source ${TargetSources}) + # Figure out the file's path relative to the ProjectDir + # NOTE: &#$@ double-quoted regexps + string(REGEX REPLACE "${ProjectDir}" "" RelativePath "${Source}") + string(REGEX REPLACE "[\\\\/][^\\\\/]*$" "" RelativePath "${RelativePath}") + string(REGEX REPLACE "^[\\\\/]" "" RelativePath "${RelativePath}") + string(REGEX REPLACE "/" "\\\\\\\\" RelativePath "${RelativePath}") + # put the source file in a source_group equivalent to the relative path + source_group("${RelativePath}" FILES ${Source}) + endforeach() +endmacro() + +# Commented-out files are files that don't compile +# and were disabled in the original MSVC project anyway + +set(CommonExtra) +if(ARM) + set(CommonExtra ${CommonExtra} + Common/ArmABI.h + Common/ArmABI.cpp + Common/ArmEmitter.h + Common/ArmEmitter.cpp + Common/ThunkARM.cpp) +else() + set(CommonExtra ${CommonExtra} + Common/ABI.cpp + Common/ABI.h + Common/CPUDetect.cpp + Common/CPUDetect.h + Common/MathUtil.cpp + Common/MathUtil.h + Common/Thunk.cpp + Common/Thunk.h + Common/x64Analyzer.cpp + Common/x64Analyzer.h + Common/x64Emitter.cpp + Common/x64Emitter.h) +endif() +if(WIN32) + set(CommonExtra ${CommonExtra} + Common/stdafx.cpp + Common/stdafx.h) +endif() + +add_library(Common STATIC + ${CommonExtra} + Common/Action.cpp + Common/Action.h + Common/ColorUtil.cpp + Common/ColorUtil.h + Common/ConsoleListener.cpp + Common/ConsoleListener.h + Common/Crypto/aes_cbc.cpp + Common/Crypto/aes_core.cpp + Common/Crypto/bn.cpp + Common/Crypto/ec.cpp + Common/Crypto/md5.cpp + Common/Crypto/md5.h + Common/Crypto/sha1.cpp + Common/Crypto/sha1.h + Common/ExtendedTrace.cpp + Common/ExtendedTrace.h + Common/FPURoundModeGeneric.cpp +# Common/FPURoundModeX86.cpp + Common/FileSearch.cpp + Common/FileSearch.h + Common/FileUtil.cpp + Common/FileUtil.h + Common/Hash.cpp + Common/Hash.h + Common/IniFile.cpp + Common/IniFile.h + Common/LogManager.cpp + Common/LogManager.h + Common/MemArena.cpp + Common/MemArena.h + Common/MemoryUtil.cpp + Common/MemoryUtil.h + Common/Misc.cpp + Common/MsgHandler.cpp + Common/MsgHandler.h + Common/StringUtil.cpp + Common/StringUtil.h + Common/Thread.cpp + Common/Thread.h + Common/Timer.cpp + Common/Timer.h + Common/Version.cpp) +include_directories(Common) +setup_target_project(Common Common) + +if(WIN32) + target_link_libraries(Common winmm) +endif() + +add_library(zlib STATIC + ext/zlib/adler32.c + ext/zlib/compress.c + ext/zlib/crc32.c + ext/zlib/crc32.h + ext/zlib/deflate.c + ext/zlib/deflate.h + ext/zlib/gzclose.c + ext/zlib/gzguts.h + ext/zlib/gzlib.c + ext/zlib/gzread.c + ext/zlib/gzwrite.c + ext/zlib/infback.c + ext/zlib/inffast.c + ext/zlib/inffast.h + ext/zlib/inffixed.h + ext/zlib/inflate.c + ext/zlib/inflate.h + ext/zlib/inftrees.c + ext/zlib/inftrees.h + ext/zlib/make_vms.com + ext/zlib/trees.c + ext/zlib/trees.h + ext/zlib/uncompr.c + ext/zlib/zconf.h + ext/zlib/zlib.h + ext/zlib/zutil.c + ext/zlib/zutil.h +) +include_directories(ext/zlib) + +add_library(etcpack STATIC + native/ext/etcpack/etcdec.cpp + native/ext/etcpack/etcdec.h + native/ext/etcpack/etcpack.cpp + native/ext/etcpack/etcpack.h + native/ext/etcpack/image.cpp + native/ext/etcpack/image.h) +include_directories(native/ext/etcpack) + +if(NOT ANDROID AND NOT BLACKBERRY) + include_directories(${OPENGL_INCLUDE_DIR}) + + add_definitions(-DGLEW_STATIC) + add_library(glew STATIC + native/ext/glew/GL/glew.h + native/ext/glew/GL/glxew.h + native/ext/glew/GL/wglew.h + native/ext/glew/glew.c) + target_link_libraries(glew ${OPENGL_LIBRARIES}) + include_directories(native/ext/glew) + set(GLEW_LIBRARIES glew) +endif() + +add_library(sha1 STATIC + native/ext/sha1/sha1.cpp + native/ext/sha1/sha1.h) +include_directories(native/ext/sha1) + +add_library(stb_image STATIC + native/ext/stb_image/stb_image.c + native/ext/stb_image/stb_image.h) +include_directories(native/ext/stb_image) + +add_library(stb_vorbis STATIC + native/ext/stb_vorbis/stb_vorbis.c + native/ext/stb_vorbis/stb_vorbis.h) +include_directories(native/ext/stb_vorbis) + +if(NOT WIN32) # should be ANDROID, but native/file/zip_read.h depends on this + add_library(libzip STATIC + native/ext/libzip/zip.h + native/ext/libzip/mkstemp.c + native/ext/libzip/zip_add.c + native/ext/libzip/zip_add_dir.c + native/ext/libzip/zip_close.c + native/ext/libzip/zip_delete.c + native/ext/libzip/zip_dirent.c + native/ext/libzip/zip_entry_free.c + native/ext/libzip/zip_entry_new.c + native/ext/libzip/zip_err_str.c + native/ext/libzip/zip_error.c + native/ext/libzip/zip_error_clear.c + native/ext/libzip/zip_error_get.c + native/ext/libzip/zip_error_get_sys_type.c + native/ext/libzip/zip_error_strerror.c + native/ext/libzip/zip_error_to_str.c + native/ext/libzip/zip_fclose.c + native/ext/libzip/zip_file_error_clear.c + native/ext/libzip/zip_file_error_get.c + native/ext/libzip/zip_file_get_offset.c + native/ext/libzip/zip_file_strerror.c + native/ext/libzip/zip_filerange_crc.c + native/ext/libzip/zip_fopen.c + native/ext/libzip/zip_fopen_index.c + native/ext/libzip/zip_fread.c + native/ext/libzip/zip_free.c + native/ext/libzip/zip_get_archive_comment.c + native/ext/libzip/zip_get_archive_flag.c + native/ext/libzip/zip_get_file_comment.c + native/ext/libzip/zip_get_name.c + native/ext/libzip/zip_get_num_files.c + native/ext/libzip/zip_memdup.c + native/ext/libzip/zip_name_locate.c + native/ext/libzip/zip_new.c + native/ext/libzip/zip_open.c + native/ext/libzip/zip_rename.c + native/ext/libzip/zip_replace.c + native/ext/libzip/zip_set_archive_comment.c + native/ext/libzip/zip_set_archive_flag.c + native/ext/libzip/zip_set_file_comment.c + native/ext/libzip/zip_set_name.c + native/ext/libzip/zip_source_buffer.c + native/ext/libzip/zip_source_file.c + native/ext/libzip/zip_source_filep.c + native/ext/libzip/zip_source_free.c + native/ext/libzip/zip_source_function.c + native/ext/libzip/zip_source_zip.c + native/ext/libzip/zip_stat.c + native/ext/libzip/zip_stat_index.c + native/ext/libzip/zip_stat_init.c + native/ext/libzip/zip_strerror.c + native/ext/libzip/zip_unchange.c + native/ext/libzip/zip_unchange_all.c + native/ext/libzip/zip_unchange_archive.c + native/ext/libzip/zip_unchange_data.c) + target_link_libraries(libzip zlib) + include_directories(native/ext/libzip) + set(LIBZIP libzip) +endif() + +set(nativeExtra) +if(ANDROID) + set(nativeExtra ${nativeExtra} + native/base/NativeApp.h + native/android/app-android.cpp + native/android/native_audio.cpp + native/android/native_audio.h) + + add_library(native_audio SHARED + native/android/native-audio-so.cpp + native/android/native-audio-so.h) + target_link_libraries(native_audio + ${OPENSL_LIBRARIES}) +endif() +if(BLACKBERRY) + set(nativeExtra ${nativeExtra} + native/base/BlackberryMain.cpp) +endif() + +if(NOT ARM) + set(nativeExtra ${nativeExtra} + native/base/backtrace.cpp + native/base/backtrace.h) +endif() + +add_library(native STATIC + ${nativeExtra} + native/audio/mixer.cpp + native/audio/mixer.h + native/audio/wav_read.cpp + native/audio/wav_read.h + native/base/basictypes.h + native/base/buffer.cpp + native/base/buffer.h + native/base/color.h + native/base/colorutil.cpp + native/base/colorutil.h + native/base/display.cpp + native/base/display.h + native/base/error_context.cpp + native/base/error_context.h + native/base/fastlist.h + native/base/fastlist_test.cpp + native/base/linked_ptr.h + native/base/logging.h + native/base/mutex.h +# native/base/PCMain.cpp + native/base/scoped_ptr.h + native/base/stats.h + native/base/stringutil.cpp + native/base/stringutil.h + native/base/threadutil.cpp + native/base/threadutil.h + native/base/timeutil.cpp + native/base/timeutil.h + native/file/chunk_file.cpp + native/file/chunk_file.h + native/file/dialog.cpp + native/file/dialog.h + native/file/easy_file.cpp + native/file/easy_file.h + native/file/fd_util.cpp + native/file/fd_util.h + native/file/file_util.cpp + native/file/file_util.h + native/file/vfs.h + native/file/zip_read.cpp + native/file/zip_read.h + native/gfx/gl_debug_log.cpp + native/gfx/gl_debug_log.h + native/gfx/gl_lost_manager.cpp + native/gfx/gl_lost_manager.h + native/gfx/texture.cpp + native/gfx/texture.h + native/gfx/texture_atlas.cpp + native/gfx/texture_atlas.h +# native/gfx/texture_dx11.cpp + native/gfx/texture_gen.cpp + native/gfx/texture_gen.h + native/gfx_es2/draw_buffer.cpp + native/gfx_es2/draw_buffer.h + native/gfx_es2/fbo.cpp + native/gfx_es2/fbo.h + native/gfx_es2/glsl_program.cpp + native/gfx_es2/glsl_program.h + native/gfx_es2/vertex_format.cpp + native/gfx_es2/vertex_format.h + native/image/png_load.cpp + native/image/png_load.h + native/image/zim_load.cpp + native/image/zim_load.h + native/image/zim_save.cpp + native/image/zim_save.h + native/input/gesture_detector.cpp + native/input/gesture_detector.h + native/input/input_state.h + native/json/json_writer.cpp + native/json/json_writer.h + native/math/compression.h + native/math/curves.cpp + native/math/curves.h + native/math/lin/aabb.cpp + native/math/lin/aabb.h + native/math/lin/matrix4x4.cpp + native/math/lin/matrix4x4.h + native/math/lin/plane.cpp + native/math/lin/plane.h + native/math/lin/quat.cpp + native/math/lin/quat.h + native/math/lin/ray.h + native/math/lin/vec3.cpp + native/math/lin/vec3.h + native/math/math_util.cpp + native/math/math_util.h + native/midi/midi_input.cpp + native/midi/midi_input.h + native/net/http_client.cpp + native/net/http_client.h + native/net/resolve.cpp + native/net/resolve.h + native/profiler/profiler.cpp + native/profiler/profiler.h + native/ui/screen.cpp + native/ui/screen.h + native/ui/ui.cpp + native/ui/ui.h + native/ui/virtual_input.cpp + native/ui/virtual_input.h + native/util/bits/bits.cpp + native/util/bits/bits.h + native/util/bits/hamming.h + native/util/bits/varint.cpp + native/util/bits/varint.h + native/util/hash/hash.cpp + native/util/hash/hash.h + native/util/random/perlin.cpp + native/util/random/perlin.h + native/util/random/rng.h + native/ext/rapidxml/rapidxml.hpp + native/ext/rapidxml/rapidxml_iterators.hpp + native/ext/rapidxml/rapidxml_print.hpp + native/ext/rapidxml/rapidxml_utils.hpp) +include_directories(native) +# rapidxml is headers only so we can't make a lib specific for it +include_directories(native/ext/rapidxml) +target_link_libraries(native ${LIBZIP} + etcpack sha1 stb_image stb_vorbis #vjson + zlib ${GLEW_LIBRARIES}) +if(ANDROID) + target_link_libraries(native log) +endif() +setup_target_project(native native) + +if(WIN32) + target_link_libraries(native ws2_32 winmm) +endif() + +add_library(kirk STATIC + ext/libkirk/AES.c + ext/libkirk/AES.h + ext/libkirk/SHA1.c + ext/libkirk/SHA1.h + ext/libkirk/bn.c + ext/libkirk/ec.c + ext/libkirk/kirk_engine.c + ext/libkirk/kirk_engine.h) +include_directories(ext/libkirk) + +set(CoreExtra) +if(ARM) + set(CoreExtra ${CoreExtra} + Core/MIPS/ARM/Asm.cpp + Core/MIPS/ARM/Asm.h + Core/MIPS/ARM/CompALU.cpp + Core/MIPS/ARM/CompBranch.cpp + Core/MIPS/ARM/CompFPU.cpp + Core/MIPS/ARM/CompLoadStore.cpp + Core/MIPS/ARM/CompVFPU.cpp + Core/MIPS/ARM/Jit.cpp + Core/MIPS/ARM/Jit.h + Core/MIPS/ARM/JitCache.cpp + Core/MIPS/ARM/JitCache.h + Core/MIPS/ARM/RegCache.cpp + Core/MIPS/ARM/RegCache.h) +else() # ASSUMES x86!! + set(CoreExtra ${CoreExtra} + Core/MIPS/x86/Asm.cpp + Core/MIPS/x86/Asm.h + Core/MIPS/x86/CompALU.cpp + Core/MIPS/x86/CompBranch.cpp + Core/MIPS/x86/CompFPU.cpp + Core/MIPS/x86/CompLoadStore.cpp + Core/MIPS/x86/CompVFPU.cpp + Core/MIPS/x86/Jit.cpp + Core/MIPS/x86/Jit.h + Core/MIPS/x86/JitCache.cpp + Core/MIPS/x86/JitCache.h + Core/MIPS/x86/RegCache.cpp + Core/MIPS/x86/RegCache.h) +endif() + +# 'ppsspp_jni' on ANDROID, 'Core' everywhere else +# SHARED on ANDROID, STATIC everywhere else +add_library(${CoreLibName} ${CoreLinkType} + ${CoreExtra} + Core/CPU.cpp + Core/CPU.h + Core/Config.cpp + Core/Config.h + Core/Core.cpp + Core/Core.h + Core/CoreParameter.h + Core/CoreTiming.cpp + Core/CoreTiming.h + Core/Debugger/Breakpoints.cpp + Core/Debugger/Breakpoints.h + Core/Debugger/DebugInterface.h + Core/Debugger/SymbolMap.cpp + Core/Debugger/SymbolMap.h + Core/ELF/ElfReader.cpp + Core/ELF/ElfReader.h + Core/ELF/ElfTypes.h + Core/ELF/PrxDecrypter.cpp + Core/ELF/PrxDecrypter.h + Core/FileSystems/BlockDevices.cpp + Core/FileSystems/BlockDevices.h + Core/FileSystems/DirectoryFileSystem.cpp + Core/FileSystems/DirectoryFileSystem.h + Core/FileSystems/FileSystem.h + Core/FileSystems/ISOFileSystem.cpp + Core/FileSystems/ISOFileSystem.h + Core/FileSystems/MetaFileSystem.cpp + Core/FileSystems/MetaFileSystem.h + Core/HLE/FunctionWrappers.h + Core/HLE/HLE.cpp + Core/HLE/HLE.h + Core/HLE/HLETables.cpp + Core/HLE/HLETables.h + Core/HLE/__sceAudio.cpp + Core/HLE/__sceAudio.h + Core/HLE/sceAtrac.cpp + Core/HLE/sceAtrac.h + Core/HLE/sceAudio.cpp + Core/HLE/sceAudio.h + Core/HLE/sceCtrl.cpp + Core/HLE/sceCtrl.h + Core/HLE/sceDisplay.cpp + Core/HLE/sceDisplay.h + Core/HLE/sceDmac.cpp + Core/HLE/sceDmac.h + Core/HLE/sceGe.cpp + Core/HLE/sceGe.h + Core/HLE/sceHprm.cpp + Core/HLE/sceHprm.h + Core/HLE/sceHttp.cpp + Core/HLE/sceHttp.h + Core/HLE/sceImpose.cpp + Core/HLE/sceImpose.h + Core/HLE/sceIo.cpp + Core/HLE/sceIo.h + Core/HLE/sceKernel.cpp + Core/HLE/sceKernel.h + Core/HLE/sceKernelAlarm.cpp + Core/HLE/sceKernelAlarm.h + Core/HLE/sceKernelEventFlag.cpp + Core/HLE/sceKernelEventFlag.h + Core/HLE/sceKernelInterrupt.cpp + Core/HLE/sceKernelInterrupt.h + Core/HLE/sceKernelMbx.cpp + Core/HLE/sceKernelMbx.h + Core/HLE/sceKernelMemory.cpp + Core/HLE/sceKernelMemory.h + Core/HLE/sceKernelModule.cpp + Core/HLE/sceKernelModule.h + Core/HLE/sceKernelMsgPipe.cpp + Core/HLE/sceKernelMsgPipe.h + Core/HLE/sceKernelMutex.cpp + Core/HLE/sceKernelMutex.h + Core/HLE/sceKernelSemaphore.cpp + Core/HLE/sceKernelSemaphore.h + Core/HLE/sceKernelThread.cpp + Core/HLE/sceKernelThread.h + Core/HLE/sceKernelTime.cpp + Core/HLE/sceKernelTime.h + Core/HLE/sceKernelVTimer.cpp + Core/HLE/sceKernelVTimer.h + Core/HLE/sceMpeg.cpp + Core/HLE/sceMpeg.h + Core/HLE/sceNet.cpp + Core/HLE/sceNet.h + Core/HLE/scePower.cpp + Core/HLE/scePower.h + Core/HLE/scePsmf.cpp + Core/HLE/scePsmf.h + Core/HLE/sceRtc.cpp + Core/HLE/sceRtc.h + Core/HLE/sceSas.cpp + Core/HLE/sceSas.h + Core/HLE/sceUmd.cpp + Core/HLE/sceUmd.h + Core/HLE/sceUtility.cpp + Core/HLE/sceUtility.h + Core/HW/MemoryStick.cpp + Core/HW/MemoryStick.h + Core/Host.cpp + Core/Host.h + Core/Loaders.cpp + Core/Loaders.h + Core/MIPS/JitCommon/JitCommon.cpp + Core/MIPS/JitCommon/JitCommon.h + Core/MIPS/MIPS.cpp + Core/MIPS/MIPS.h + Core/MIPS/MIPSAnalyst.cpp + Core/MIPS/MIPSAnalyst.h + Core/MIPS/MIPSCodeUtils.cpp + Core/MIPS/MIPSCodeUtils.h + Core/MIPS/MIPSDebugInterface.cpp + Core/MIPS/MIPSDebugInterface.h + Core/MIPS/MIPSDis.cpp + Core/MIPS/MIPSDis.h + Core/MIPS/MIPSDisVFPU.cpp + Core/MIPS/MIPSDisVFPU.h + Core/MIPS/MIPSInt.cpp + Core/MIPS/MIPSInt.h + Core/MIPS/MIPSIntVFPU.cpp + Core/MIPS/MIPSIntVFPU.h + Core/MIPS/MIPSTables.cpp + Core/MIPS/MIPSTables.h + Core/MIPS/MIPSVFPUUtils.cpp + Core/MIPS/MIPSVFPUUtils.h + Core/MemMap.cpp + Core/MemMap.h + Core/MemMapFunctions.cpp + Core/PSPLoaders.cpp + Core/PSPLoaders.h + Core/PSPMixer.cpp + Core/PSPMixer.h + Core/System.cpp + Core/System.h + Core/Util/BlockAllocator.cpp + Core/Util/BlockAllocator.h + Core/Util/PPGeDraw.cpp + Core/Util/PPGeDraw.h + Core/Util/Pool.h + Core/Util/ppge_atlas.cpp + Core/Util/ppge_atlas.h + $ + Globals.h) +target_link_libraries(${CoreLibName} Common native kirk + ${GLEW_LIBRARIES} ${OPENGL_LIBRARIES}) +setup_target_project(${CoreLibName} Core) + +add_library(GPU OBJECT + GPU/GLES/DisplayListInterpreter.cpp + GPU/GLES/DisplayListInterpreter.h + GPU/GLES/FragmentShaderGenerator.cpp + GPU/GLES/FragmentShaderGenerator.h + GPU/GLES/Framebuffer.cpp + GPU/GLES/Framebuffer.h + GPU/GLES/ShaderManager.cpp + GPU/GLES/ShaderManager.h + GPU/GLES/TextureCache.cpp + GPU/GLES/TextureCache.h + GPU/GLES/TransformPipeline.cpp + GPU/GLES/TransformPipeline.h + GPU/GLES/VertexDecoder.cpp + GPU/GLES/VertexDecoder.h + GPU/GLES/VertexShaderGenerator.cpp + GPU/GLES/VertexShaderGenerator.h + GPU/GPUInterface.h + GPU/GPUState.cpp + GPU/GPUState.h + GPU/Math3D.cpp + GPU/Math3D.h +# GPU/Null/NullDisplayListInterpreter.cpp +# GPU/Null/NullDisplayListInterpreter.h + GPU/Null/NullGpu.cpp + GPU/Null/NullGpu.h + GPU/ge_constants.h) +setup_target_project(GPU GPU) + +if(WIN32) + add_executable(PPSSPPWindows WIN32 + Windows/Breakpoints.h + Windows/DSoundStream.cpp + Windows/DSoundStream.h + Windows/Debugger/CPURegsInterface.h + Windows/Debugger/CtrlDisAsmView.cpp + Windows/Debugger/CtrlDisAsmView.h + Windows/Debugger/CtrlMemView.cpp + Windows/Debugger/CtrlMemView.h + Windows/Debugger/CtrlRegisterList.cpp + Windows/Debugger/CtrlRegisterList.h + Windows/Debugger/Debugger.h + Windows/Debugger/Debugger_Disasm.cpp + Windows/Debugger/Debugger_Disasm.h + Windows/Debugger/Debugger_MemoryDlg.cpp + Windows/Debugger/Debugger_MemoryDlg.h + Windows/Debugger/Debugger_Misc.cpp + Windows/Debugger/Debugger_Misc.h +# Windows/Debugger/Debugger_Profiler.cpp +# Windows/Debugger/Debugger_Profiler.h + Windows/Debugger/Debugger_SymbolMap.h + Windows/Debugger/Debugger_VFPUDlg.cpp + Windows/Debugger/Debugger_VFPUDlg.h + Windows/Debugger/SimpleELF.h +# Windows/DlgDynaView.cpp +# Windows/DlgDynaView.h + Windows/EmuThread.cpp + Windows/EmuThread.h + Windows/Globals.cpp + Windows/InputBox.cpp + Windows/InputBox.h + Windows/InputDevice.cpp + Windows/InputDevice.h + Windows/KeyboardDevice.cpp + Windows/KeyboardDevice.h + Windows/MIPSCompALU.h + Windows/MIPSCompBranch.h + Windows/OpenGLBase.cpp + Windows/OpenGLBase.h + Windows/W32Util/DialogManager.cpp + Windows/W32Util/DialogManager.h + Windows/W32Util/Misc.cpp + Windows/W32Util/Misc.h + Windows/W32Util/PropertySheet.cpp + Windows/W32Util/PropertySheet.h + Windows/W32Util/ShellUtil.cpp + Windows/W32Util/ShellUtil.h + Windows/W32Util/XPTheme.h + Windows/WindowsFileSystem.h + Windows/WindowsHost.cpp + Windows/WindowsHost.h + Windows/WndMainWindow.cpp + Windows/WndMainWindow.h + Windows/XPTheme.h + Windows/XinputDevice.cpp + Windows/XinputDevice.h + Windows/main.cpp + Windows/main.h + Windows/ppsspp.rc + Windows/resource.h + Windows/stdafx.cpp + Windows/stdafx.h) + target_link_libraries(PPSSPPWindows ${CoreLibName} + kernel32 user32 gdi32 shell32 comctl32 dsound xinput) + setup_target_project(PPSSPPWindows Windows) +endif() + +if(HEADLESS) + add_executable(PPSSPPHeadless + headless/Headless.cpp) + target_link_libraries(PPSSPPHeadless ${CoreLibName} + ${CMAKE_THREAD_LIBS_INIT}) + setup_target_project(PPSSPPHeadless headless) +endif() + +if(SDL_FOUND) + include_directories(${SDL_INCLUDE_DIR}) + + set(NativeAppSource + android/jni/NativeApp.cpp + android/jni/EmuScreen.cpp + android/jni/MenuScreens.cpp + android/jni/GamepadEmu.cpp + android/jni/UIShader.cpp + android/jni/ui_atlas.cpp) + set(AndroidAssets + android/assets/ui_atlas.zim + android/assets/ppge_atlas.zim) + set(LinkCommon ${CoreLibName} + ${SDL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) + + if(BLACKBERRY) + add_executable(PPSSPPBlackberry + native/base/BlackberryMain.cpp + ${NativeAppSource}) + target_link_libraries(PPSSPPBlackberry ${LinkCommon} + bps screen socket EGL GLESv2) + elseif(ANDROID) + # no target + else() + if(APPLE) + set(SDL_Main + SDL/SDLMain.h + SDL/SDLMain.m) + else() + set(SDL_Main + native/base/PCMain.cpp) + endif() + + add_executable(PPSSPPSDL ${SDL_Main} ${NativeAppSource}) + target_link_libraries(PPSSPPSDL ${LinkCommon}) + endif() + + file(INSTALL ${AndroidAssets} DESTINATION assets) +endif() + +#include(CPack) diff --git a/Common/ArmEmitter.cpp b/Common/ArmEmitter.cpp index 0928b3d8f8..17ef8e711f 100644 --- a/Common/ArmEmitter.cpp +++ b/Common/ArmEmitter.cpp @@ -61,7 +61,7 @@ const u8 *ARMXEmitter::AlignCodePage() void ARMXEmitter::Flush() { - __clear_cache (startcode, code); + __builtin___clear_cache (startcode, code); SLEEP(0); } void ARMXEmitter::SetCC(CCFlags cond) diff --git a/Common/CPUDetect.cpp b/Common/CPUDetect.cpp index 8222117669..ea04ca0704 100644 --- a/Common/CPUDetect.cpp +++ b/Common/CPUDetect.cpp @@ -93,6 +93,10 @@ CPUInfo::CPUInfo() { Detect(); } +#ifdef _WIN32 +#include +#endif + // Detects the various cpu features void CPUInfo::Detect() { diff --git a/Common/FileUtil.cpp b/Common/FileUtil.cpp index e2eb22a3ff..ebe0d12de1 100644 --- a/Common/FileUtil.cpp +++ b/Common/FileUtil.cpp @@ -48,7 +48,7 @@ #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) #endif -#ifdef BSD4_4 +#if !defined(__linux__) && !defined(_WIN32) && !defined(__QNX__) #define stat64 stat #define fstat64 fstat #endif diff --git a/Common/IniFile.cpp b/Common/IniFile.cpp index e8408f0dac..ff867a01b2 100644 --- a/Common/IniFile.cpp +++ b/Common/IniFile.cpp @@ -19,6 +19,10 @@ #include #include +#ifndef _MSC_VER +#include +#endif + #include #include #include diff --git a/Common/MemoryUtil.cpp b/Common/MemoryUtil.cpp index 2a8008f226..a47a0bbb14 100644 --- a/Common/MemoryUtil.cpp +++ b/Common/MemoryUtil.cpp @@ -25,11 +25,8 @@ #else #include #include +#endif #include -#ifndef __APPLE__ -#include -#endif -#endif #if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT) diff --git a/Common/Misc.cpp b/Common/Misc.cpp index ea749d1a7b..53f37c2bf2 100644 --- a/Common/Misc.cpp +++ b/Common/Misc.cpp @@ -21,6 +21,10 @@ #define __thread #endif +#ifdef _WIN32 +#include +#endif + // Generic function to get last error message. // Call directly after the command or use the error num. // This function might change the error code. diff --git a/Common/MsgHandler.cpp b/Common/MsgHandler.cpp index fcc48e7c2d..5277064b06 100644 --- a/Common/MsgHandler.cpp +++ b/Common/MsgHandler.cpp @@ -98,6 +98,10 @@ bool MsgAlert(bool yes_no, int Style, const char* format, ...) return true; } +#ifdef _WIN32 +#include +#endif + // Default non library dependent panic alert bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style) { diff --git a/Common/x64Emitter.h b/Common/x64Emitter.h index 9e9c39f110..816a82e90a 100644 --- a/Common/x64Emitter.h +++ b/Common/x64Emitter.h @@ -24,7 +24,7 @@ #include "MemoryUtil.h" #if !defined(_M_IX86) && !defined(_M_X64) -#error Don't build this on arm. +#error "Don't build this on arm." #endif namespace Gen diff --git a/Core/MIPS/MIPSIntVFPU.cpp b/Core/MIPS/MIPSIntVFPU.cpp index e170fd2166..51264ba65c 100644 --- a/Core/MIPS/MIPSIntVFPU.cpp +++ b/Core/MIPS/MIPSIntVFPU.cpp @@ -26,10 +26,6 @@ #include -#ifndef _MSC_VER -using std::isnan; -#endif - #define R(i) (currentMIPS->r[i]) #define RF(i) (*(float*)(&(currentMIPS->r[i]))) #define V(i) (currentMIPS->v[i]) diff --git a/SDL/bar-descriptor.xml b/SDL/bar-descriptor.xml index d56d018c55..7bbb7d9a98 100644 --- a/SDL/bar-descriptor.xml +++ b/SDL/bar-descriptor.xml @@ -2,7 +2,7 @@ com.Qtness.PPSSPP PPSSPP - ppsspp + PPSSPPBlackberry 0.31 1 Playstation portable emulator. diff --git a/SDL/blackberry_package.sh b/SDL/blackberry_package.sh index b2b47e1f62..ecc905fadd 100755 --- a/SDL/blackberry_package.sh +++ b/SDL/blackberry_package.sh @@ -4,7 +4,7 @@ TYPE=Device-Release DEBUG="-devMode -debugToken ${HOME}/debugtoken.bar" PPSSPP_ROOT=${PWD}/.. WORKSPACE=${PPSSPP_ROOT}/.. -blackberry-nativepackager -package PPSSPP.bar bar-descriptor.xml ppsspp \ +blackberry-nativepackager -package PPSSPP.bar bar-descriptor.xml PPSSPPBlackberry \ -e icon-114.png icon-114.png $DEBUG \ -e ../android/assets assets \ -e ${WORKSPACE}/SDL12/${TYPE}/libSDL12.so lib/libSDL12.so \ diff --git a/Windows/DSoundStream.h b/Windows/DSoundStream.h index fce90f9956..0a52c28e0a 100644 --- a/Windows/DSoundStream.h +++ b/Windows/DSoundStream.h @@ -1,6 +1,8 @@ #ifndef __SOUNDSTREAM_H__ #define __SOUNDSTREAM_H__ +#include + namespace DSound { typedef int (*StreamCallback)(short *buffer, int numSamples, int bits, int rate, int channels); diff --git a/Windows/Debugger/CtrlDisAsmView.cpp b/Windows/Debugger/CtrlDisAsmView.cpp index 776ee08003..27ea27be2e 100644 --- a/Windows/Debugger/CtrlDisAsmView.cpp +++ b/Windows/Debugger/CtrlDisAsmView.cpp @@ -13,6 +13,9 @@ #include "../../globals.h" #include "../main.h" +#include +#include + TCHAR CtrlDisAsmView::szClassName[] = _T("CtrlDisAsmView"); extern HMENU g_hPopupMenus; diff --git a/Windows/Debugger/CtrlDisAsmView.h b/Windows/Debugger/CtrlDisAsmView.h index f72018e29b..34130c96aa 100644 --- a/Windows/Debugger/CtrlDisAsmView.h +++ b/Windows/Debugger/CtrlDisAsmView.h @@ -20,6 +20,7 @@ #include "../../Core/Debugger/DebugInterface.h" +#include class CtrlDisAsmView { diff --git a/Windows/Debugger/Debugger_Disasm.cpp b/Windows/Debugger/Debugger_Disasm.cpp index 9e67795487..b326bc75bc 100644 --- a/Windows/Debugger/Debugger_Disasm.cpp +++ b/Windows/Debugger/Debugger_Disasm.cpp @@ -21,6 +21,10 @@ #include "../XPTheme.h" #endif +#include +#include +#include + namespace MainWindow { void UpdateMenus(); diff --git a/Windows/Debugger/Debugger_Disasm.h b/Windows/Debugger/Debugger_Disasm.h index d9611308f9..6f0a398d72 100644 --- a/Windows/Debugger/Debugger_Disasm.h +++ b/Windows/Debugger/Debugger_Disasm.h @@ -10,6 +10,8 @@ #include "../../Globals.h" #include "../../Core/CPU.h" +#include + class CDisasm : public Dialog { private: diff --git a/Windows/Debugger/Debugger_MemoryDlg.h b/Windows/Debugger/Debugger_MemoryDlg.h index 92059dc078..764e8bbd3e 100644 --- a/Windows/Debugger/Debugger_MemoryDlg.h +++ b/Windows/Debugger/Debugger_MemoryDlg.h @@ -8,6 +8,8 @@ #include "../../Core/Debugger/DebugInterface.h" +#include + class CMemoryDlg : public Dialog { private: diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index da27fd6804..8b318a19cf 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -10,6 +10,9 @@ #include "../Core/System.h" #include "../Core/Config.h" +#include +#include + char fileToStart[MAX_PATH]; static HANDLE emuThread; diff --git a/Globals.cpp b/Windows/Globals.cpp similarity index 100% rename from Globals.cpp rename to Windows/Globals.cpp diff --git a/Windows/InputBox.h b/Windows/InputBox.h index 5afb3f0256..e75a0c95c5 100644 --- a/Windows/InputBox.h +++ b/Windows/InputBox.h @@ -2,5 +2,7 @@ #include "../Globals.h" +#include + bool InputBox_GetString(HINSTANCE hInst, HWND hParent, TCHAR *title, TCHAR *defaultvalue, TCHAR *outvalue); bool InputBox_GetHex(HINSTANCE hInst, HWND hParent, TCHAR *title, u32 defaultvalue, u32 &outvalue); diff --git a/Windows/InputDevice.h b/Windows/InputDevice.h index 8c50214dfc..8d651152c6 100644 --- a/Windows/InputDevice.h +++ b/Windows/InputDevice.h @@ -8,6 +8,7 @@ public: virtual int UpdateState() = 0; }; +#include #include #include std::list> getInputDevices(); diff --git a/Windows/PPSSPP.vcxproj b/Windows/PPSSPP.vcxproj index 1b399343c9..392c522cde 100644 --- a/Windows/PPSSPP.vcxproj +++ b/Windows/PPSSPP.vcxproj @@ -279,9 +279,9 @@ - - - + + + Create Create Create @@ -359,4 +359,4 @@ - \ No newline at end of file + diff --git a/Windows/W32Util/DialogManager.h b/Windows/W32Util/DialogManager.h index 8dcf5955f9..7f698186bc 100644 --- a/Windows/W32Util/DialogManager.h +++ b/Windows/W32Util/DialogManager.h @@ -1,5 +1,6 @@ #pragma once +#include class Dialog { diff --git a/Windows/W32Util/Misc.h b/Windows/W32Util/Misc.h index 175d69ea75..a1d2a2d322 100644 --- a/Windows/W32Util/Misc.h +++ b/Windows/W32Util/Misc.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace W32Util { void CenterWindow(HWND hwnd); diff --git a/Windows/W32Util/PropertySheet.cpp b/Windows/W32Util/PropertySheet.cpp index 002f8aa3ec..319521773c 100644 --- a/Windows/W32Util/PropertySheet.cpp +++ b/Windows/W32Util/PropertySheet.cpp @@ -2,6 +2,8 @@ #include "Misc.h" #include "PropertySheet.h" +#include + namespace W32Util { bool centered; diff --git a/Windows/W32Util/ShellUtil.cpp b/Windows/W32Util/ShellUtil.cpp index d378b7d605..a0cb33a2f4 100644 --- a/Windows/W32Util/ShellUtil.cpp +++ b/Windows/W32Util/ShellUtil.cpp @@ -5,6 +5,9 @@ #include "ShellUtil.h" +#include +#include + namespace W32Util { std::string BrowseForFolder(HWND parent, char *title) diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 426384a002..22f9c48795 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -5,6 +5,7 @@ #include +#include #include "../globals.h" #include "shellapi.h" diff --git a/Windows/WndMainWindow.h b/Windows/WndMainWindow.h index 2db48c759a..bc20c80132 100644 --- a/Windows/WndMainWindow.h +++ b/Windows/WndMainWindow.h @@ -1,5 +1,6 @@ #pragma once +#include namespace MainWindow { diff --git a/main.cpp b/Windows/main.cpp similarity index 100% rename from main.cpp rename to Windows/main.cpp diff --git a/Windows/main.h b/Windows/main.h index 07cae40cb6..c882f098ee 100644 --- a/Windows/main.h +++ b/Windows/main.h @@ -21,6 +21,8 @@ #include "Debugger/Debugger_Disasm.h" #include "Debugger/Debugger_MemoryDlg.h" +#include + #define MAX_CPUCOUNT 1 extern CDisasm *disasmWindow[MAX_CPUCOUNT]; diff --git a/stdafx.cpp b/Windows/stdafx.cpp similarity index 100% rename from stdafx.cpp rename to Windows/stdafx.cpp diff --git a/stdafx.h b/Windows/stdafx.h similarity index 100% rename from stdafx.h rename to Windows/stdafx.h diff --git a/android/android.toolchain.cmake b/android/android.toolchain.cmake new file mode 100644 index 0000000000..69b402670d --- /dev/null +++ b/android/android.toolchain.cmake @@ -0,0 +1,1125 @@ +# ------------------------------------------------------------------------------ +# Android CMake toolchain file, for use with the Android NDK r5-r8 +# Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended). +# See home page: http://code.google.com/p/android-cmake/ +# +# The file is mantained by the OpenCV project. And also can be found at +# http://code.opencv.org/projects/opencv/repository/revisions/master/changes/android/android.toolchain.cmake +# +# Usage Linux: +# $ export ANDROID_NDK=/absolute/path/to/the/android-ndk +# $ mkdir build && cd build +# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. +# $ make -j8 +# +# Usage Linux (using standalone toolchain): +# $ export ANDROID_STANDALONE_TOOLCHAIN=/absolute/path/to/android-toolchain +# $ mkdir build && cd build +# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. +# $ make -j8 +# +# Usage Windows: +# You need native port of make to build your project. +# Android NDK r7 (or newer) already has make.exe on board. +# For older NDK you have to install it separately. +# For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm +# +# $ SET ANDROID_NDK=C:\absolute\path\to\the\android-ndk +# $ mkdir build && cd build +# $ cmake.exe -G"MinGW Makefiles" +# -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake +# -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" .. +# $ "%ANDROID_NDK%\prebuilt\windows\bin\make.exe" +# +# +# Options (can be set as cmake parameters: -D=): +# ANDROID_NDK=/opt/android-ndk - path to the NDK root. +# Can be set as environment variable. Can be set only at first cmake run. +# +# ANDROID_STANDALONE_TOOLCHAIN=/opt/android-toolchain - path to the +# standalone toolchain. This option is not used if full NDK is found +# (ignored if ANDROID_NDK is set). +# Can be set as environment variable. Can be set only at first cmake run. +# +# ANDROID_ABI=armeabi-v7a - specifies the target Application Binary +# Interface (ABI). This option nearly matches to the APP_ABI variable +# used by ndk-build tool from Android NDK. +# +# Possible targets are: +# "armeabi" - matches to the NDK ABI with the same name. +# See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation. +# "armeabi-v7a" - matches to the NDK ABI with the same name. +# See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation. +# "armeabi-v7a with NEON" - same as armeabi-v7a, but +# sets NEON as floating-point unit +# "armeabi-v7a with VFPV3" - same as armeabi-v7a, but +# sets VFPV3 as floating-point unit (has 32 registers instead of 16). +# "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP. +# "x86" - matches to the NDK ABI with the same name. +# See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation. +# "mips" - matches to the NDK ABI with the same name +# (not testes on real devices) +# +# ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for. +# Option is read-only when standalone toolchain used. +# +# ANDROID_FORCE_ARM_BUILD=OFF - set true to generate 32-bit ARM instructions +# instead of Thumb-1. Is not available for "x86" (inapplicable) and +# "armeabi-v6 with VFP" (forced) ABIs. +# +# ANDROID_NO_UNDEFINED=ON - set true to show all undefined symbols as linker +# errors even if they are not used. +# +# ANDROID_SO_UNDEFINED=OFF - set true to allow undefined symbols in shared +# libraries. Automatically turned on for NDK r5x and r6x due to GLESv2 +# problems. +# +# LIBRARY_OUTPUT_PATH_ROOT=${CMAKE_SOURCE_DIR} - where to output binary +# files. See additional details below. +# +# ANDROID_SET_OBSOLETE_VARIABLES=ON - it set, then toolchain defines some +# obsolete variables which were set by previous versions of this file for +# backward compatibility. +# +# +# What?: +# android-cmake toolchain searches for NDK/toolchain in the following order: +# ANDROID_NDK - cmake parameter +# ANDROID_NDK - environment variable +# ANDROID_STANDALONE_TOOLCHAIN - cmake parameter +# ANDROID_STANDALONE_TOOLCHAIN - environment variable +# ANDROID_NDK - default locations +# ANDROID_STANDALONE_TOOLCHAIN - default locations +# +# Make sure to do the following in your scripts: +# SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" ) +# SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" ) +# The flags will be prepopulated with critical flags, so don't loose them. +# Also be aware that toolchain also sets configuration-specific compiler +# flags and linker flags. +# +# ANDROID and BUILD_ANDROID will be set to true, you may test any of these +# variables to make necessary Android-specific configuration changes. +# +# Also ARMEABI or ARMEABI_V7A or X86 will be set true, mutually exclusive. +# NEON option will be set true if VFP is set to NEON. +# +# LIBRARY_OUTPUT_PATH_ROOT should be set in cache to determine where Android +# libraries will be installed. +# Default is ${CMAKE_SOURCE_DIR}, and the android libs will always be +# under the ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME} +# (depending on the target ABI). This is convenient for Android packaging. +# +# Authors: +# Ethan Rublee ethan.ruble@gmail.com +# Andrey Kamaev andrey.kamaev@itseez.com +# +# Change Log: +# - initial version December 2010 +# - modified April 2011 +# [+] added possibility to build with NDK (without standalone toolchain) +# [+] support cross-compilation on Windows (native, no cygwin support) +# [+] added compiler option to force "char" type to be signed +# [+] added toolchain option to compile to 32-bit ARM instructions +# [+] added toolchain option to disable SWIG search +# [+] added platform "armeabi-v7a with VFPV3" +# [~] ARM_TARGETS renamed to ARM_TARGET +# [+] EXECUTABLE_OUTPUT_PATH is set by toolchain (required on Windows) +# [~] Fixed bug with ANDROID_API_LEVEL variable +# [~] turn off SWIG search if it is not found first time +# - modified May 2011 +# [~] ANDROID_LEVEL is renamed to ANDROID_API_LEVEL +# [+] ANDROID_API_LEVEL is detected by toolchain if not specified +# [~] added guard to prevent changing of output directories on the first +# cmake pass +# [~] toolchain exits with error if ARM_TARGET is not recognized +# - modified June 2011 +# [~] default NDK path is updated for version r5c +# [+] variable CMAKE_SYSTEM_PROCESSOR is set based on ARM_TARGET +# [~] toolchain install directory is added to linker paths +# [-] removed SWIG-related stuff from toolchain +# [+] added macro find_host_package, find_host_program to search +# packages/programs on the host system +# [~] fixed path to STL library +# - modified July 2011 +# [~] fixed options caching +# [~] search for all supported NDK versions +# [~] allowed spaces in NDK path +# - modified September 2011 +# [~] updated for NDK r6b +# - modified November 2011 +# [*] rewritten for NDK r7 +# [+] x86 toolchain support (experimental) +# [+] added "armeabi-v6 with VFP" ABI for ARMv6 processors. +# [~] improved compiler and linker flags management +# [+] support different build flags for Release and Debug configurations +# [~] by default compiler flags the same as used by ndk-build (but only +# where reasonable) +# [~] ANDROID_NDK_TOOLCHAIN_ROOT is splitted to ANDROID_STANDALONE_TOOLCHAIN +# and ANDROID_TOOLCHAIN_ROOT +# [~] ARM_TARGET is renamed to ANDROID_ABI +# [~] ARMEABI_NDK_NAME is renamed to ANDROID_NDK_ABI_NAME +# [~] ANDROID_API_LEVEL is renamed to ANDROID_NATIVE_API_LEVEL +# - modified January 2012 +# [+] added stlport_static support (experimental) +# [+] added special check for cygwin +# [+] filtered out hidden files (starting with .) while globbing inside NDK +# [+] automatically applied GLESv2 linkage fix for NDK revisions 5-6 +# [+] added ANDROID_GET_ABI_RAWNAME to get NDK ABI names by CMake flags +# - modified February 2012 +# [+] updated for NDK r7b +# [~] fixed cmake try_compile() command +# [~] Fix for missing install_name_tool on OS X +# - modified March 2012 +# [~] fixed incorrect C compiler flags +# [~] fixed CMAKE_SYSTEM_PROCESSOR change on ANDROID_ABI change +# [+] improved toolchain loading speed +# [+] added assembler language support (.S) +# [+] allowed preset search paths and extra search suffixes +# - modified April 2012 +# [+] updated for NDK r7c +# [~] fixed most of problems with compiler/linker flags and caching +# [+] added option ANDROID_FUNCTION_LEVEL_LINKING +# - modified May 2012 +# [+] updated for NDK r8 +# [+] added mips architecture support +# - modified August 2012 +# [+] updated for NDK r8b +# [~] all intermediate files generated by toolchain are moved into CMakeFiles +# [~] libstdc++ and libsupc are removed from explicit link libraries +# ------------------------------------------------------------------------------ + +cmake_minimum_required( VERSION 2.6.3 ) + +if( DEFINED CMAKE_CROSSCOMPILING ) + # subsequent toolchain loading is not really needed + return() +endif() + +get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) +if( _CMAKE_IN_TRY_COMPILE ) + include( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL ) +endif() + +# this one is important +set( CMAKE_SYSTEM_NAME Linux ) +# this one not so much +set( CMAKE_SYSTEM_VERSION 1 ) + +set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) +if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS) + if( CMAKE_HOST_WIN32 ) + file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) + set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}/android-ndk" "$ENV{SystemDrive}/NVPACK/android-ndk" ) + else() + file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS ) + set( ANDROID_NDK_SEARCH_PATHS /opt/android-ndk "${ANDROID_NDK_SEARCH_PATHS}/NVPACK/android-ndk" ) + endif() +endif() +if(NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH) + set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain ) +endif() + +set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" ) +set( ANDROID_SUPPORTED_ABIS_x86 "x86" ) +set( ANDROID_SUPPORTED_ABIS_mipsel "mips" ) + +set( ANDROID_DEFAULT_NDK_API_LEVEL 9 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 ) +set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 ) + + +macro( __LIST_FILTER listvar regex ) + if( ${listvar} ) + foreach( __val ${${listvar}} ) + if( __val MATCHES "${regex}" ) + list( REMOVE_ITEM ${listvar} "${__val}" ) + endif() + endforeach() + endif() +endmacro() + +macro( __INIT_VARIABLE var_name ) + set( __test_path 0 ) + foreach( __var ${ARGN} ) + if( __var STREQUAL "PATH" ) + set( __test_path 1 ) + break() + endif() + endforeach() + if( __test_path AND NOT EXISTS "${${var_name}}" ) + unset( ${var_name} CACHE ) + endif() + if( "${${var_name}}" STREQUAL "" ) + set( __values 0 ) + foreach( __var ${ARGN} ) + if( __var STREQUAL "VALUES" ) + set( __values 1 ) + elseif( NOT __var STREQUAL "PATH" ) + set( __obsolete 0 ) + if( __var MATCHES "^OBSOLETE_.*$" ) + string( REPLACE "OBSOLETE_" "" __var "${__var}" ) + set( __obsolete 1 ) + endif() + if( __var MATCHES "^ENV_.*$" ) + string( REPLACE "ENV_" "" __var "${__var}" ) + set( __value "$ENV{${__var}}" ) + elseif( DEFINED ${__var} ) + set( __value "${${__var}}" ) + else() + if( __values ) + set( __value "${__var}" ) + else() + set( __value "" ) + endif() + endif() + if( NOT "${__value}" STREQUAL "" ) + if( __test_path ) + if( EXISTS "${__value}" ) + set( ${var_name} "${__value}" ) + if( __obsolete ) + message( WARNING "Using value of obsolete variable ${__var} as initial value for ${var_name}. Please note, that ${__var} can be completely removed in future versions of the toolchain." ) + endif() + break() + endif() + else() + set( ${var_name} "${__value}" ) + if( __obsolete ) + message( WARNING "Using value of obsolete variable ${__var} as initial value for ${var_name}. Please note, that ${__var} can be completely removed in future versions of the toolchain." ) + endif() + break() + endif() + endif() + endif() + endforeach() + unset( __value ) + unset( __values ) + unset( __obsolete ) + endif() + unset( __test_path ) +endmacro() + +macro( __DETECT_NATIVE_API_LEVEL _var _path ) + SET( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*$" ) + FILE( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) + if( NOT __apiFileContent ) + message( SEND_ERROR "Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) + endif() + string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" ) + unset( __apiFileContent ) + unset( __ndkApiLevelRegex ) +endmacro() + +macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) + file( GLOB __gccExePath "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) + __LIST_FILTER( __gccExePath "bin/[.].*-gcc${TOOL_OS_SUFFIX}$" ) + list( LENGTH __gccExePath __gccExePathsCount ) + if( NOT __gccExePathsCount EQUAL 1 ) + message( WARNING "Could not uniquely determine machine name for compiler from ${_root}." ) + set( ${_var} "" ) + else() + get_filename_component( __gccExeName "${__gccExePath}" NAME_WE ) + string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" ) + endif() + unset( __gccExePath ) + unset( __gccExePathsCount ) + unset( __gccExeName ) +endmacro() + +macro( __COPY_IF_DIFFERENT _source _destination ) + execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${_source}" "${_destination}" RESULT_VARIABLE __fileCopyProcess ) + if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${_destination}") + message( SEND_ERROR "Failed copying of ${_source} to the ${_destination}" ) + endif() + unset( __fileCopyProcess ) +endmacro() + + +# stl version: by default gnustl_static will be used +set( ANDROID_USE_STLPORT FALSE CACHE BOOL "Experimental: use stlport_static instead of gnustl_static") +mark_as_advanced( ANDROID_USE_STLPORT ) + +# fight against cygwin +set( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools") +mark_as_advanced( ANDROID_FORBID_SYGWIN ) +if( ANDROID_FORBID_SYGWIN ) + if( CYGWIN ) + message( FATAL_ERROR "Android NDK and android-cmake toolchain are not welcome Cygwin. It is unlikely that this cmake toolchain will work under cygwin. But if you want to try then you can set cmake variable ANDROID_FORBID_SYGWIN to FALSE and rerun cmake." ) + endif() + + if( CMAKE_HOST_WIN32 ) + # remove cygwin from PATH + set( __new_path "$ENV{PATH}") + __LIST_FILTER( __new_path "cygwin" ) + set(ENV{PATH} "${__new_path}") + unset(__new_path) + endif() +endif() + +# detect current host platform +set( TOOL_OS_SUFFIX "" ) +if( CMAKE_HOST_APPLE ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86" ) +elseif( CMAKE_HOST_WIN32 ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "windows" ) + set( TOOL_OS_SUFFIX ".exe" ) +elseif( CMAKE_HOST_UNIX ) + set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86" ) +else() + message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) +endif() + +# see if we have path to Android NDK +__INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK ) +if( NOT ANDROID_NDK ) + # see if we have path to Android standalone toolchain + __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN OBSOLETE_ANDROID_NDK_TOOLCHAIN_ROOT OBSOLETE_ENV_ANDROID_NDK_TOOLCHAIN_ROOT ) + + if( NOT ANDROID_STANDALONE_TOOLCHAIN ) + #try to find Android NDK in one of the the default locations + set( __ndkSearchPaths ) + foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} ) + foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} ) + list( APPEND __ndkSearchPaths "${__ndkSearchPath}${suffix}" ) + endforeach() + endforeach() + __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} ) + unset( __ndkSearchPaths ) + + if( ANDROID_NDK ) + message( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" ) + message( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" ) + else() + #try to find Android standalone toolchain in one of the the default locations + __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH ) + + if( ANDROID_STANDALONE_TOOLCHAIN ) + message( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" ) + message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" ) + endif( ANDROID_STANDALONE_TOOLCHAIN ) + endif( ANDROID_NDK ) + endif( NOT ANDROID_STANDALONE_TOOLCHAIN ) +endif( NOT ANDROID_NDK ) + +# remember found paths +if( ANDROID_NDK ) + get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE ) + # try to detect change + if( CMAKE_AR ) + string( LENGTH "${ANDROID_NDK}" __length ) + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath ) + if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK ) + message( FATAL_ERROR "It is not possible to change path to the NDK on subsequent run." ) + endif() + unset( __androidNdkPreviousPath ) + unset( __length ) + endif() + set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" ) + set( BUILD_WITH_ANDROID_NDK True ) +elseif( ANDROID_STANDALONE_TOOLCHAIN ) + get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE ) + # try to detect change + if( CMAKE_AR ) + string( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length ) + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidStandaloneToolchainPreviousPath ) + if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN ) + message( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." ) + endif() + unset( __androidStandaloneToolchainPreviousPath ) + unset( __length ) + endif() + set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" ) + set( BUILD_WITH_STANDALONE_TOOLCHAIN True ) +else() + list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH) + message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolcahin. + You should either set an environment variable: + export ANDROID_NDK=~/my-android-ndk + or + export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain + or put the toolchain or NDK in the default path: + sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH} + sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" ) +endif() + +# get all the details about standalone toolchain +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" ) + set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) + set( __availableToolchains "standalone" ) + __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" ) + if( NOT __availableToolchainMachines ) + message( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." ) + endif() + if( __availableToolchainMachines MATCHES i686 ) + set( __availableToolchainArchs "x86" ) + elseif( __availableToolchainMachines MATCHES arm ) + set( __availableToolchainArchs "arm" ) + elseif( __availableToolchainMachines MATCHES mipsel ) + set( __availableToolchainArchs "mipsel" ) + endif() + if( ANDROID_COMPILER_VERSION ) + # do not run gcc every time because it is relatevely expencive + set( __availableToolchainCompilerVersions "${ANDROID_COMPILER_VERSION}" ) + else() + execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" --version + OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) + endif() +endif() + +# get all the details about NDK +if( BUILD_WITH_ANDROID_NDK ) + file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" ) + string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) + file( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" ) + __LIST_FILTER( __availableToolchains "^[.]" ) + set( __availableToolchainMachines "" ) + set( __availableToolchainArchs "" ) + set( __availableToolchainCompilerVersions "" ) + foreach( __toolchain ${__availableToolchains} ) + __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK}/toolchains/${__toolchain}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + if( __machine ) + string( REGEX MATCH "[0-9]+[.][0-9]+[.]*[0-9]*$" __version "${__toolchain}" ) + string( REGEX MATCH "^[^-]+" __arch "${__toolchain}" ) + list( APPEND __availableToolchainMachines "${__machine}" ) + list( APPEND __availableToolchainArchs "${__arch}" ) + list( APPEND __availableToolchainCompilerVersions "${__version}" ) + else() + list( REMOVE_ITEM __availableToolchains "${__toolchain}" ) + endif() + endforeach() + if( NOT __availableToolchains ) + message( FATAL_ERROR "Could not any working toolchain in the NDK. Probably your Android NDK is broken." ) + endif() +endif() + +# build list of available ABIs +if( NOT ANDROID_SUPPORTED_ABIS ) + set( ANDROID_SUPPORTED_ABIS "" ) + set( __uniqToolchainArchNames ${__availableToolchainArchs} ) + list( REMOVE_DUPLICATES __uniqToolchainArchNames ) + list( SORT __uniqToolchainArchNames ) + foreach( __arch ${__uniqToolchainArchNames} ) + list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) + endforeach() + unset( __uniqToolchainArchNames ) + if( NOT ANDROID_SUPPORTED_ABIS ) + message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) + endif() +endif() + +# choose target ABI +__INIT_VARIABLE( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${ANDROID_SUPPORTED_ABIS} ) +# verify that target ABI is supported +list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx ) +if( __androidAbiIdx EQUAL -1 ) + string( REPLACE ";" "\", \"", PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" ) + message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain. + Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\" + " ) +endif() +unset( __androidAbiIdx ) + +# remember target ABI +set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) + +# set target ABI options +if( ANDROID_ABI STREQUAL "x86" ) + set( X86 true ) + set( ANDROID_NDK_ABI_NAME "x86" ) + set( ANDROID_ARCH_NAME "x86" ) + set( ANDROID_ARCH_FULLNAME "x86" ) + set( CMAKE_SYSTEM_PROCESSOR "i686" ) +elseif( ANDROID_ABI STREQUAL "mips" ) + set( MIPS true ) + set( ANDROID_NDK_ABI_NAME "mips" ) + set( ANDROID_ARCH_NAME "mips" ) + set( ANDROID_ARCH_FULLNAME "mipsel" ) + set( CMAKE_SYSTEM_PROCESSOR "mips" ) +elseif( ANDROID_ABI STREQUAL "armeabi" ) + set( ARMEABI true ) + set( ANDROID_NDK_ABI_NAME "armeabi" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_ARCH_FULLNAME "arm" ) + set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) +elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" ) + set( ARMEABI_V6 true ) + set( ANDROID_NDK_ABI_NAME "armeabi" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_ARCH_FULLNAME "arm" ) + set( CMAKE_SYSTEM_PROCESSOR "armv6" ) + # need always fallback to older platform + set( ARMEABI true ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a") + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_ARCH_FULLNAME "arm" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" ) + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_ARCH_FULLNAME "arm" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) + set( VFPV3 true ) +elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) + set( ARMEABI_V7A true ) + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) + set( ANDROID_ARCH_NAME "arm" ) + set( ANDROID_ARCH_FULLNAME "arm" ) + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) + set( VFPV3 true ) + set( NEON true ) +else() + message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." ) +endif() + +if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" ) + # really dirty hack + # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run... + file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" ) +endif() + +set( ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} CACHE INTERNAL "ANDROID_ABI can be changed only to one of these ABIs. Changing to any other ABI requires to reset cmake cache." ) +if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME} ) + set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} ) +endif() + +if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) + __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF ) + set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE ) + mark_as_advanced( ANDROID_FORCE_ARM_BUILD ) +else() + unset( ANDROID_FORCE_ARM_BUILD CACHE ) +endif() + +# choose toolchain +if( ANDROID_TOOLCHAIN_NAME ) + list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx ) + if( __toolchainIdx EQUAL -1 ) + message( FATAL_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing. You need to remove CMakeCache.txt and rerun cmake manually to change the toolchain" ) + endif() + list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch ) + if( NOT __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME ) + message( SEND_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) + endif() +else() + set( __toolchainIdx -1 ) + set( __applicableToolchains "" ) + set( __toolchainMaxVersion "0.0.0" ) + list( LENGTH __availableToolchains __availableToolchainsCount ) + math( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" ) + foreach( __idx RANGE ${__availableToolchainsCount} ) + list( GET __availableToolchainArchs ${__idx} __toolchainArch ) + if( __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME ) + list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion ) + if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion ) + set( __toolchainMaxVersion "${__toolchainVersion}" ) + set( __toolchainIdx ${__idx} ) + endif() + endif() + endforeach() + unset( __availableToolchainsCount ) + unset( __toolchainMaxVersion ) + unset( __toolchainVersion ) +endif() +unset( __toolchainArch ) +if( __toolchainIdx EQUAL -1 ) + message( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." ) +endif() +list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME ) +list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME ) +list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION ) +set( ANDROID_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" CACHE INTERNAL "Name of toolchain used" ) +set( ANDROID_COMPILER_VERSION "${ANDROID_COMPILER_VERSION}" CACHE INTERNAL "compiler version from selected toolchain" ) +unset( __toolchainIdx ) +unset( __availableToolchains ) +unset( __availableToolchainMachines ) +unset( __availableToolchainArchs ) +unset( __availableToolchainCompilerVersions ) + +# choose native API level +__INIT_VARIABLE( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL ) +string( REGEX MATCH "[0-9]+" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" ) +# validate +list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) +if( __levelIdx EQUAL -1 ) + message( SEND_ERROR "Specified Android native API level (${ANDROID_NATIVE_API_LEVEL}) is not supported by your NDK/toolchain." ) +endif() +unset( __levelIdx ) +if( BUILD_WITH_ANDROID_NDK ) + __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) + if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL ) + message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) + endif() + unset( __realApiLevel ) +endif() +set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) +if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) + set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) +endif() + +# setup paths +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) + set( __stlLibPath "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) +endif() +if( BUILD_WITH_ANDROID_NDK ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) + if( ANDROID_USE_STLPORT ) + set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" ) + set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}" ) + else() + if( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) + set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/include" ) + set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}" ) + else() + set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include" ) + set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}" ) + endif() + endif() +endif() + +# specify the cross compiler +set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" ) +set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" ) +set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "Assembler" ) +if( CMAKE_VERSION VERSION_LESS 2.8.5 ) + set( CMAKE_ASM_COMPILER_ARG1 "-c" ) +endif() +# there may be a way to make cmake deduce these TODO deduce the rest of the tools +set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) +set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) +set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" ) +set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" ) +set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" ) +set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" ) +set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" ) +set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" ) +if( APPLE ) + find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool ) + if( NOT CMAKE_INSTALL_NAME_TOOL ) + message( FATAL_ERROR "Could not find install_name_tool, please check your installation." ) + endif() + mark_as_advanced( CMAKE_INSTALL_NAME_TOOL ) +endif() + +# export directories +set( ANDROID_SYSTEM_INCLUDE_DIRS "" ) +set( ANDROID_SYSTEM_LIB_DIRS "" ) + +# setup output directories +set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" ) +set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) + +if(NOT _CMAKE_IN_TRY_COMPILE) + if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) + else() + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) + endif() + set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) +endif() + +# includes +list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_SYSROOT}/usr/include" ) +if( __stlIncludePath AND EXISTS "${__stlIncludePath}" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${__stlIncludePath}" ) +endif() + +# c++ bits includes +if( __stlLibPath AND EXISTS "${__stlLibPath}/include" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${__stlLibPath}/include" ) +endif() +if( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/thumb/bits" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) +elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) +elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) +elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/bits" ) + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) +endif() + +# flags and definitions +if(ANDROID_SYSROOT MATCHES "[ ;\"]") + set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" ) + # quotes will break try_compile and compiler identification + message(WARNING "Your Android system root has non-alphanumeric symbols. It can break compiler features detection and the whole build.") +else() + set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) +endif() + +remove_definitions( -DANDROID ) +add_definitions( -DANDROID ) + +# Force set compilers because standard identification works badly for us +include( CMakeForceCompiler ) +CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU ) +set( CMAKE_C_PLATFORM_ID Linux ) +set( CMAKE_C_SIZEOF_DATA_PTR 4 ) +set( CMAKE_C_HAS_ISYSROOT 1 ) +set( CMAKE_C_COMPILER_ABI ELF ) +CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU ) +set( CMAKE_CXX_PLATFORM_ID Linux ) +set( CMAKE_CXX_SIZEOF_DATA_PTR 4 ) +set( CMAKE_CXX_HAS_ISYSROOT 1 ) +set( CMAKE_CXX_COMPILER_ABI ELF ) +# force ASM compiler (required for CMake < 2.8.5) +set( CMAKE_ASM_COMPILER_ID_RUN TRUE ) +set( CMAKE_ASM_COMPILER_ID GNU ) +set( CMAKE_ASM_COMPILER_WORKS TRUE ) +set( CMAKE_ASM_COMPILER_FORCED TRUE ) +set( CMAKE_COMPILER_IS_GNUASM 1) + +# NDK flags +if( ARMEABI OR ARMEABI_V7A ) + # NDK also defines -ffunction-sections -funwind-tables but they result in worse OpenCV performance + set( _CMAKE_CXX_FLAGS "-fPIC -Wno-psabi" ) + set( _CMAKE_C_FLAGS "-fPIC -Wno-psabi" ) + remove_definitions( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ) + add_definitions( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ) + # extra arm-specific flags + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) +elseif( X86 ) + set( _CMAKE_CXX_FLAGS "-funwind-tables" ) + set( _CMAKE_C_FLAGS "-funwind-tables" ) +elseif( MIPS ) + set( _CMAKE_CXX_FLAGS "-fpic -Wno-psabi -fno-strict-aliasing -finline-functions -ffunction-sections -funwind-tables -fmessage-length=0 -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" ) + set( _CMAKE_CXX_FLAGS "-fpic -Wno-psabi -fno-strict-aliasing -finline-functions -ffunction-sections -funwind-tables -fmessage-length=0 -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) +else() + set( _CMAKE_CXX_FLAGS "" ) + set( _CMAKE_C_FLAGS "" ) +endif() + +if( ANDROID_USE_STLPORT ) + set( _CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions" ) + set( _CMAKE_C_FLAGS "${_CMAKE_C_FLAGS} -fno-exceptions" ) +else() + set( _CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS} -frtti -fexceptions" ) + set( _CMAKE_C_FLAGS "${_CMAKE_C_FLAGS} -fexceptions" ) +endif() + +# release and debug flags +if( ARMEABI OR ARMEABI_V7A ) + if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 ) + # It is recommended to use the -mthumb compiler flag to force the generation + # of 16-bit Thumb-1 instructions (the default being 32-bit ARM ones). + # O3 instead of O2/Os in release mode - like cmake sets for desktop gcc + set( _CMAKE_CXX_FLAGS_RELEASE "-mthumb -O3" ) + set( _CMAKE_C_FLAGS_RELEASE "-mthumb -O3" ) + set( _CMAKE_CXX_FLAGS_DEBUG "-marm -Os -finline-limit=64" ) + set( _CMAKE_C_FLAGS_DEBUG "-marm -Os -finline-limit=64" ) + else() + # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI + # O3 instead of O2/Os in release mode - like cmake sets for desktop gcc + set( _CMAKE_CXX_FLAGS_RELEASE "-marm -O3 -fstrict-aliasing" ) + set( _CMAKE_C_FLAGS_RELEASE "-marm -O3 -fstrict-aliasing" ) + set( _CMAKE_CXX_FLAGS_DEBUG "-marm -O0 -finline-limit=300" ) + set( _CMAKE_C_FLAGS_DEBUG "-marm -O0 -finline-limit=300" ) + endif() +elseif( X86 ) + set( _CMAKE_CXX_FLAGS_RELEASE "-O3 -fstrict-aliasing" ) + set( _CMAKE_C_FLAGS_RELEASE "-O3 -fstrict-aliasing" ) + set( _CMAKE_CXX_FLAGS_DEBUG "-O0 -finline-limit=300" ) + set( _CMAKE_C_FLAGS_DEBUG "-O0 -finline-limit=300" ) +elseif( MIPS ) + set( _CMAKE_CXX_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" ) + set( _CMAKE_C_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" ) + set( _CMAKE_CXX_FLAGS_DEBUG "-O0 -g" ) + set( _CMAKE_C_FLAGS_DEBUG "-O0 -g" ) +endif() +set( _CMAKE_CXX_FLAGS_RELEASE "${_CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" ) +set( _CMAKE_C_FLAGS_RELEASE "${_CMAKE_C_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" ) +set( _CMAKE_CXX_FLAGS_DEBUG "${_CMAKE_CXX_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG" ) +set( _CMAKE_C_FLAGS_DEBUG "${_CMAKE_C_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG" ) + +# ABI-specific flags +if( ARMEABI_V7A ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) + if( NEON ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" ) + elseif( VFPV3 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" ) + else() + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfp" ) + endif() +elseif( ARMEABI_V6 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) +elseif( ARMEABI ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) +elseif( X86 ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" )#sse? +endif() + +# linker flags +if( NOT DEFINED __ndklibspath ) + set( __ndklibspath "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ndklibs/${ANDROID_NDK_ABI_NAME}" ) +endif() +list( APPEND ANDROID_SYSTEM_LIB_DIRS "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ) +set( ANDROID_LINKER_FLAGS "" ) + +# STL +if( ANDROID_USE_STLPORT ) + if( EXISTS "${__stlLibPath}/libstlport_static.a" ) + set( CMAKE_CXX_CREATE_SHARED_LIBRARY " -o \"${__stlLibPath}/libstlport_static.a\"") + set( CMAKE_CXX_CREATE_SHARED_MODULE " -o \"${__stlLibPath}/libstlport_static.a\"") + endif() +else( ANDROID_USE_STLPORT ) + if( EXISTS "${__stlLibPath}/libgnustl_static.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/libgnustl_static.a" "${__ndklibspath}/libstdc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/thumb/libstdc++.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/thumb/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) + elseif( EXISTS "${__stlLibPath}/libstdc++.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) + endif() + if( EXISTS "${__stlLibPath}/libsupc++.a" ) + __COPY_IF_DIFFERENT( "${__stlLibPath}/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" ) + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" ) + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" ) + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) + elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" ) + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) + endif() + list( APPEND ANDROID_SYSTEM_LIB_DIRS "${__ndklibspath}" ) +endif( ANDROID_USE_STLPORT ) + +# cleanup for STL search +unset( __stlIncludePath ) +unset( __stlLibPath ) + +# other linker flags +__INIT_VARIABLE( ANDROID_NO_UNDEFINED OBSOLETE_NO_UNDEFINED VALUES ON ) +set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" FORCE ) +mark_as_advanced( ANDROID_NO_UNDEFINED ) +if( ANDROID_NO_UNDEFINED ) + set( ANDROID_LINKER_FLAGS "-Wl,--no-undefined ${ANDROID_LINKER_FLAGS}" ) +endif() + +if (ANDROID_NDK MATCHES "-r[56].?$") + # libGLESv2.so in NDK's prior to r7 refers to exteranal symbols. So this flag option is required for all projects using OpenGL from native. + __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES ON ) +else() + __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF ) +endif() + +set( ANDROID_SO_UNDEFINED ${ANDROID_SO_UNDEFINED} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" FORCE ) +mark_as_advanced( ANDROID_SO_UNDEFINED ) +if( ANDROID_SO_UNDEFINED ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" ) +endif() + +__INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON ) +set( ANDROID_FUNCTION_LEVEL_LINKING ON CACHE BOOL "Allows or disallows undefined symbols in shared libraries" FORCE ) +mark_as_advanced( ANDROID_FUNCTION_LEVEL_LINKING ) +if( ANDROID_FUNCTION_LEVEL_LINKING ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" ) + set( ANDROID_LINKER_FLAGS "-Wl,--gc-sections ${ANDROID_LINKER_FLAGS}" ) +endif() + +if( ARMEABI_V7A ) + # this is *required* to use the following linker flags that routes around + # a CPU bug in some Cortex-A8 implementations: + set( ANDROID_LINKER_FLAGS "-Wl,--fix-cortex-a8 ${ANDROID_LINKER_FLAGS}" ) +endif() + +# cache flags +set( CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags" ) +set( CMAKE_C_FLAGS "${_CMAKE_C_FLAGS}" CACHE STRING "c flags" ) +set( CMAKE_CXX_FLAGS_RELEASE "${_CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "c++ Release flags" ) +set( CMAKE_C_FLAGS_RELEASE "${_CMAKE_C_FLAGS_RELEASE}" CACHE STRING "c Release flags" ) +set( CMAKE_CXX_FLAGS_DEBUG "${_CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "c++ Debug flags" ) +set( CMAKE_C_FLAGS_DEBUG "${_CMAKE_C_FLAGS_DEBUG}" CACHE STRING "c Debug flags" ) +set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "linker flags" ) +set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "linker flags" ) +set( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "linker flags" ) + +include_directories( SYSTEM ${ANDROID_SYSTEM_INCLUDE_DIRS} ) +link_directories( ${ANDROID_SYSTEM_LIB_DIRS} ) + +# finish flags +set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Extra Android compiler flags") +set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Extra Android linker flags") +set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" ) +set( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" ) +if( MIPS AND BUILD_WITH_ANDROID_NDK ) + set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" ) + set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" ) + set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.x ${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) +else() + set( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" ) + set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" ) + set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) +endif() + +# set these global flags for cmake client scripts to change behavior +set( ANDROID True ) +set( BUILD_ANDROID True ) + +# where is the target environment +set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) + +# only search for libraries and includes in the ndk toolchain +set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + + +# macro to find packages on the host OS +macro( find_host_package ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_package( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endmacro() + + +# macro to find programs on the host OS +macro( find_host_program ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_program( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endmacro() + + +macro( ANDROID_GET_ABI_RAWNAME TOOLCHAIN_FLAG VAR ) + if( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI" ) + set( ${VAR} "armeabi" ) + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI_V7A" ) + set( ${VAR} "armeabi-v7a" ) + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "X86" ) + set( ${VAR} "x86" ) + else() + set( ${VAR} "unknown" ) + endif() +endmacro() + + +# export toolchain settings for the try_compile() command +if( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" ) + set( __toolchain_config "") + foreach( __var ANDROID_ABI ANDROID_FORCE_ARM_BUILD ANDROID_NATIVE_API_LEVEL ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_SET_OBSOLETE_VARIABLES LIBRARY_OUTPUT_PATH_ROOT ANDROID_USE_STLPORT ANDROID_FORBID_SYGWIN ANDROID_NDK ANDROID_STANDALONE_TOOLCHAIN ANDROID_FUNCTION_LEVEL_LINKING __ndklibspath ) + if( DEFINED ${__var} ) + if( "${__var}" MATCHES " ") + set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" ) + else() + set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" ) + endif() + endif() + endforeach() + file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" ) + unset( __toolchain_config ) + unset( __ndklibspath ) +endif() + + +# set some obsolete variables for backward compatibility +set( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" ) +mark_as_advanced( ANDROID_SET_OBSOLETE_VARIABLES ) +if( ANDROID_SET_OBSOLETE_VARIABLES ) + set( ANDROID_API_LEVEL ${ANDROID_NATIVE_API_LEVEL} ) + set( ARM_TARGET "${ANDROID_ABI}" ) + set( ARMEABI_NDK_NAME "${ANDROID_NDK_ABI_NAME}" ) +endif() + + +# Variables controlling behavior or set by cmake toolchain: +# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips" +# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14 (depends on NDK version) +# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF +# ANDROID_USE_STLPORT : OFF/ON - EXPERIMENTAL!!! +# ANDROID_FORBID_SYGWIN : ON/OFF +# ANDROID_NO_UNDEFINED : ON/OFF +# ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version) +# ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF +# Variables that takes effect only at first run: +# ANDROID_FORCE_ARM_BUILD : ON/OFF +# LIBRARY_OUTPUT_PATH_ROOT : +# Can be set only at the first run: +# ANDROID_NDK +# ANDROID_STANDALONE_TOOLCHAIN +# ANDROID_TOOLCHAIN_NAME : "arm-linux-androideabi-4.4.3" or "arm-linux-androideabi-4.6" or "mipsel-linux-android-4.4.3" or "mipsel-linux-android-4.6" or "x86-4.4.3" or "x86-4.6" +# Obsolete: +# ANDROID_API_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL +# ARM_TARGET : superseded by ANDROID_ABI +# ARM_TARGETS : superseded by ANDROID_ABI (can be set only) +# ANDROID_NDK_TOOLCHAIN_ROOT : superseded by ANDROID_STANDALONE_TOOLCHAIN (can be set only) +# ANDROID_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL (completely removed) +# +# Primary read-only variables: +# ANDROID : always TRUE +# ARMEABI : TRUE for arm v6 and older devices +# ARMEABI_V6 : TRUE for arm v6 +# ARMEABI_V7A : TRUE for arm v7a +# NEON : TRUE if NEON unit is enabled +# VFPV3 : TRUE if VFP version 3 is enabled +# X86 : TRUE if configured for x86 +# BUILD_ANDROID : always TRUE +# BUILD_WITH_ANDROID_NDK : TRUE if NDK is used +# BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used +# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform +# ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a" or "x86" depending on ANDROID_ABI +# ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI +# TOOL_OS_SUFFIX : "" or ".exe" depending on host platform +# ANDROID_SYSROOT : path to the compiler sysroot +# ANDROID_SYSTEM_INCLUDE_DIRS +# ANDROID_SYSTEM_LIB_DIRS +# Obsolete: +# ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME +# +# Secondary (less stable) read-only variables: +# ANDROID_COMPILER_VERSION : GCC version used +# ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform +# ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI +# ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux" +# ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK) +# ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK +# +# Defaults: +# ANDROID_DEFAULT_NDK_API_LEVEL +# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH} +# ANDROID_NDK_SEARCH_PATHS +# ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH +# ANDROID_SUPPORTED_ABIS_${ARCH} +# ANDROID_SUPPORTED_NDK_VERSIONS diff --git a/android/jni/Android.mk b/android/jni/Android.mk index a63bc5f606..55dd60a07d 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -53,7 +53,6 @@ LOCAL_SRC_FILES := \ $(SRC)/ext/libkirk/bn.c \ $(SRC)/ext/libkirk/ec.c \ $(SRC)/ext/libkirk/kirk_engine.c \ - $(SRC)/Globals.cpp \ $(SRC)/Common/ArmABI.cpp \ $(SRC)/Common/ArmEmitter.cpp \ $(SRC)/Common/LogManager.cpp \ diff --git a/native b/native index 0598fc425c..188c0c1a2f 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 0598fc425c6b898af9fee5b49b2054b2fffa55e6 +Subproject commit 188c0c1a2f9e4d93bc2c7ebda5a73a204dc432f5