update building system to add android support.
authorZhongwei Yao <Zhongwei.Yao@arm.com>
Sun, 7 Apr 2013 03:31:48 +0000 (11:31 +0800)
committerZhongwei Yao <Zhongwei.Yao@arm.com>
Thu, 23 May 2013 12:14:59 +0000 (20:14 +0800)
CMakeLists.txt
GNUlinux_config.cmake [moved from config.cmake with 89% similarity]
README.txt
android/android_config.cmake [new file with mode: 0644]
doc/CMakeBuilding.txt
modules/CMakeLists.txt
test/CMakeLists.txt

index f289251..4a64e4e 100644 (file)
@@ -34,7 +34,7 @@ option(NE10_BUILD_EXAMPLES "Build NE10 examples" ON)
 
 #unit test options
 option(NE10_BUILD_UNIT_TEST "Build NE10 unit test" OFF)
-if (NE10_BUILD_UNIT_TEST)
+if(NE10_BUILD_UNIT_TEST)
     #decide the test is smoke, regression or performance test, only one of three options is ON!
     option(NE10_SMOKE_TEST "Run smoke test" OFF)
     option(NE10_REGRESSION_TEST "Run regression test" OFF)
@@ -43,6 +43,11 @@ if (NE10_BUILD_UNIT_TEST)
     option(NE10_DEBUG_TRACE "Print debug trace" OFF)
 endif()
 
+#check if proper platform is set.
+if((NOT ANDROID_PLATFORM) AND (NOT GNULINUX_PLATFORM))
+    message(FATAL_ERROR "No platform is defined! see CMakeBuilding.txt under doc for details.")
+endif()
+
 #select functionalities to be compiled
 option(NE10_ENABLE_MATH "Build math functionalities to NE10" ON)
 option(NE10_ENABLE_DSP "Build dsp functionalities to NE10" ON)
@@ -51,10 +56,19 @@ option(NE10_ENABLE_IMGPROC "Build image processing functionalities to NE10" ON)
 set(NE10_VERSION 10)
 
 # set complile flags for ARM.
-set( CMAKE_C_FLAGS "-O2 -mthumb-interwork -march=armv7-a -mcpu=cortex-a9 -mfpu=vfp3" )
-
-set( CMAKE_ASM_FLAGS "-mthumb-interwork -march=armv7-a -mcpu=cortex-a9 -mfpu=neon" )
-
+if(ANDROID_PLATFORM)
+    set(CMAKE_C_FLAGS "-O2 -mthumb-interwork -march=armv7-a -mfloat-abi=softfp -mfpu=vfp3 --sysroot=${NDK_SYSROOT_PATH}")
+    set(CMAKE_ASM_FLAGS "-mthumb-interwork -march=armv7-a -mfloat-abi=softfp -mfpu=neon --sysroot=${NDK_SYSROOT_PATH}")
+    message("loaded toolchain:
+    ${ANDROID_TOOLCHAIN_PATH}/arm-linux-androideabi-gcc
+    ${ANDROID_TOOLCHAIN_PATH}/arm-linux-androideabi-g++
+    ${ANDROID_TOOLCHAIN_PATH}/arm-linux-androideabi-as
+    ${ANDROID_TOOLCHAIN_PATH}/arm-linux-androideabi-ar
+    ${ANDROID_TOOLCHAIN_PATH}/arm-linux-androideabi-ranlib")
+elseif(GNULINUX_PLATFORM)
+    set(CMAKE_C_FLAGS "-O2 -mthumb-interwork -march=armv7-a -mfloat-abi=softfp -mfpu=vfp3")
+    set(CMAKE_ASM_FLAGS "-mthumb-interwork -march=armv7-a -mfloat-abi=softfp -mfpu=neon")
+endif()
 # The NE10 library.
 add_subdirectory(modules)
 
similarity index 89%
rename from config.cmake
rename to GNUlinux_config.cmake
index 783e4e0..a40fb28 100644 (file)
@@ -1,5 +1,5 @@
 #
-#  Copyright 2011-12 ARM Limited
+#  Copyright 2013 ARM Limited
 #  All rights reserved.
 #
 #  Redistribution and use in source and binary forms, with or without
 #  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
-set( CMAKE_C_COMPILER arm-linux-gnueabi-gcc )
-set( CMAKE_CXX_COMPILER arm-linux-gnueabi-g++ )
-set( CMAKE_ASM_COMPILER arm-linux-gnueabi-as )
+set(GNULINUX_PLATFORM ON)
+set(CMAKE_C_COMPILER arm-linux-gnueabi-gcc)
+set(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++)
+set(CMAKE_ASM_COMPILER arm-linux-gnueabi-as)
 
 find_program(CMAKE_AR NAMES "arm-linux-gnueabi-ar")
 mark_as_advanced(CMAKE_AR)
-
 find_program(CMAKE_RANLIB NAMES "arm-linux-gnueabi-ranlib")
 mark_as_advanced(CMAKE_RANLIB)
-
index b728fb1..ec36f80 100644 (file)
@@ -4,7 +4,7 @@ See http://projectne10.github.com/Ne10/
 
 Build
 =====
-See CMakeBuilding.txt file in the "doc" folder
+See CMakeBuilding.txt file in the "doc" folder, CMakeBuilding.txt also includes doc for android support.
 
 documentation
 =============
diff --git a/android/android_config.cmake b/android/android_config.cmake
new file mode 100644 (file)
index 0000000..a10d60e
--- /dev/null
@@ -0,0 +1,81 @@
+#
+#  Copyright 2013 ARM Limited
+#  All rights reserved.
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions are met:
+#    * Redistributions of source code must retain the above copyright
+#      notice, this list of conditions and the following disclaimer.
+#    * Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#    * Neither the name of ARM Limited nor the
+#      names of its contributors may be used to endorse or promote products
+#      derived from this software without specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND
+#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL ARM LIMITED BE LIABLE FOR ANY
+#  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+#  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+#  Usage:
+#   $ export ANDROID_NDK=/absolute/path/of/android-ndk
+#   $ mkdir build && cd build
+#   $ cmake -DCMAKE_TOOLCHAIN_FILE=path/of/android_config.cmake ..
+#   $ make
+#
+#  Option:
+#   you can also specify android api level and gcc version by
+#   setting ANDROID_API_LEVEL(default:14) and
+#   ARM_ANDROID_TOOLCHAIN_VERSION(default:4.6) environment variable.
+#
+#  Note:
+#  arm linux androideabi version must be >=4.6, namely, gcc version must be >=4.6
+
+set(CMAKE_SYSTEM_NAME Linux)
+
+set(ANDROID_PLATFORM ON)
+
+if(DEFINED ENV{ANDROID_NDK})
+    if(NOT DEFINED ENV{ANDROID_API_LEVEL})
+        set(ANDROID_API_LEVEL 14)
+    else()
+        set(ANDROID_API_LEVEL $ENV{ANDROID_API_LEVEL})
+    endif()
+
+    if(NOT DEFINED ENV{ARM_ANDROID_TOOLCHAIN_VERSION})
+        set(ARM_ANDROID_TOOLCHAIN_VERSION 4.6)
+    else()
+        set(ARM_ANDROID_TOOLCHAIN_VERSION $ENV{ARM_ANDROID_TOOLCHAIN_VERSION})
+    endif()
+    #NDK_SYSROOT_PATH is used in compiler's '--sysroot' flags
+    set(NDK_SYSROOT_PATH "$ENV{ANDROID_NDK}/platforms/android-${ANDROID_API_LEVEL}/arch-arm/")
+
+    set(ANDROID_TOOLCHAIN_PATH "$ENV{ANDROID_NDK}/toolchains/arm-linux-androideabi-${ARM_ANDROID_TOOLCHAIN_VERSION}/prebuilt/linux-x86_64/bin")
+
+    #change toolchain name according to your configuration
+    set(CMAKE_C_COMPILER ${ANDROID_TOOLCHAIN_PATH}/arm-linux-androideabi-gcc)
+    set(CMAKE_CXX_COMPILER ${ANDROID_TOOLCHAIN_PATH}/arm-linux-androideabi-g++)
+    set(CMAKE_ASM_COMPILER ${ANDROID_TOOLCHAIN_PATH}/arm-linux-androideabi-as)
+
+    # Skip the platform compiler checks for cross compiling
+    set(CMAKE_CXX_COMPILER_WORKS TRUE)
+    set(CMAKE_C_COMPILER_WORKS TRUE)
+    set(CMAKE_ASM_COMPILER_WORKS TRUE)
+
+    find_program(CMAKE_AR NAMES "${ANDROID_TOOLCHAIN_PATH}/arm-linux-androideabi-ar")
+    mark_as_advanced(CMAKE_AR)
+
+    find_program(CMAKE_RANLIB NAMES "${ANDROID_TOOLCHAIN_PATH}/arm-linux-androideabi-ranlib")
+    mark_as_advanced(CMAKE_RANLIB)
+
+else()
+    message(FATAL_ERROR "Could not find Android NDK. You should set an environment variable: export ANDROID_NDK=/your/path/to/android/ndk")
+endif()
index fa6d4cb..4ef4feb 100644 (file)
@@ -37,6 +37,7 @@ First download and install cmake from cmake.org.
 In Ubuntu, you can install cmake by "sudo apt-get install cmake"
 
 ---------------------------NATIVE-COMPILING------------------------------
+=Unix platforms=:
 For Unix platforms, say the following on a terminal: (Replace $NE10PATH with the directory where this file is located.)
     cd $NE10PATH
     mkdir build && cd build
@@ -45,11 +46,15 @@ For Unix platforms, say the following on a terminal: (Replace $NE10PATH with the
 Then the libNE10.a is placed in ./modules/ and a sample program "NE10_test_static" is placed in ./samples/. you can run it.
 You might want to add -DNE10_BUILD_SHARED=ON to the cmake call to generate the dynamic library and test program "NE10_test_dynamic".
 
+=Android platforms=:
+it's not common do native compiling on android, Ne10 also doesn't support it.
+
 ---------------------------CROSS-COMPILING------------------------------
-For cross-compiling, the process is in the following:
+=Unix platforms=:
+For cross-compiling for unix platforms, the process is in the following:
     cd $NE10PATH
 
-Open the config.cmake and change the compiler toolchain to yourself.My toolchain is Linaro GCC 4.6.
+Open the GNUlinux_config.cmake and change the compiler toolchain to yourself.My toolchain is Linaro GCC 4.6.
 In Ubuntu 11.10 you can install it by "sudo apt-get install gcc-arm-linux-gnueabi".
     set( CMAKE_C_COMPILER arm-linux-gnueabi-gcc )
     set( CMAKE_CXX_COMPILER arm-linux-gnueabi-g++ )
@@ -63,7 +68,7 @@ In Ubuntu 11.10 you can install it by "sudo apt-get install gcc-arm-linux-gnueab
 
 Now you can use the following commands to generate makefile.
     mkdir build && cd build
-    cmake -DCMAKE_TOOLCHAIN_FILE=../config.cmake ..
+    cmake -DCMAKE_TOOLCHAIN_FILE=../GNUlinux_config.cmake ..
     make
 
 Then the libNE10.a is placed in ./modules/ and a sample program "NE10_test_static" is placed in ./samples/. you can copy these to the target and run it.
@@ -75,6 +80,18 @@ When you run NE10_test_dynamic on the target, you might meet the error:
 You can run the following command:
     export LD_LIBRARY_PATH=$NE10PATH/build/modules
 
+=Android platforms=:
+For cross-compiling for android, the note to Unix platforms also applies and before cross-compiling, you must have the android NDK installed. And then:
+   cd $NE10PATH
+   export ANDROID_NDK=/absolute/path/of/android-ndk
+   mkdir build && cd build
+   cmake -DCMAKE_TOOLCHAIN_FILE=path/of/android_config.cmake ..
+   make
+
+There are also two other environment variable:
+   ANDROID_API_LEVEL: used to specify android api level, default value is: 14
+   ARM_ANDROID_TOOLCHAIN_VERSION: used be specify gcc version, default is: 4.6, gcc version must be >=4.6
+
 ---------------------------UNIT TEST------------------------------
 
 The unit test framework of Ne10 is based on seatest(http://code.google.com/p/seatest/).
index 5d132f5..f4e408a 100644 (file)
@@ -240,6 +240,8 @@ if(NE10_BUILD_SHARED)
         ${NE10_INIT_SRCS}
     )
 
+    target_link_libraries(NE10_shared m)
+
     set_target_properties(NE10_shared PROPERTIES
         OUTPUT_NAME "NE10"
         CLEAN_DIRECT_OUTPUT 1
@@ -259,5 +261,7 @@ if(NE10_BUILD_SHARED)
         VERSION ${NE10_VERSION}
     )
 
+    target_link_libraries(NE10_test m)
+
 endif()
 
index 38e70f5..adc69fc 100644 (file)
@@ -62,12 +62,20 @@ if(NE10_ENABLE_MATH)
 
     if(NE10_BUILD_STATIC)
         add_executable(NE10_math_unit_test_static ${NE10_TEST_MATH_SRCS} ${NE10_TEST_COMMON_SRCS})
-        target_link_libraries (
-            NE10_math_unit_test_static
-            NE10
-            m
-            rt
-        )
+        if(ANDROID_PLATFORM)
+            target_link_libraries (
+                NE10_math_unit_test_static
+                NE10
+                m
+            )
+        elseif(GNULINUX_PLATFORM)
+            target_link_libraries (
+                NE10_math_unit_test_static
+                NE10
+                m
+                rt
+            )
+        endif()
         if(NE10_SMOKE_TEST)
             set_target_properties(NE10_math_unit_test_static PROPERTIES
                 OUTPUT_NAME "NE10_math_unit_test_smoke"
@@ -81,7 +89,6 @@ if(NE10_ENABLE_MATH)
                 OUTPUT_NAME "NE10_math_unit_test_performance"
             )
         endif()
-
     endif()
 endif()
 
@@ -101,12 +108,20 @@ if(NE10_ENABLE_DSP)
 
     if(NE10_BUILD_STATIC)
         add_executable(NE10_dsp_unit_test_static ${NE10_TEST_DSP_SRCS} ${NE10_TEST_COMMON_SRCS})
-        target_link_libraries (
-            NE10_dsp_unit_test_static
-            NE10
-            m
-            rt
-        )
+        if(ANDROID_PLATFORM)
+            target_link_libraries (
+                NE10_dsp_unit_test_static
+                NE10
+                m
+            )
+        elseif(GNULINUX_PLATFORM)
+            target_link_libraries (
+                NE10_dsp_unit_test_static
+                NE10
+                m
+                rt
+            )
+        endif()
         if(NE10_SMOKE_TEST)
             set_target_properties(NE10_dsp_unit_test_static PROPERTIES
                 OUTPUT_NAME "NE10_dsp_unit_test_smoke"