
cmake_minimum_required(VERSION 3.5)
project( rt_service NONE )

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7-a)
set(SYSROOTS home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/SDK/sysroots)


set(TOOLCHAIN_PREFIX $ENV{SYSROOTS}/x86_64-ostl_sdk-linux/usr/bin/arm-ostl-linux-gnueabi/arm-ostl-linux-gnueabi-)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)

set(CMAKE_SYSROOT $ENV{SYSROOTS}/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi)

set(CMAKE_PREFIX_PATH ${CMAKE_SYSROOT}/usr/lib/cmake)
# set(OE_QMAKE_PATH_EXTERNAL_HOST_BINS $ENV{QT_BIN_PATH})  => only for QT not needed at the moment

set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=<SDK installation directory>/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
set(COMPILER_FLAGS " -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}" CACHE STRING "" FORCE)


list(APPEND CMAKE_MODULE_PATH "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/ cortexa7t2hf-neon-vfpv4/python3/usr")

list(APPEND CMAKE_MODULE_PATH "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/ cortexa7t2hf-neon-vfpv4/boost/usr")


# set(PYTHON_LIBRARIES "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/ cortexa7t2hf-neon-vfpv4/python3/usr/lib") 

# set(PYTHON_INCLUDE_DIRS "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/cortexa7t2hf-neon-vfpv4/python3/usr/include") 


# set(CMAKE_C_COMPILER_WORKS 1)
# set(CMAKE_CXX_COMPILER_WORKS 1)
# set(TOOLCHAIN_PREFIX home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/SDK/sysroots/x86_64-ostl_sdk-linux/usr/bin/arm-ostl-linux/)
# set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
# set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)

# set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")


# Find python and Boost - both are required dependencies
# find_package(PythonLibs REQUIRED)
# find_package(PythonLibs 3.10 REQUIRED)
# find_package(Boost REQUIRED)
# find_package(Boost COMPONENTS python REQUIRED)

# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")

add_definitions(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)


# set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
# set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
# set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


#set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# set (CMAKE_RUNTIME_OUTPUT_DIRECTORY /home/markus/git/vrpmdvweb/vrpmdvserver/extensions/rt_service)


# Add a shared module - modules are intended to be imported at runtime.
# - This is where you add the source files
add_library(rt_service MODULE rt_service.cpp)

set_target_properties(rt_service PROPERTIES LINKER_LANGUAGE CXX)
# this is probably unlikely to be needed, but just in case
set(CMAKE_CXX_FLAGS "-m32")
set(CMAKE_EXE_LINKER_FLAGS    "-m32 -L${LIB32}" CACHE STRING "executable linker flags"     FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "shared library linker flags" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "module linker flags"         FORCE)
# set_target_properties(rt_service PROPERTIES COMPILE_OPTIONS "-m32")


# Set up the libraries and header search paths for this target
target_link_libraries(rt_service ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_include_directories(rt_service PRIVATE ${PYTHON_INCLUDE_DIRS})

set(MY_RESOURCE_FILE rt_service.so)
#set_directory_properties(MY_EXTENSION_LIB /home/markus/git/vrpmwvweb/vrpmdvserver/extensions/)
#file(COPY ${CMAKE_CURRENT_BINARY_DIR}/${MY_RESOURCE_FILE}
#     DESTINATION /home/markus/git/vrpmdvweb/vrpmdvserver/extensions/rt_service)


# location of the Python header files
#PYTHON_VERSION = 3.10
#PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
# location of the Boost Python include files and library
#BOOST_INC = /usr/include
#BOOST_LIB = /usr/lib
# compile mesh classes
#TARGET = rt_service
#$(TARGET).so: $(TARGET).o	g++ -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -lboost_python-$(PYTHON_VERSION) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) -o $(TARGET).so
#$(TARGET).o: $(TARGET).cpp	g++ -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp
