Skip to content

Commit

Permalink
cmake: Update to modern CMake usage
Browse files Browse the repository at this point in the history
This includes using target based setting of includes
and link libraries. This will transitively add the includes
and linking flags to dependent targets.

This is still a work in progress since only the dynamic
libraries have been touched and not all of include_directories
directives are gone yet.

cmake: remove GR_INCLUDE_SUBDIRECTORY macro

Previously this macro was used to inject subdirectories in the
current CMake namespace. This is generally undesired and pollutes the
current context.

previously GNU Radio CMake had a non-default option ENABLE_STATIC_LIBS
to build both, shared libraries and static libraries.
This seems to be a construction taken over from autotools and serves
no purpuose in CMake and complicates the library building.

cmake: remove GR_LIBTOOL and la generation support

This looks like it was primarily used to support projects using
autotools, but comments state that the generated .la files aren't
compatible with autotools anyway.

cmake: Bump required CMake version to 3.8

UseSWIG cmake uses syntax which requires at least CMake 3.8 and is non-trivial
to change
  • Loading branch information
noc0lour authored and marcusmueller committed Mar 4, 2019
1 parent 4e777f1 commit ab2fb35
Show file tree
Hide file tree
Showing 97 changed files with 1,568 additions and 2,706 deletions.
59 changes: 31 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
########################################################################
# Make sure this version matches ${GR_CMAKE_MIN_VERSION} (a variable can't be
# used here).
cmake_minimum_required(VERSION 3.5.1)
cmake_minimum_required(VERSION 3.8)
project(gnuradio CXX C)
enable_testing()
option(BUILD_SHARED_LIBS "Build shared libraries" ON)

# Make sure our local CMake Modules path comes first
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/Modules)
Expand Down Expand Up @@ -73,13 +74,13 @@ if(POLICY CMP0026)
cmake_policy(SET CMP0026 NEW)
endif()
if(POLICY CMP0043)
cmake_policy(SET CMP0043 OLD)
cmake_policy(SET CMP0043 NEW)
endif()
if(POLICY CMP0045)
cmake_policy(SET CMP0045 OLD)
cmake_policy(SET CMP0045 NEW)
endif()
if(POLICY CMP0046)
cmake_policy(SET CMP0046 OLD)
cmake_policy(SET CMP0046 NEW)
endif()

########################################################################
Expand Down Expand Up @@ -289,9 +290,6 @@ else(ENABLE_PERFORMANCE_COUNTERS)
message(STATUS "NO PERF COUNTERS")
endif(ENABLE_PERFORMANCE_COUNTERS)

OPTION(ENABLE_STATIC_LIBS "Enable building of static libraries" OFF)
message(STATUS "Building Static Libraries: ${ENABLE_STATIC_LIBS}")

########################################################################
# Variables replaced when configuring the package config files
########################################################################
Expand Down Expand Up @@ -380,14 +378,15 @@ message(STATUS "")
message(STATUS "Configuring VOLK support...")

OPTION(ENABLE_INTERNAL_VOLK "Enable internal VOLK only" ON)
unSET(VOLK_FOUND)
UNSET(Volk_FOUND)
if(NOT ENABLE_INTERNAL_VOLK)
find_package(Volk)
if(NOT VOLK_FOUND)
set(GR_VOLK_LIB "Volk::volk")
if(NOT Volk_FOUND)
message(STATUS " External VOLK not found; checking internal.")
endif()
endif()
if(NOT VOLK_FOUND)
if(NOT Volk_FOUND)
find_file(INTREE_VOLK_FOUND
volk/volk_common.h
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/volk/include
Expand Down Expand Up @@ -419,7 +418,7 @@ if(NOT VOLK_FOUND)
${CMAKE_CURRENT_BINARY_DIR}/volk/include
)

SET(VOLK_LIBRARIES volk)
set(GR_VOLK_LIB "volk")

SET(VOLK_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_PREFIX}/lib)
SET(VOLK_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)
Expand All @@ -429,12 +428,12 @@ else()

get_filename_component(VOLK_INSTALL_LIBRARY_DIR "${VOLK_LIBRARIES}" DIRECTORY)
SET(VOLK_INSTALL_INCLUDE_DIR ${VOLK_INCLUDE_DIRS})
endif(NOT VOLK_FOUND)
endif(NOT Volk_FOUND)

message(STATUS " Override with -DENABLE_INTERNAL_VOLK=ON/OFF")

# Handle logging
find_package(Log4cpp REQUIRED)
find_package(LOG4CPP REQUIRED)

########################################################################
# Distribute the README file
Expand All @@ -447,13 +446,21 @@ install(
########################################################################
# The following dependency libraries are needed by all gr modules:
########################################################################
list(APPEND GR_TEST_TARGET_DEPS volk gnuradio-runtime)
list(APPEND GR_TEST_PYTHON_DIRS
${CMAKE_BINARY_DIR}/gnuradio-runtime/python
${CMAKE_SOURCE_DIR}/gnuradio-runtime/python
${CMAKE_BINARY_DIR}/gnuradio-runtime/swig
)

# Install our Cmake modules into $prefix/lib/cmake/gnuradio
# See "Package Configuration Files" on page:
# http://www.cmake.org/Wiki/CMake/Tutorials/Packaging

if(NOT CMAKE_MODULES_DIR)
SET(CMAKE_MODULES_DIR lib${LIB_SUFFIX}/cmake)
endif(NOT CMAKE_MODULES_DIR)


# Note that above we put the binary gnuradio-runtime/python directory
# before the source directory. This is due to a quirk with ControlPort
# and how slice generates files and names. We want the QA and
Expand Down Expand Up @@ -504,14 +511,19 @@ if(ENABLE_GR_CTRLPORT)
endif(CTRLPORT_BACKENDS GREATER 0)
endif(ENABLE_GR_CTRLPORT)

# Install our Cmake modules into $prefix/lib/cmake/gnuradio
# See "Package Configuration Files" on page:
# http://www.cmake.org/Wiki/CMake/Tutorials/Packaging

configure_file(
# Install all other cmake files into same directory
file(GLOB cmake_others "cmake/Modules/*.cmake")
list(REMOVE_ITEM cmake_others
"${CMAKE_SOURCE_DIR}/cmake/Modules/FindGnuradio.cmake"
)

include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_SOURCE_DIR}/cmake/Modules/GnuradioConfig.cmake.in
${CMAKE_BINARY_DIR}/cmake/Modules/GnuradioConfig.cmake
@ONLY)
INSTALL_DESTINATION ${CMAKE_MODULES_DIR}/gnuradio
)

configure_file(
${CMAKE_SOURCE_DIR}/cmake/Modules/GnuradioConfigVersion.cmake.in
Expand All @@ -523,15 +535,6 @@ SET(cmake_configs
${CMAKE_BINARY_DIR}/cmake/Modules/GnuradioConfigVersion.cmake
)

if(NOT CMAKE_MODULES_DIR)
SET(CMAKE_MODULES_DIR lib${LIB_SUFFIX}/cmake)
endif(NOT CMAKE_MODULES_DIR)

# Install all other cmake files into same directory
file(GLOB cmake_others "cmake/Modules/*.cmake")
list(REMOVE_ITEM cmake_others
"${CMAKE_SOURCE_DIR}/cmake/Modules/FindGnuradio.cmake"
)

install(
FILES ${cmake_configs} ${cmake_others}
Expand Down
61 changes: 0 additions & 61 deletions cmake/Modules/CMakeMacroLibtoolFile.cmake

This file was deleted.

7 changes: 7 additions & 0 deletions cmake/Modules/FindALSA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ set(ALSA_PROCESS_INCLUDES ALSA_INCLUDE_DIR)
set(ALSA_PROCESS_LIBS ALSA_LIBRARY)
libfind_process(ALSA)

if (ALSA_FOUND AND NOT TARGET ALSA::ALSA)
add_library(ALSA::ALSA INTERFACE IMPORTED)
set_target_properties(ALSA::ALSA PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ALSA_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${ALSA_LIBRARY}"
)
endif()
8 changes: 8 additions & 0 deletions cmake/Modules/FindCodec2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ endif(LIBCODEC2_INCLUDE_DIR AND LIBCODEC2_LIBRARIES)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBCODEC2 DEFAULT_MSG LIBCODEC2_LIBRARIES LIBCODEC2_INCLUDE_DIRS)
mark_as_advanced(LIBCODEC2_INCLUDE_DIR LIBCODEC2_LIBRARIES)

if (LIBCODEC2_FOUND AND NOT TARGET CODEC2::CODEC2)
add_library(CODEC2::CODEC2 INTERFACE IMPORTED)
set_target_properties(CODEC2::CODEC2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LIBCODEC2_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${LIBCODEC2_LIBRARIES}"
)
endif()
35 changes: 26 additions & 9 deletions cmake/Modules/FindFFTW3f.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,55 @@
# Find single-precision (float) version of FFTW3

INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(PC_FFTW3F "fftw3f >= 3.0")
PKG_CHECK_MODULES(PC_FFTW3f "fftw3f >= 3.0")

FIND_PATH(
FFTW3F_INCLUDE_DIRS
FFTW3f_INCLUDE_DIRS
NAMES fftw3.h
HINTS $ENV{FFTW3_DIR}/include
${PC_FFTW3F_INCLUDE_DIR}
${PC_FFTW3f_INCLUDE_DIR}
PATHS /usr/local/include
/usr/include
)

FIND_LIBRARY(
FFTW3F_LIBRARIES
FFTW3f_LIBRARIES
NAMES fftw3f libfftw3f
HINTS $ENV{FFTW3_DIR}/lib
${PC_FFTW3F_LIBDIR}
${PC_FFTW3f_LIBDIR}
PATHS /usr/local/lib
/usr/lib
/usr/lib64
)

FIND_LIBRARY(
FFTW3F_THREADS_LIBRARIES
FFTW3f_THREADS_LIBRARIES
NAMES fftw3f_threads libfftw3f_threads
HINTS $ENV{FFTW3_DIR}/lib
${PC_FFTW3F_LIBDIR}
${PC_FFTW3f_LIBDIR}
PATHS /usr/local/lib
/usr/lib
/usr/lib64
)



INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FFTW3F DEFAULT_MSG FFTW3F_LIBRARIES FFTW3F_INCLUDE_DIRS)
MARK_AS_ADVANCED(FFTW3F_LIBRARIES FFTW3F_INCLUDE_DIRS FFTW3F_THREADS_LIBRARIES)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FFTW3f DEFAULT_MSG FFTW3f_LIBRARIES FFTW3f_INCLUDE_DIRS)
MARK_AS_ADVANCED(FFTW3f_LIBRARIES FFTW3f_INCLUDE_DIRS FFTW3f_THREADS_LIBRARIES)

if (FFTW3f_FOUND AND NOT TARGET fftw3f::fftw3f)
add_library(fftw3f::fftw3f INTERFACE IMPORTED)
set_target_properties(fftw3f::fftw3f PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${FFTW3f_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${FFTW3f_LIBRARIES}"
)
if (FFTW3f_THREADS_LIBRARIES)
set_property(TARGET fftw3f::fftw3f APPEND PROPERTY INTERFACE_LINK_LIBRARIES
"${FFTW3f_THREADS_LIBRARIES}"
)
set_target_properties(fftw3f::fftw3f PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "FFTW3F_THREADS"
)
endif()
endif()
20 changes: 18 additions & 2 deletions cmake/Modules/FindGSL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ PKG_CHECK_MODULES(GSL "gsl >= 1.10")
IF(GSL_FOUND)
set(GSL_LIBRARY_DIRS ${GSL_LIBDIR})
set(GSL_INCLUDE_DIRS ${GSL_INCLUDEDIR})
if( NOT TARGET gsl::gsl)
add_library(gsl::gsl INTERFACE IMPORTED)
set_target_properties(gsl::gsl PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${GSL_LIBRARIES}"
INTERFACE_COMPILE_DEFINITIONS "${GSL_DEFINITIONS}"
)
endif( NOT TARGET gsl::gsl)
ELSE(GSL_FOUND)
set( GSL_FOUND OFF )
set( GSL_CBLAS_FOUND OFF )
Expand Down Expand Up @@ -130,19 +138,27 @@ else( WIN32 AND NOT CYGWIN AND NOT MSYS )
endif( GSL_CONFIG_EXECUTABLE )
endif( UNIX OR MSYS )
endif( WIN32 AND NOT CYGWIN AND NOT MSYS )
#needed for gsl windows port but safe to always define
LIST(APPEND GSL_DEFINITIONS "-DGSL_DLL")

if( GSL_FOUND )
if( NOT GSL_FIND_QUIETLY )
message( STATUS "FindGSL: Found both GSL headers and library" )
endif( NOT GSL_FIND_QUIETLY )
if( NOT TARGET gsl::gsl)
add_library(gsl::gsl INTERFACE IMPORTED)
set_target_properties(gsl::gsl PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${GSL_LIBRARIES}"
INTERFACE_COMPILE_DEFINITIONS "${GSL_DEFINITIONS}"
)
endif( NOT TARGET gsl::gsl)
else( GSL_FOUND )
if( GSL_FIND_REQUIRED )
message( FATAL_ERROR "FindGSL: Could not find GSL headers or library" )
endif( GSL_FIND_REQUIRED )
endif( GSL_FOUND )

#needed for gsl windows port but safe to always define
LIST(APPEND GSL_DEFINITIONS "-DGSL_DLL")

ENDIF(GSL_FOUND)

Expand Down
8 changes: 8 additions & 0 deletions cmake/Modules/FindGSM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ endif(LIBGSM_INCLUDE_DIR AND LIBGSM_LIBRARIES)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBGSM DEFAULT_MSG LIBGSM_LIBRARIES LIBGSM_INCLUDE_DIRS)
mark_as_advanced(LIBGSM_INCLUDE_DIR LIBGSM_LIBRARIES)

if (LIBGSM_FOUND AND NOT TARGET GSM::GSM)
add_library(GSM::GSM INTERFACE IMPORTED)
set_target_properties(GSM::GSM PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LIBGSM_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${LIBGSM_LIBRARIES}"
)
endif()
11 changes: 9 additions & 2 deletions cmake/Modules/FindJack.cmake → cmake/Modules/FindJACK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# JACK_FOUND - system has jack
# JACK_INCLUDE_DIRS - the jack include directory
# JACK_LIBRARIES - Link these to use jack
# JACK_DEFINITIONS - Compiler switches required for using jack
#
# Copyright (c) 2008 Andreas Schneider <[email protected]>
# Modified for other libraries by Lasse Kärkkäinen <tronic>
Expand Down Expand Up @@ -78,5 +77,13 @@ else (JACK_LIBRARIES AND JACK_INCLUDE_DIRS)
# show the JACK_INCLUDE_DIRS and JACK_LIBRARIES variables only in the advanced view
mark_as_advanced(JACK_INCLUDE_DIRS JACK_LIBRARIES)

endif (JACK_LIBRARIES AND JACK_INCLUDE_DIRS)
if (JACK_FOUND AND NOT TARGET JACK::JACK)
add_library(JACK::JACK INTERFACE IMPORTED)
set_target_properties(JACK::JACK PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${JACK_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${JACK_LIBRARIES}"
)
endif()


endif (JACK_LIBRARIES AND JACK_INCLUDE_DIRS)
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ else ()
endif ()
endif ()


if (LOG4CPP_FOUND AND NOT TARGET log4cpp::log4cpp)
add_library(Log4Cpp::log4cpp INTERFACE IMPORTED)
set_target_properties(Log4Cpp::log4cpp PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LOG4CPP_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${LOG4CPP_LIBRARIES}"
)
endif()

mark_as_advanced(
LOG4CPP_LIBRARIES
LOG4CPP_INCLUDE_DIRS
Expand Down
Loading

0 comments on commit ab2fb35

Please sign in to comment.