gr-fosphor: Make the different GUI version optional

You'd don't have to have glfw, qt and wx all at once, you can select
which variant you want built.

Python support is also make fully optional

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
Sylvain Munaut 2013-10-26 21:09:50 +02:00
parent 6183eefc9a
commit 180fd0042a
10 changed files with 241 additions and 36 deletions

View File

@ -92,16 +92,13 @@ set(GRC_BLOCKS_DIR ${GR_PKG_DATA_DIR}/grc/blocks)
########################################################################
# Find gr-fosphor build dependencies
########################################################################
# Required
find_package(OpenGL)
if(NOT OPENGL_FOUND)
message(FATAL_ERROR "OpenGL required to compile gr-fosphor")
endif()
find_package(GLFW3)
if (NOT GLFW3_FOUND)
message(FATAL_ERROR "GLFW3 required to compile gr-fosphor")
endif()
find_package(OpenCL)
if(NOT OPENCL_FOUND)
message(FATAL_ERROR "OpenCL required to compile gr-fosphor")
@ -112,9 +109,13 @@ if(NOT FREETYPE2_FOUND)
message(FATAL_ERROR "freetype2 required to compile gr-fosphor")
endif()
find_package(Qt4 4.2.0 COMPONENTS QtCore QtGui QtOpenGL)
include(GrSetupQt4)
# Optional
find_package(GLFW3)
find_package(Qt4 4.2.0 COMPONENTS QtCore QtGui QtOpenGL)
if (QT_FOUND)
include(GrSetupQt4)
endif (QT_FOUND)
########################################################################
# Find gnuradio build dependencies
@ -131,6 +132,38 @@ endif()
find_package(Doxygen)
find_package(PythonLibs 2)
find_package(SWIG)
########################################################################
# Setup the components
########################################################################
include(GrComponent)
GR_REGISTER_COMPONENT("Python" ENABLE_PYTHON
PYTHONLIBS_FOUND SWIG_FOUND
)
GR_REGISTER_COMPONENT("GLFW" ENABLE_GLFW
GLFW3_FOUND
)
GR_REGISTER_COMPONENT("QT" ENABLE_QT
QT_FOUND
)
GR_REGISTER_COMPONENT("WX" ENABLE_WX
PYTHONLIBS_FOUND SWIG_FOUND ENABLE_PYTHON
)
macro(list_cond_append cond list_name)
if(${cond})
list(APPEND ${list_name} ${ARGN})
endif(${cond})
endmacro(list_cond_append)
########################################################################
# Setup the include and linker paths
########################################################################
@ -168,10 +201,14 @@ add_custom_target(uninstall
########################################################################
add_subdirectory(include/gnuradio/fosphor)
add_subdirectory(lib)
add_subdirectory(swig)
add_subdirectory(python)
add_subdirectory(grc)
add_subdirectory(apps)
if(ENABLE_PYTHON)
add_subdirectory(swig)
add_subdirectory(python)
add_subdirectory(grc)
add_subdirectory(apps)
endif(ENABLE_PYTHON)
add_subdirectory(docs)
########################################################################
@ -191,3 +228,8 @@ install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-fosphor.pc
DESTINATION ${GR_LIBRARY_DIR}/pkgconfig
)
########################################################################
# Print Summary
########################################################################
GR_PRINT_COMPONENT_SUMMARY()

View File

@ -0,0 +1,115 @@
# Copyright 2010-2011 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
if(DEFINED __INCLUDED_GR_COMPONENT_CMAKE)
return()
endif()
set(__INCLUDED_GR_COMPONENT_CMAKE TRUE)
set(_gr_enabled_components "" CACHE INTERNAL "" FORCE)
set(_gr_disabled_components "" CACHE INTERNAL "" FORCE)
if(NOT DEFINED ENABLE_DEFAULT)
set(ENABLE_DEFAULT ON)
message(STATUS "")
message(STATUS "The build system will automatically enable all components.")
message(STATUS "Use -DENABLE_DEFAULT=OFF to disable components by default.")
endif()
########################################################################
# Register a component into the system
# - name: canonical component name
# - var: variable for enabled status
# - argn: list of dependencies
########################################################################
function(GR_REGISTER_COMPONENT name var)
include(CMakeDependentOption)
message(STATUS "")
message(STATUS "Configuring ${name} support...")
foreach(dep ${ARGN})
message(STATUS " Dependency ${dep} = ${${dep}}")
endforeach(dep)
#if the user set the var to force, we note this
if("${${var}}" STREQUAL "FORCE")
set(${var} ON)
set(var_force TRUE)
else()
set(var_force FALSE)
endif()
#rewrite the dependency list so that deps that are also components use the cached version
unset(comp_deps)
foreach(dep ${ARGN})
list(FIND _gr_enabled_components ${dep} dep_enb_index)
list(FIND _gr_disabled_components ${dep} dep_dis_index)
if (${dep_enb_index} EQUAL -1 AND ${dep_dis_index} EQUAL -1)
list(APPEND comp_deps ${dep})
else()
list(APPEND comp_deps ${dep}_cached) #is a component, use cached version
endif()
endforeach(dep)
#setup the dependent option for this component
CMAKE_DEPENDENT_OPTION(${var} "enable ${name} support" ${ENABLE_DEFAULT} "${comp_deps}" OFF)
set(${var} "${${var}}" PARENT_SCOPE)
set(${var}_cached "${${var}}" CACHE INTERNAL "" FORCE)
#force was specified, but the dependencies were not met
if(NOT ${var} AND var_force)
message(FATAL_ERROR "user force-enabled ${name} but configuration checked failed")
endif()
#append the component into one of the lists
if(${var})
message(STATUS " Enabling ${name} support.")
list(APPEND _gr_enabled_components ${name})
else(${var})
message(STATUS " Disabling ${name} support.")
list(APPEND _gr_disabled_components ${name})
endif(${var})
message(STATUS " Override with -D${var}=ON/OFF")
#make components lists into global variables
set(_gr_enabled_components ${_gr_enabled_components} CACHE INTERNAL "" FORCE)
set(_gr_disabled_components ${_gr_disabled_components} CACHE INTERNAL "" FORCE)
endfunction(GR_REGISTER_COMPONENT)
########################################################################
# Print the registered component summary
########################################################################
function(GR_PRINT_COMPONENT_SUMMARY)
message(STATUS "")
message(STATUS "######################################################")
message(STATUS "# gr-fosphor enabled components ")
message(STATUS "######################################################")
foreach(comp ${_gr_enabled_components})
message(STATUS " * ${comp}")
endforeach(comp)
message(STATUS "")
message(STATUS "######################################################")
message(STATUS "# gr-fosphor disabled components ")
message(STATUS "######################################################")
foreach(comp ${_gr_disabled_components})
message(STATUS " * ${comp}")
endforeach(comp)
message(STATUS "")
endfunction(GR_PRINT_COMPONENT_SUMMARY)

View File

@ -16,9 +16,12 @@
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
list_cond_append(ENABLE_GLFW fosphor_grc fosphor_glfw_sink_c.xml)
list_cond_append(ENABLE_QT fosphor_grc fosphor_qt_sink_c.xml)
list_cond_append(ENABLE_WX fosphor_grc fosphor_wx_sink_c.xml)
install(FILES
fosphor_glfw_sink_c.xml
fosphor_qt_sink_c.xml
fosphor_wx_sink_c.xml
${fosphor_grc}
DESTINATION share/gnuradio/grc/blocks
)

View File

@ -20,11 +20,16 @@
########################################################################
# Install public header files
########################################################################
install(FILES
list(APPEND fosphor_headers
api.h
base_sink_c.h
glfw_sink_c.h
qt_sink_c.h
wx_core_sink_c.h
)
list_cond_append(ENABLE_GLFW fosphor_headers glfw_sink_c.h)
list_cond_append(ENABLE_QT fosphor_headers qt_sink_c.h)
list_cond_append(ENABLE_WX fosphor_headers wx_core_sink_c.h)
install(FILES
${fosphor_headers}
DESTINATION include/gnuradio/fosphor
)

View File

@ -23,7 +23,6 @@
include(GrPlatform) #define LIB_SUFFIX
include(GrMiscUtils)
find_package(PythonLibs 2)
find_package(PythonInterp 2)
add_custom_command(
@ -36,22 +35,31 @@ add_custom_command(
include_directories(
${OPENGL_INCLUDE_DIRS}
${GLFW3_INCLUDE_DIRS}
${OPENCL_INCLUDE_DIRS}
${FREETYPE2_INCLUDE_DIRS}
${Boost_INCLUDE_DIR}
${PYTHON_INCLUDE_DIRS}
${QT_INCLUDE_DIRS}
)
link_directories(
${OPENGL_LIBRARY_DIRS}
${GLFW3_LIBRARY_DIRS}
${OPENCL_LIBRARY_DIRS}
${FREETYPE2_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS}
)
set(CMAKE_AUTOMOC ON)
if(ENABLE_PYTHON)
add_definitions(-DENABLE_PYTHON)
include_directories(${PYTHON_INCLUDE_DIRS})
endif(ENABLE_PYTHON)
if(ENABLE_GLFW)
include_directories(${GLFW3_INCLUDE_DIRS})
link_directories(${GLFW3_LIBRARY_DIRS})
endif(ENABLE_GLFW)
if(ENABLE_QT)
set(CMAKE_AUTOMOC ON)
include_directories(${QT_INCLUDE_DIRS})
endif(ENABLE_QT)
list(APPEND fosphor_sources
fosphor/cl.c
@ -63,23 +71,26 @@ list(APPEND fosphor_sources
fosphor/resource.c
fosphor/resource_data.c
fifo.cc
QGLSurface.cc
base_sink_c_impl.cc
glfw_sink_c_impl.cc
qt_sink_c_impl.cc
wx_core_sink_c_impl.cc
)
add_library(gnuradio-fosphor SHARED ${fosphor_sources})
target_link_libraries(gnuradio-fosphor
list_cond_append(ENABLE_GLFW fosphor_sources glfw_sink_c_impl.cc)
list_cond_append(ENABLE_QT fosphor_sources QGLSurface.cc qt_sink_c_impl.cc)
list_cond_append(ENABLE_WX fosphor_sources wx_core_sink_c_impl.cc)
list(APPEND fosphor_libraries
${OPENGL_LIBRARIES}
${GLFW3_LIBRARIES}
${OPENCL_LIBRARIES}
${FREETYPE2_LIBRARIES}
${Boost_LIBRARIES}
${GNURADIO_RUNTIME_LIBRARIES}
${QT_LIBRARIES}
)
list_cond_append(ENABLE_GLFW fosphor_libraries ${GLFW3_LIBRARIES})
list_cond_append(ENABLE_QT fosphor_libraries ${QT_LIBRARIES})
add_library(gnuradio-fosphor SHARED ${fosphor_sources})
target_link_libraries(gnuradio-fosphor ${fosphor_libraries})
set_target_properties(gnuradio-fosphor PROPERTIES DEFINE_SYMBOL "gnuradio_fosphor_EXPORTS")
GR_LIBRARY_FOO(gnuradio-fosphor)

View File

@ -18,7 +18,9 @@
* Boston, MA 02110-1301, USA.
*/
#include <Python.h>
#ifdef ENABLE_PYTHON
# include <Python.h>
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -85,6 +87,7 @@ qt_sink_c_impl::glctx_fini()
}
#ifdef ENABLE_PYTHON
PyObject*
qt_sink_c_impl::pyqwidget()
{
@ -92,6 +95,13 @@ qt_sink_c_impl::pyqwidget()
PyObject *retarg = Py_BuildValue("N", w);
return retarg;
}
#else
void*
qt_sink_c_impl::pyqwidget()
{
return NULL;
}
#endif
} /* namespace fosphor */
} /* namespace gr */

View File

@ -28,10 +28,15 @@ endif()
########################################################################
# Install python sources
########################################################################
list(APPEND fosphor_python
__init__.py
)
list_cond_append(ENABLE_WX fosphor_python wx_sink_c.py)
GR_PYTHON_INSTALL(
FILES
__init__.py
wx_sink_c.py
${fosphor_python}
DESTINATION ${GR_PYTHON_DIR}/gnuradio/fosphor
)

View File

@ -45,7 +45,11 @@ if _RTLD_GLOBAL != 0:
from fosphor_swig import *
# import any pure python here
from wx_sink_c import wx_sink_c
try:
from wx_sink_c import wx_sink_c
except ImportError:
# No WX support most likely
pass
#
# ----------------------------------------------------------------

View File

@ -39,6 +39,10 @@ set(GR_SWIG_LIBRARIES gnuradio-fosphor)
set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/fosphor_swig_doc.i)
set(GR_SWIG_DOC_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../include/gnuradio/fosphor)
list_cond_append(ENABLE_GLFW GR_SWIG_FLAGS -DENABLE_GLFW)
list_cond_append(ENABLE_QT GR_SWIG_FLAGS -DENABLE_QT)
list_cond_append(ENABLE_WX GR_SWIG_FLAGS -DENABLE_WX)
GR_SWIG_MAKE(fosphor_swig fosphor_swig.i)
########################################################################

View File

@ -16,12 +16,18 @@
%include "gnuradio/fosphor/base_sink_c.h"
#ifdef ENABLE_GLFW
%nodefaultctor gr::fosphor::glfw_sink_c; // bug workaround
%include "gnuradio/fosphor/glfw_sink_c.h"
GR_SWIG_BLOCK_MAGIC2(fosphor, glfw_sink_c);
#endif
#ifdef ENABLE_QT
%include "gnuradio/fosphor/qt_sink_c.h"
GR_SWIG_BLOCK_MAGIC2(fosphor, qt_sink_c);
#endif
#ifdef ENABLE_WX
%include "gnuradio/fosphor/wx_core_sink_c.h"
GR_SWIG_BLOCK_MAGIC2(fosphor, wx_core_sink_c);
#endif