damaris-backends/drivers/Spectrum-MI40xxSeries/CMakeLists.txt
2019-06-04 17:08:47 +02:00

85 lines
3.9 KiB
CMake

cmake_minimum_required(VERSION 3.0)
# unpack headers needed
set(SPC_DRV drv_header_v402b6844.zip)
set(SPC_HEADERS
include/spcerr.h
include/regs.h
include/dlltyp.h
include/spcioctl.inc)
add_custom_command(OUTPUT ${SPC_HEADERS}
COMMAND unzip -o -q -u ${SPC_DRV} "*.h" "*.txt" "*.inc" -d include/
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Unpacking SPC headers"
VERBATIM)
# Kernelmodule is build from NDA source code.
# just go to the current directory and tar xfz drvsrc_all_V*.tgz
# this will usually create a "linux" folder
# the actual kernel source file is in the src_all/micx_drv subfolder.
# If the "linux" folder exists the driver will be build.
# Alternatively you can set the SPC_SOURCE environment variable to the micx_drv folder
file(GLOB MILIST "drvsrc_all_V*.tgz" )
# sort and select last (alphabetic order) tarball driver
list(SORT MILIST)
if(MILIST)
list(GET MILIST -1 MITGZ )
else()
set(MITGZ "non-existing-file")
endif()
#message(STATUS ${MITGZ})
if(EXISTS ${MITGZ})
message(STATUS "Using spectrum driver source tarball: " ${MITGZ})
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/linux/src_all/micx_drv
COMMAND tar xfvz ${MITGZ}
COMMAND cp -v ${CMAKE_CURRENT_SOURCE_DIR}/linux/src_all/micx_drv/makefile.kernel26 ${CMAKE_CURRENT_SOURCE_DIR}/linux/src_all/micx_drv/Makefile
COMMAND sed -i "s/Wno-deprecated-declarations/w/" ${CMAKE_CURRENT_SOURCE_DIR}/linux/src_all/micx_drv/Makefile
# fails on jessie
COMMAND sed -i "s/-Wno-error=date-time//g" ${CMAKE_CURRENT_SOURCE_DIR}/linux/src_all/micx_drv/Makefile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Unpacking Spectrum driver tarball"
VERBATIM)
set(SPC_SRC "${CMAKE_CURRENT_SOURCE_DIR}/linux/src_all/micx_drv")
add_custom_target(spc_smp ALL DEPENDS ${SPC_SRC})
elseif(DEFINED ENV{SPC_SOURCE})
message(STATUS "SPC_SOURCE environment variable set: " $ENV{SPC_SOURCE})
set(SPC_SRC $ENV{SPC_SOURCE})
add_custom_target(spc_smp ALL DEPENDS ${SPC_SRC})
else()
set(SPC_SRC "${CMAKE_CURRENT_SOURCE_DIR}/linux/src_all/micx_drv")
message("\nIf you have signed the NDA from Spectrum and got a kernel driver tarball (i.e. drvsrc_all_V*.tgz), put it in:\n\n\t" ${CMAKE_CURRENT_SOURCE_DIR} "\n\nto get a kernel module built\n")
message(WARNING "Spectrum driver source path not defined in envirnoment variable SPC_SOURCE,\nusing default: " ${SPC_SRC})
endif()
set(DRIVER_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB KERNEL_VERSIONS_DIR RELATIVE "/lib/modules" "/lib/modules/*/build")
foreach(KERNEL_DIR ${KERNEL_VERSIONS_DIR})
string(REPLACE "/build" "" KERNEL_VERSION ${KERNEL_DIR})
message(STATUS "Compiling spc_smp.ko for kernel: " ${KERNEL_VERSION})
set(DRIVER_FILE ${KERNEL_VERSION}/spc_smp.ko )
set(KBUILD_CMD ${CMAKE_MAKE_PROGRAM}
-C "/lib/modules/${KERNEL_DIR}"
M=${SPC_SRC} modules)
add_custom_command(OUTPUT ${DRIVER_FILE}
COMMAND ${KBUILD_CMD}
COMMAND mkdir -p ${DRIVER_DIRECTORY}/${KERNEL_VERSION}
COMMAND cp -fv ${SPC_SRC}/spc_smp.ko ${DRIVER_DIRECTORY}/${KERNEL_VERSION}/spc_smp.ko
COMMENT "Building spc_smp.ko for kernel version: " ${KERNEL_VERSION}
WORKING_DIRECTORY ${SPC_SRC}
VERBATIM)
add_custom_target (micx_drv_${KERNEL_VERSION} ALL DEPENDS ${DRIVER_FILE})
add_dependencies (micx_drv_${KERNEL_VERSION} spc_smp)
install(FILES ${DRIVER_FILE} DESTINATION /lib/modules/${KERNEL_VERSION}/kernel/damaris)
endforeach(KERNEL_DIR)
add_library(Spectrum_MI40xxSeries STATIC Spectrum-MI40xxSeries.cpp GatedData.cpp ${SPC_HEADERS})
add_executable(hw_test_ext hw_test_extclock.cpp GatedData.cpp ${SPC_HEADERS})
#target_sources(hw_test_ext PRIVATE ${SPC_HEADERS})
add_executable(hw_test_int hw_test_intclock.cpp GatedData.cpp ${SPC_HEADERS})
#target_include_directories(hw_test_int ${SPC_HEADERS})