summaryrefslogtreecommitdiff
path: root/cmake/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/Modules')
-rw-r--r--cmake/Modules/FindUHD.cmake108
-rw-r--r--cmake/Modules/GrBuildTypes.cmake160
-rw-r--r--cmake/Modules/GrComponent.cmake6
-rw-r--r--cmake/Modules/GrMiscUtils.cmake182
4 files changed, 443 insertions, 13 deletions
diff --git a/cmake/Modules/FindUHD.cmake b/cmake/Modules/FindUHD.cmake
index b4d12b6d7b..94db092e8e 100644
--- a/cmake/Modules/FindUHD.cmake
+++ b/cmake/Modules/FindUHD.cmake
@@ -2,27 +2,113 @@
# Find the library for the USRP Hardware Driver
########################################################################
-INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(PC_UHD uhd)
+# First check to see if UHD installed its own version
+# of FindUHD, and if so use it.
-FIND_PATH(
+unset(UHD_FOUND)
+
+# obvious locations for FindUHD.cmake to already be installed are:
+# ${prefix}/share/cmake-X.Y/Modules (${CMAKE_ROOT})
+# ${prefix}/share/cmake/Modules
+# ${prefix}/lib/cmake
+# ${prefix}/lib64/cmake
+
+get_filename_component(CMAKE_ROOT_PARENT "${CMAKE_ROOT}" PATH)
+
+find_path(
+ LOCAL_FINDUHD_DIR
+ NAMES FindUHD.cmake
+ PATH_SUFFIXES cmake cmake/Modules Modules
+ HINTS ${CMAKE_MODULES_DIR}
+ PATHS ${CMAKE_ROOT}
+ ${CMAKE_ROOT_PARENT}
+ ${CMAKE_INSTALL_PREFIX}/lib
+ ${CMAKE_INSTALL_PREFIX}/lib64
+)
+
+if(LOCAL_FINDUHD_DIR)
+
+ # save the current MODULE path
+ set(SAVED_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
+
+ # remove the current directory from the MODULE path
+ list(REMOVE_ITEM CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
+
+ # prepend the found directory to the MODULE path
+ list(INSERT CMAKE_MODULE_PATH 0 ${LOCAL_FINDUHD_DIR})
+
+ # "QUITE" works on CMake 2.8+ only
+ unset(LOCAL_UHD_QUIET)
+ if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.0")
+ set(LOCAL_UHD_QUIET "QUIET")
+ endif()
+
+ # set REQUIRED, as directed
+ unset(LOCAL_UHD_REQUIRED)
+ if(UHD_FIND_REQUIRED)
+ set(LOCAL_UHD_REQUIRED "REQUIRED")
+ endif(UHD_FIND_REQUIRED)
+
+ # set VERSION to be checking, as directed
+ unset(LOCAL_UHD_VERSION)
+ if(UHD_FIND_VERSION)
+ set(LOCAL_UHD_VERSION "${UHD_FIND_VERSION}")
+ endif(UHD_FIND_VERSION)
+
+ # set EXACT, as directed, but only if VERSION was specified
+ unset(LOCAL_UHD_VERSION_EXACT)
+ if(UHD_FIND_VERSION_EXACT)
+ if(LOCAL_UHD_VERSION)
+ set(LOCAL_UHD_VERSION_EXACT "EXACT")
+ endif(LOCAL_UHD_VERSION)
+ endif(UHD_FIND_VERSION_EXACT)
+
+ # try to find UHD using the already-installed FindUHD, as directed
+ find_package(
+ UHD ${LOCAL_UHD_VERSION} ${LOCAL_UHD_VERSION_EXACT}
+ ${LOCAL_UHD_REQUIRED} ${LOCAL_UHD_QUIET}
+ )
+
+ # restore CMAKE_MODULE_PATH
+
+ set(CMAKE_MODULE_PATH ${SAVED_CMAKE_MODULE_PATH})
+
+ # print the standard message iff UHD was found
+ if(UHD_FOUND)
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(UHD DEFAULT_MSG UHD_LIBRARIES UHD_INCLUDE_DIRS)
+ endif(UHD_FOUND)
+
+endif(LOCAL_FINDUHD_DIR)
+
+# check if UHD was found above
+if(NOT UHD_FOUND)
+
+ # Not found; try the "old" method (not as robust)
+
+ include(FindPkgConfig)
+ pkg_check_modules(PC_UHD uhd)
+
+ find_path(
UHD_INCLUDE_DIRS
NAMES uhd/config.hpp
HINTS $ENV{UHD_DIR}/include
- ${PC_UHD_INCLUDEDIR}
+ ${PC_UHD_INCLUDEDIR}
PATHS /usr/local/include
/usr/include
-)
+ )
-FIND_LIBRARY(
+ find_library(
UHD_LIBRARIES
NAMES uhd
HINTS $ENV{UHD_DIR}/lib
- ${PC_UHD_LIBDIR}
+ ${PC_UHD_LIBDIR}
PATHS /usr/local/lib
/usr/lib
-)
+ )
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(UHD DEFAULT_MSG UHD_LIBRARIES UHD_INCLUDE_DIRS)
+ mark_as_advanced(UHD_LIBRARIES UHD_INCLUDE_DIRS)
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(UHD DEFAULT_MSG UHD_LIBRARIES UHD_INCLUDE_DIRS)
-MARK_AS_ADVANCED(UHD_LIBRARIES UHD_INCLUDE_DIRS)
+endif(NOT UHD_FOUND)
diff --git a/cmake/Modules/GrBuildTypes.cmake b/cmake/Modules/GrBuildTypes.cmake
new file mode 100644
index 0000000000..34614c9d08
--- /dev/null
+++ b/cmake/Modules/GrBuildTypes.cmake
@@ -0,0 +1,160 @@
+# Copyright 2014 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_BUILD_TYPES_CMAKE)
+ return()
+endif()
+set(__INCLUDED_GR_BUILD_TYPES_CMAKE TRUE)
+
+# Standard CMake Build Types and their basic CFLAGS:
+# - None: nothing set
+# - Debug: -O2 -g
+# - Release: -O3
+# - RelWithDebInfo: -O3 -g
+# - MinSizeRel: -Os
+
+# Addtional Build Types, defined below:
+# - NoOptWithASM: -O0 -g -save-temps
+# - O2WithASM: -O2 -g -save-temps
+# - O3WithASM: -O3 -g -save-temps
+
+# Defines the list of acceptable cmake build types. When adding a new
+# build type below, make sure to add it to this list.
+list(APPEND AVAIL_BUILDTYPES
+ None Debug Release RelWithDebInfo MinSizeRel
+ NoOptWithASM O2WithASM O3WithASM
+)
+
+########################################################################
+# GR_CHECK_BUILD_TYPE(build type)
+#
+# Use this to check that the build type set in CMAKE_BUILD_TYPE on the
+# commandline is one of the valid build types used by this project. It
+# checks the value set in the cmake interface against the list of
+# known build types in AVAIL_BUILDTYPES. If the build type is found,
+# the function exits immediately. If nothing is found by the end of
+# checking all available build types, we exit with an error and list
+# the avialable build types.
+########################################################################
+function(GR_CHECK_BUILD_TYPE settype)
+ STRING(TOUPPER ${settype} _settype)
+ foreach(btype ${AVAIL_BUILDTYPES})
+ STRING(TOUPPER ${btype} _btype)
+ if(${_settype} STREQUAL ${_btype})
+ return() # found it; exit cleanly
+ endif(${_settype} STREQUAL ${_btype})
+ endforeach(btype)
+ # Build type not found; error out
+ message(FATAL_ERROR "Build type '${settype}' not valid, must be one of: ${AVAIL_BUILDTYPES}")
+endfunction(GR_CHECK_BUILD_TYPE)
+
+########################################################################
+# For GCC and Clang, we can set a build type:
+#
+# -DCMAKE_BUILD_TYPE=NoOptWithASM
+#
+# This type uses no optimization (-O0), outputs debug symbols (-g) and
+# outputs all intermediary files the build system produces, including
+# all assembly (.s) files. Look in the build directory for these
+# files.
+# NOTE: This is not defined on Windows systems.
+########################################################################
+if(NOT WIN32)
+ SET(CMAKE_CXX_FLAGS_NOOPTWITHASM "-Wall -save-temps -g -O0" CACHE STRING
+ "Flags used by the C++ compiler during NoOptWithASM builds." FORCE)
+ SET(CMAKE_C_FLAGS_NOOPTWITHASM "-Wall -save-temps -g -O0" CACHE STRING
+ "Flags used by the C compiler during NoOptWithASM builds." FORCE)
+ SET(CMAKE_EXE_LINKER_FLAGS_NOOPTWITHASM
+ "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
+ "Flags used for linking binaries during NoOptWithASM builds." FORCE)
+ SET(CMAKE_SHARED_LINKER_FLAGS_NOOPTWITHASM
+ "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
+ "Flags used by the shared lib linker during NoOptWithASM builds." FORCE)
+
+ MARK_AS_ADVANCED(
+ CMAKE_CXX_FLAGS_NOOPTWITHASM
+ CMAKE_C_FLAGS_NOOPTWITHASM
+ CMAKE_EXE_LINKER_FLAGS_NOOPTWITHASM
+ CMAKE_SHARED_LINKER_FLAGS_NOOPTWITHASM)
+endif(NOT WIN32)
+
+
+
+########################################################################
+# For GCC and Clang, we can set a build type:
+#
+# -DCMAKE_BUILD_TYPE=O2WithASM
+#
+# This type uses level 2 optimization (-O2), outputs debug symbols
+# (-g) and outputs all intermediary files the build system produces,
+# including all assembly (.s) files. Look in the build directory for
+# these files.
+# NOTE: This is not defined on Windows systems.
+########################################################################
+
+if(NOT WIN32)
+ SET(CMAKE_CXX_FLAGS_O2WITHASM "-Wall -save-temps -g -O2" CACHE STRING
+ "Flags used by the C++ compiler during O2WithASM builds." FORCE)
+ SET(CMAKE_C_FLAGS_O2WITHASM "-Wall -save-temps -g -O2" CACHE STRING
+ "Flags used by the C compiler during O2WithASM builds." FORCE)
+ SET(CMAKE_EXE_LINKER_FLAGS_O2WITHASM
+ "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
+ "Flags used for linking binaries during O2WithASM builds." FORCE)
+ SET(CMAKE_SHARED_LINKER_FLAGS_O2WITHASM
+ "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
+ "Flags used by the shared lib linker during O2WithASM builds." FORCE)
+
+ MARK_AS_ADVANCED(
+ CMAKE_CXX_FLAGS_O2WITHASM
+ CMAKE_C_FLAGS_O2WITHASM
+ CMAKE_EXE_LINKER_FLAGS_O2WITHASM
+ CMAKE_SHARED_LINKER_FLAGS_O2WITHASM)
+endif(NOT WIN32)
+
+
+########################################################################
+# For GCC and Clang, we can set a build type:
+#
+# -DCMAKE_BUILD_TYPE=O3WithASM
+#
+# This type uses level 3 optimization (-O3), outputs debug symbols
+# (-g) and outputs all intermediary files the build system produces,
+# including all assembly (.s) files. Look in the build directory for
+# these files.
+# NOTE: This is not defined on Windows systems.
+########################################################################
+
+if(NOT WIN32)
+ SET(CMAKE_CXX_FLAGS_O3WITHASM "-Wall -save-temps -g -O3" CACHE STRING
+ "Flags used by the C++ compiler during O3WithASM builds." FORCE)
+ SET(CMAKE_C_FLAGS_O3WITHASM "-Wall -save-temps -g -O3" CACHE STRING
+ "Flags used by the C compiler during O3WithASM builds." FORCE)
+ SET(CMAKE_EXE_LINKER_FLAGS_O3WITHASM
+ "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
+ "Flags used for linking binaries during O3WithASM builds." FORCE)
+ SET(CMAKE_SHARED_LINKER_FLAGS_O3WITHASM
+ "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
+ "Flags used by the shared lib linker during O3WithASM builds." FORCE)
+
+ MARK_AS_ADVANCED(
+ CMAKE_CXX_FLAGS_O3WITHASM
+ CMAKE_C_FLAGS_O3WITHASM
+ CMAKE_EXE_LINKER_FLAGS_O3WITHASM
+ CMAKE_SHARED_LINKER_FLAGS_O3WITHASM)
+endif(NOT WIN32)
diff --git a/cmake/Modules/GrComponent.cmake b/cmake/Modules/GrComponent.cmake
index 5be3e8125d..031ccd7faf 100644
--- a/cmake/Modules/GrComponent.cmake
+++ b/cmake/Modules/GrComponent.cmake
@@ -90,6 +90,12 @@ function(GR_REGISTER_COMPONENT name var)
set(_gr_disabled_components ${_gr_disabled_components} CACHE INTERNAL "" FORCE)
endfunction(GR_REGISTER_COMPONENT)
+
+function(GR_APPEND_SUBCOMPONENT name)
+ list(APPEND _gr_enabled_components "* ${name}")
+ set(_gr_enabled_components ${_gr_enabled_components} CACHE INTERNAL "" FORCE)
+endfunction(GR_APPEND_SUBCOMPONENT name)
+
########################################################################
# Print the registered component summary
########################################################################
diff --git a/cmake/Modules/GrMiscUtils.cmake b/cmake/Modules/GrMiscUtils.cmake
index 3d9a5f519b..188c40480b 100644
--- a/cmake/Modules/GrMiscUtils.cmake
+++ b/cmake/Modules/GrMiscUtils.cmake
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Free Software Foundation, Inc.
+# Copyright 2010-2011,2014 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -94,7 +94,13 @@ macro(GR_ADD_CXX_COMPILER_FLAG_IF_AVAILABLE flag have)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(${flag} ${have})
if(${have})
- add_definitions(${flag})
+ if(${CMAKE_VERSION} VERSION_GREATER "2.8.4")
+ STRING(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_dup)
+ if(${flag_dup} EQUAL -1)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
+ endif(${flag_dup} EQUAL -1)
+ endif(${CMAKE_VERSION} VERSION_GREATER "2.8.4")
endif(${have})
endmacro(GR_ADD_CXX_COMPILER_FLAG_IF_AVAILABLE)
@@ -345,3 +351,175 @@ set(CMAKE_REQUIRED_LIBRARIES -lpthread)
GR_ADD_COND_DEF(HAVE_SCHED_SETSCHEDULER)
endmacro(GR_CHECK_LINUX_SCHED_AVAIL)
+########################################################################
+# Macros to generate source and header files from template
+########################################################################
+macro(GR_EXPAND_X_H component root)
+
+ include(GrPython)
+
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+"#!${PYTHON_EXECUTABLE}
+
+import sys, os, re
+sys.path.append('${GR_RUNTIME_PYTHONPATH}')
+os.environ['srcdir'] = '${CMAKE_CURRENT_SOURCE_DIR}'
+os.chdir('${CMAKE_CURRENT_BINARY_DIR}')
+
+if __name__ == '__main__':
+ import build_utils
+ root, inp = sys.argv[1:3]
+ for sig in sys.argv[3:]:
+ name = re.sub ('X+', sig, root)
+ d = build_utils.standard_dict2(name, sig, '${component}')
+ build_utils.expand_template(d, inp)
+")
+
+ #make a list of all the generated headers
+ unset(expanded_files_h)
+ foreach(sig ${ARGN})
+ string(REGEX REPLACE "X+" ${sig} name ${root})
+ list(APPEND expanded_files_h ${CMAKE_CURRENT_BINARY_DIR}/${name}.h)
+ endforeach(sig)
+ unset(name)
+
+ #create a command to generate the headers
+ add_custom_command(
+ OUTPUT ${expanded_files_h}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}.h.t
+ COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+ ${root} ${root}.h.t ${ARGN}
+ )
+
+ #install rules for the generated headers
+ list(APPEND generated_includes ${expanded_files_h})
+
+endmacro(GR_EXPAND_X_H)
+
+macro(GR_EXPAND_X_CC_H component root)
+
+ include(GrPython)
+
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+"#!${PYTHON_EXECUTABLE}
+
+import sys, os, re
+sys.path.append('${GR_RUNTIME_PYTHONPATH}')
+os.environ['srcdir'] = '${CMAKE_CURRENT_SOURCE_DIR}'
+os.chdir('${CMAKE_CURRENT_BINARY_DIR}')
+
+if __name__ == '__main__':
+ import build_utils
+ root, inp = sys.argv[1:3]
+ for sig in sys.argv[3:]:
+ name = re.sub ('X+', sig, root)
+ d = build_utils.standard_impl_dict2(name, sig, '${component}')
+ build_utils.expand_template(d, inp)
+")
+
+ #make a list of all the generated files
+ unset(expanded_files_cc)
+ unset(expanded_files_h)
+ foreach(sig ${ARGN})
+ string(REGEX REPLACE "X+" ${sig} name ${root})
+ list(APPEND expanded_files_cc ${CMAKE_CURRENT_BINARY_DIR}/${name}.cc)
+ list(APPEND expanded_files_h ${CMAKE_CURRENT_BINARY_DIR}/${name}.h)
+ endforeach(sig)
+ unset(name)
+
+ #create a command to generate the source files
+ add_custom_command(
+ OUTPUT ${expanded_files_cc}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}.cc.t
+ COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+ ${root} ${root}.cc.t ${ARGN}
+ )
+
+ #create a command to generate the header files
+ add_custom_command(
+ OUTPUT ${expanded_files_h}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}.h.t
+ COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+ ${root} ${root}.h.t ${ARGN}
+ )
+
+ #make source files depends on headers to force generation
+ set_source_files_properties(${expanded_files_cc}
+ PROPERTIES OBJECT_DEPENDS "${expanded_files_h}"
+ )
+
+ #install rules for the generated files
+ list(APPEND generated_sources ${expanded_files_cc})
+ list(APPEND generated_headers ${expanded_files_h})
+
+endmacro(GR_EXPAND_X_CC_H)
+
+macro(GR_EXPAND_X_CC_H_IMPL component root)
+
+ include(GrPython)
+
+ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+"#!${PYTHON_EXECUTABLE}
+
+import sys, os, re
+sys.path.append('${GR_RUNTIME_PYTHONPATH}')
+os.environ['srcdir'] = '${CMAKE_CURRENT_SOURCE_DIR}'
+os.chdir('${CMAKE_CURRENT_BINARY_DIR}')
+
+if __name__ == '__main__':
+ import build_utils
+ root, inp = sys.argv[1:3]
+ for sig in sys.argv[3:]:
+ name = re.sub ('X+', sig, root)
+ d = build_utils.standard_dict(name, sig, '${component}')
+ build_utils.expand_template(d, inp, '_impl')
+")
+
+ #make a list of all the generated files
+ unset(expanded_files_cc_impl)
+ unset(expanded_files_h_impl)
+ unset(expanded_files_h)
+ foreach(sig ${ARGN})
+ string(REGEX REPLACE "X+" ${sig} name ${root})
+ list(APPEND expanded_files_cc_impl ${CMAKE_CURRENT_BINARY_DIR}/${name}_impl.cc)
+ list(APPEND expanded_files_h_impl ${CMAKE_CURRENT_BINARY_DIR}/${name}_impl.h)
+ list(APPEND expanded_files_h ${CMAKE_CURRENT_BINARY_DIR}/../include/gnuradio/${component}/${name}.h)
+ endforeach(sig)
+ unset(name)
+
+ #create a command to generate the _impl.cc files
+ add_custom_command(
+ OUTPUT ${expanded_files_cc_impl}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}_impl.cc.t
+ COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+ ${root} ${root}_impl.cc.t ${ARGN}
+ )
+
+ #create a command to generate the _impl.h files
+ add_custom_command(
+ OUTPUT ${expanded_files_h_impl}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}_impl.h.t
+ COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+ ${root} ${root}_impl.h.t ${ARGN}
+ )
+
+ #make _impl.cc source files depend on _impl.h to force generation
+ set_source_files_properties(${expanded_files_cc_impl}
+ PROPERTIES OBJECT_DEPENDS "${expanded_files_h_impl}"
+ )
+
+ #make _impl.h source files depend on headers to force generation
+ set_source_files_properties(${expanded_files_h_impl}
+ PROPERTIES OBJECT_DEPENDS "${expanded_files_h}"
+ )
+
+ #install rules for the generated files
+ list(APPEND generated_sources ${expanded_files_cc_impl})
+ list(APPEND generated_headers ${expanded_files_h_impl})
+
+endmacro(GR_EXPAND_X_CC_H_IMPL)