blob: bcb1b38ff75eef3053451edf190e39b422e7c5f0 [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
33macro(GRCC_COMPILE file_name)
34 if(${CMAKE_VERSION} VERSION_LESS "3.2.0") #use wrapper script to set the environment on systems without cmake 3.2
35 ADD_CUSTOM_COMMAND(
36 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${file_name}
37 COMMAND /bin/sh ${CMAKE_SOURCE_DIR}/cmake/Modules/GrccCompileWrapper.sh "${PYTHONPATH}" "${CMAKE_SOURCE_DIR}/grc" "${PC_GNURADIO_RUNTIME_PREFIX}/${GR_RUNTIME_DIR}/grcc -d ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.grc"
38 COMMAND "${CMAKE_COMMAND}" -E rename ${CMAKE_CURRENT_BINARY_DIR}/${file_name}.py ${CMAKE_CURRENT_BINARY_DIR}/${file_name}
39 DEPENDS ${file_name}.grc
40 )
41 else() #for the rest use new/more portable way
42 ADD_CUSTOM_COMMAND(
43 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${file_name}
44 COMMAND "${CMAKE_COMMAND}"
45 -E env PYTHONPATH="${PYTHONPATH}" GRC_BLOCKS_PATH=${CMAKE_SOURCE_DIR}/grc
46 ${PC_GNURADIO_RUNTIME_PREFIX}/${GR_RUNTIME_DIR}/grcc -d ${CMAKE_CURRENT_BINARY_DIR}
47 ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.grc
48 COMMAND "${CMAKE_COMMAND}" -E rename ${CMAKE_CURRENT_BINARY_DIR}/${file_name}.py ${CMAKE_CURRENT_BINARY_DIR}/${file_name}
49 DEPENDS ${file_name}.grc
50 )
51 endif()
52endmacro(GRCC_COMPILE)
53
54########################################################################
55# Override the GR_UNIQUE_TARGET function to not append a hash
56# to the `target` name, because we need a known name in order
57# to add an explicit dependency that's needed for the parallel build
58#
59# The original code segment (taken from GrPython.cmake) is
60#
61# execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import re, hashlib
62#unique = hashlib.md5('${reldir}${ARGN}').hexdigest()[:5]
63#print(re.sub('\\W', '_', '${desc} ${reldir} ' + unique))"
64# OUTPUT_VARIABLE _target OUTPUT_STRIP_TRAILING_WHITESPACE)
65#
66########################################################################
67function(GR_UNIQUE_TARGET desc)
68 file(RELATIVE_PATH reldir ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
69 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import re, hashlib
70print(re.sub('\\W', '_', '${desc} ${reldir}'))"
71 OUTPUT_VARIABLE _target OUTPUT_STRIP_TRAILING_WHITESPACE)
72 add_custom_target(${_target} ALL DEPENDS ${ARGN})
73endfunction(GR_UNIQUE_TARGET)