From 902f4581372d08fa8f4ec9b2391648606d1c8c8e Mon Sep 17 00:00:00 2001 From: Toni Jones Date: Thu, 21 Feb 2019 15:05:34 -0600 Subject: cmake: Add RegMaps build component to MPM Add RegMaps build component to MPM. The PYTHON_CHECK_MODULE is included from UHDPython in order to look up the presence of Mako. Mako is required for generating the regmaps and RegMap will be disabled without it. The RegMaps component creates custom commands for generating all regmaps, creates a Python submodule "ic_reg_maps" with a custom __init__.py file, and creates a target "ic_reg_maps" which gets installed with usrp_mpm. --- mpm/python/usrp_mpm/chips/CMakeLists.txt | 1 + mpm/python/usrp_mpm/chips/__init__.py | 1 + .../usrp_mpm/chips/ic_reg_maps/CMakeLists.txt | 53 ++++++++++++++++++++++ .../usrp_mpm/chips/ic_reg_maps/__init__.py.in | 9 ++++ 4 files changed, 64 insertions(+) create mode 100755 mpm/python/usrp_mpm/chips/ic_reg_maps/CMakeLists.txt create mode 100755 mpm/python/usrp_mpm/chips/ic_reg_maps/__init__.py.in (limited to 'mpm/python/usrp_mpm') diff --git a/mpm/python/usrp_mpm/chips/CMakeLists.txt b/mpm/python/usrp_mpm/chips/CMakeLists.txt index 1f64d8e2d..484df8572 100644 --- a/mpm/python/usrp_mpm/chips/CMakeLists.txt +++ b/mpm/python/usrp_mpm/chips/CMakeLists.txt @@ -14,4 +14,5 @@ set(USRP_MPM_CHIP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/ds125df410.py ) list(APPEND USRP_MPM_FILES ${USRP_MPM_CHIP_FILES}) +add_subdirectory(ic_reg_maps) set(USRP_MPM_FILES ${USRP_MPM_FILES} PARENT_SCOPE) diff --git a/mpm/python/usrp_mpm/chips/__init__.py b/mpm/python/usrp_mpm/chips/__init__.py index 453ab5c2a..1b43ede6a 100644 --- a/mpm/python/usrp_mpm/chips/__init__.py +++ b/mpm/python/usrp_mpm/chips/__init__.py @@ -11,3 +11,4 @@ from .adf400x import ADF400x from .lmk04828 import LMK04828 from .lmk04832 import LMK04832 from .lmk03328 import LMK03328 +from . import ic_reg_maps diff --git a/mpm/python/usrp_mpm/chips/ic_reg_maps/CMakeLists.txt b/mpm/python/usrp_mpm/chips/ic_reg_maps/CMakeLists.txt new file mode 100755 index 000000000..631f30264 --- /dev/null +++ b/mpm/python/usrp_mpm/chips/ic_reg_maps/CMakeLists.txt @@ -0,0 +1,53 @@ +# +# Copyright 2019 Ettus Research, a National Instruments Brand +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +# macro for creating ic_reg_map files from a given generation file +macro(REG_MAPS_GEN_SOURCE pyfile outfile) + # ensure that the directory exists for outfile + get_filename_component(outfile_dir ${outfile} PATH) + file(MAKE_DIRECTORY ${outfile_dir}) + + # get name of outfile for the Python submodule __init__ file + get_filename_component(outfile_name ${outfile} NAME_WE) + string(APPEND REG_MAP_IMPORT "\nfrom ." ${outfile_name} " import " ${outfile_name} "_t") + + # make the outfile depend on the python script + add_custom_command( + OUTPUT ${outfile} DEPENDS ${pyfile} ${REG_MAPS_GEN_SOURCE_DEPS} + COMMAND ${PYTHON_EXECUTABLE} -B ${pyfile} ${outfile} + COMMENT "Generating ${outfile}" + ) + + # store all reg maps to be generated + set(IC_REG_MAPS ${IC_REG_MAPS} ${outfile}) +endmacro(REG_MAPS_GEN_SOURCE) + +if(ENABLE_REGMAPS) + # designate the file which will be used to generate all reg maps + set(REG_MAPS_GEN_SOURCE_DEPS ${UHD_HOST_ROOT}/lib/ic_reg_maps/common.py) + + # specify all reg maps you wish to generate + REG_MAPS_GEN_SOURCE( + ${UHD_HOST_ROOT}/lib/ic_reg_maps/gen_lmk04816_regs.py + ${CMAKE_CURRENT_BINARY_DIR}/lmk04816_regs.py + ) + + # add an ic_reg_maps target which can be referenced outside of this subdirectory + add_custom_target(ic_reg_maps DEPENDS ${IC_REG_MAPS}) + + # add new ic_reg_maps target to the list of usrp_mpm dependencies + set(USRP_MPM_FILES ${USRP_MPM_FILES}) + list(APPEND USRP_MPM_FILES ic_reg_maps) + set(USRP_MPM_FILES ${USRP_MPM_FILES} PARENT_SCOPE) +endif(ENABLE_REGMAPS) + +# write the Python submodule __init__.py by appending all generated reg map file +# names to be imported. This is not within "if(ENABLE_REGMAPS)" because MPM +# depends on the ic_reg_maps submodule regardless of whether any regmaps are +# generated. +set(REG_MAP_INIT_IN "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in") +set(REG_MAP_INIT "${CMAKE_CURRENT_BINARY_DIR}/__init__.py") +configure_file(${REG_MAP_INIT_IN} ${REG_MAP_INIT}) diff --git a/mpm/python/usrp_mpm/chips/ic_reg_maps/__init__.py.in b/mpm/python/usrp_mpm/chips/ic_reg_maps/__init__.py.in new file mode 100755 index 000000000..ce4110769 --- /dev/null +++ b/mpm/python/usrp_mpm/chips/ic_reg_maps/__init__.py.in @@ -0,0 +1,9 @@ +# +# Copyright 2019 Ettus Research, a National Instruments Brand +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +""" +ic_reg_maps submodule +""" +${REG_MAP_IMPORT} -- cgit v1.2.3