blob: d2bc2d8efa6e42feac454116320914aa6c9a8943 [file] [log] [blame]
Piotr Krysikf00936d2018-06-18 14:59:18 +02001# Author (C) 2018 by Piotr Krysik <ptrkrysik@gmail.com>
2# Author (C) 2018 by Vasil Velichkov <vvvelichkov@gmail.com>
3#
4# This file is part of GNU Radio
5#
6# GNU Radio is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3, or (at your option)
9# any later version.
10#
11# GNU Radio is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with GNU Radio; see the file COPYING. If not, write to
18# the Free Software Foundation, Inc., 51 Franklin Street,
19# Boston, MA 02110-1301, USA.
20
21SET(PYTHONPATH
22 ${CMAKE_SOURCE_DIR}/python
23 ${CMAKE_SOURCE_DIR}/python/misc_utils
24 ${CMAKE_SOURCE_DIR}/python/demapping
25 ${CMAKE_SOURCE_DIR}/python/receiver
26 ${CMAKE_SOURCE_DIR}/python/transmitter
27 ${CMAKE_SOURCE_DIR}/python/trx
28 ${CMAKE_BINARY_DIR}/swig
29 $ENV{PYTHONPATH}
30 )
31string(REPLACE ";" ":" PYTHONPATH "${PYTHONPATH}")
32
Vasil Velichkov1789ae22019-08-13 20:32:05 +000033find_program(GRCC grcc
34 PATHS ${CMAKE_INSTALL_PREFIX}/${GR_RUNTIME_DIR}
35 )
36
Piotr Krysikf00936d2018-06-18 14:59:18 +020037macro(GRCC_COMPILE file_name)
Vasil Velichkov1789ae22019-08-13 20:32:05 +000038 ADD_CUSTOM_COMMAND(
39 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${file_name}
40 COMMAND "${CMAKE_COMMAND}"
41 -E env PYTHONPATH="${PYTHONPATH}" GRC_BLOCKS_PATH=${CMAKE_SOURCE_DIR}/grc
Vasil Velichkov6eea94f2019-09-08 02:47:57 +030042 CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}
Vasil Velichkov1789ae22019-08-13 20:32:05 +000043 ${GRCC} -o ${CMAKE_CURRENT_BINARY_DIR}
44 ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.grc
45 COMMAND "${CMAKE_COMMAND}" -E rename ${CMAKE_CURRENT_BINARY_DIR}/${file_name}.py ${CMAKE_CURRENT_BINARY_DIR}/${file_name}
46 DEPENDS ${file_name}.grc
Piotr Krysikf00936d2018-06-18 14:59:18 +020047 )
Piotr Krysikf00936d2018-06-18 14:59:18 +020048endmacro(GRCC_COMPILE)
49
50########################################################################
51# Override the GR_UNIQUE_TARGET function to not append a hash
52# to the `target` name, because we need a known name in order
53# to add an explicit dependency that's needed for the parallel build
54#
55# The original code segment (taken from GrPython.cmake) is
56#
57# execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import re, hashlib
58#unique = hashlib.md5('${reldir}${ARGN}').hexdigest()[:5]
59#print(re.sub('\\W', '_', '${desc} ${reldir} ' + unique))"
60# OUTPUT_VARIABLE _target OUTPUT_STRIP_TRAILING_WHITESPACE)
61#
62########################################################################
63function(GR_UNIQUE_TARGET desc)
64 file(RELATIVE_PATH reldir ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
65 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import re, hashlib
66print(re.sub('\\W', '_', '${desc} ${reldir}'))"
67 OUTPUT_VARIABLE _target OUTPUT_STRIP_TRAILING_WHITESPACE)
68 add_custom_target(${_target} ALL DEPENDS ${ARGN})
69endfunction(GR_UNIQUE_TARGET)