#/******************************************************************************
 #* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
 #*   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 Texas Instruments Incorporated 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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.
 #*****************************************************************************/
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

SET(CMAKE_SYSTEM_PROCESSOR ARM)

SET(CMAKE_C_COMPILER   arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)

# For external builds, paths to dependent libraries/packages are assumed to
# be specified by environment variables.
# For internal development builds setup a default path for dependent libs/pkgs
if ("$ENV{DEFAULT_DEV_INSTALL_DIR}" STREQUAL "")
   set(DEFAULT_DEV_INSTALL_DIR /opt/ti)
else()
   set(DEFAULT_DEV_INSTALL_DIR $ENV{DEFAULT_DEV_INSTALL_DIR})
endif()

# Point to the development kit file system where we should get ARM
# libraries and headers
if ("$ENV{LINUX_DEVKIT_ROOT}" STREQUAL "")
   SET(LINUX_DEVKIT_ROOT ${DEFAULT_DEV_INSTALL_DIR}/mcsdk_linux_3_00_04_18/linux-devkit/arago-2013.12/sysroots/cortexa15hf-vfp-neon-3.8-oe-linux-gnueabi)
   MESSAGE(STATUS "Environment variable LINUX_DEVKIT_ROOT not set. "
                  "Assuming the linux devkit filesystem is installed "
                  "at ${LINUX_DEVKIT_ROOT}")
else()
    SET(LINUX_DEVKIT_ROOT $ENV{LINUX_DEVKIT_ROOT})
    MESSAGE(STATUS "LINUX_DEVKIT_ROOT set to ${LINUX_DEVKIT_ROOT}")
endif()

# Point to the TARGET_ROOTDIR filesystem install path
# If it isn't defined, then native compilation is in progress and OpenCL will
# be available in standard locations /usr/lib,include.
# If it is defined, then cross compilation is in progress and OpenCL will be 
# available in $TARGET_ROOTDIR/usr/lib,include.
IF ("$ENV{TARGET_ROOTDIR}" STREQUAL "")
    MESSAGE(STATUS "TARGET_ROOTDIR not defined, assuming native compilation")
    SET(TARGET_ROOTDIR /)
ELSE()
    SET(TARGET_ROOTDIR $ENV{TARGET_ROOTDIR})
    MESSAGE(STATUS "TARGET_ROOTDIR set to ${TARGET_ROOTDIR}")
ENDIF()

# Target environment: Set paths to look for target libs and includes within
SET(CMAKE_FIND_ROOT_PATH $ENV{LINUX_DEVKIT_ROOT} $ENV{TARGET_ROOTDIR})

# Search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# For libraries and headers in the target directories
# The option ONLY makes cmake look only within the CMAKE_ROOT_PATH's 
# for headers and libraries that are needed for the target build
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH true)
