diff options
Diffstat (limited to 'cmake/Modules')
-rw-r--r-- | cmake/Modules/FindUHD.cmake | 79 | ||||
-rw-r--r-- | cmake/Modules/GrBuildTypes.cmake | 160 | ||||
-rw-r--r-- | cmake/Modules/GrComponent.cmake | 6 | ||||
-rw-r--r-- | cmake/Modules/GrMiscUtils.cmake | 182 | ||||
-rw-r--r-- | cmake/Modules/GrSwig.cmake | 6 |
5 files changed, 417 insertions, 16 deletions
diff --git a/cmake/Modules/FindUHD.cmake b/cmake/Modules/FindUHD.cmake index b4d12b6d7b..cfb89b11ce 100644 --- a/cmake/Modules/FindUHD.cmake +++ b/cmake/Modules/FindUHD.cmake @@ -2,27 +2,84 @@ # Find the library for the USRP Hardware Driver ######################################################################## -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(PC_UHD uhd) +# make this file non-reentrant +if(__INCLUDED_FIND_UHD_CMAKE) + return() +endif() +set(__INCLUDED_FIND_UHD_CMAKE TRUE) -FIND_PATH( +# First check to see if UHD installed its own CMake files + +# save the current MODULE path +set(SAVED_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) + +# clear the current MODULE path; uses system paths only +unset(CMAKE_MODULE_PATH) + +# try to find UHD via the provided parameters, +# handle REQUIRED internally later +unset(UHD_FOUND) + +# was the version specified? +unset(LOCAL_UHD_FIND_VERSION) +if(UHD_FIND_VERSION) + set(LOCAL_UHD_FIND_VERSION ${UHD_FIND_VERSION}) +endif(UHD_FIND_VERSION) + +# was EXACT specified? +unset(LOCAL_UHD_FIND_VERSION_EXACT) +if(UHD_FIND_VERSION_EXACT) + set(LOCAL_UHD_FIND_VERSION_EXACT "EXACT") +endif(UHD_FIND_VERSION_EXACT) + +# try to find UHDConfig using the desired parameters; +# UHDConfigVersion will catch a pass-through version bug ... +find_package( + UHD ${LOCAL_UHD_FIND_VERSION} + ${LOCAL_UHD_FIND_VERSION_EXACT} QUIET +) + +# restore CMAKE_MODULE_PATH +set(CMAKE_MODULE_PATH ${SAVED_CMAKE_MODULE_PATH}) + +# 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 -) + ) +endif(NOT UHD_FOUND) + +if(UHD_LIBRARIES AND UHD_INCLUDE_DIRS) + + # if UHDConfig set UHD_FOUND==TRUE, then these have already been + # done, but done quietly. It does not hurt to redo them here. + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(UHD DEFAULT_MSG UHD_LIBRARIES UHD_INCLUDE_DIRS) + mark_as_advanced(UHD_LIBRARIES UHD_INCLUDE_DIRS) + +elseif(UHD_FIND_REQUIRED) + + message(FATAL_ERROR "UHD is required, but was not found.") -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(UHD DEFAULT_MSG UHD_LIBRARIES UHD_INCLUDE_DIRS) -MARK_AS_ADVANCED(UHD_LIBRARIES UHD_INCLUDE_DIRS) +endif() 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) diff --git a/cmake/Modules/GrSwig.cmake b/cmake/Modules/GrSwig.cmake index 68c4f0a58a..abf4dc4612 100644 --- a/cmake/Modules/GrSwig.cmake +++ b/cmake/Modules/GrSwig.cmake @@ -39,7 +39,7 @@ function(GR_SWIG_MAKE_DOCS output_file) set(input_files) unset(INPUT_PATHS) foreach(input_path ${ARGN}) - if (IS_DIRECTORY ${input_path}) #when input path is a directory + if(IS_DIRECTORY ${input_path}) #when input path is a directory file(GLOB input_path_h_files ${input_path}/*.h) else() #otherwise its just a file, no glob set(input_path_h_files ${input_path}) @@ -110,7 +110,7 @@ macro(GR_SWIG_MAKE name) # vector<long unsigned int> (on 64-bit machines). Use this to test # the size of size_t, then set SIZE_T_32 if it's a 32-bit machine # or not if it's 64-bit. The logic in gr_type.i handles the rest. - INCLUDE (CheckTypeSize) + INCLUDE(CheckTypeSize) CHECK_TYPE_SIZE("size_t" SIZEOF_SIZE_T) CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT) if(${SIZEOF_SIZE_T} EQUAL ${SIZEOF_UINT}) @@ -118,7 +118,7 @@ macro(GR_SWIG_MAKE name) endif(${SIZEOF_SIZE_T} EQUAL ${SIZEOF_UINT}) #do swig doc generation if specified - if (GR_SWIG_DOC_FILE) + if(GR_SWIG_DOC_FILE) set(GR_SWIG_DOCS_SOURCE_DEPS ${GR_SWIG_SOURCE_DEPS}) list(APPEND GR_SWIG_DOCS_TARGET_DEPS ${GR_SWIG_TARGET_DEPS}) GR_SWIG_MAKE_DOCS(${GR_SWIG_DOC_FILE} ${GR_SWIG_DOC_DIRS}) |