diff options
author | Andrej Rode <mail@andrejro.de> | 2019-03-02 19:59:00 +0100 |
---|---|---|
committer | Marcus Müller <marcus.mueller@ettus.com> | 2019-03-04 22:30:37 +0100 |
commit | ab2fb35677e38a384df3f9503d1f45f64bbc0374 (patch) | |
tree | c59965a71d4951e9bcae9efcf9a6005df2f340a1 /gr-audio/lib | |
parent | 4e777f1c0ee28011255e3b6b703463cef0f207e0 (diff) |
cmake: Update to modern CMake usage
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
Diffstat (limited to 'gr-audio/lib')
-rw-r--r-- | gr-audio/lib/CMakeLists.txt | 173 |
1 files changed, 56 insertions, 117 deletions
diff --git a/gr-audio/lib/CMakeLists.txt b/gr-audio/lib/CMakeLists.txt index 7d01bac39d..91333b24df 100644 --- a/gr-audio/lib/CMakeLists.txt +++ b/gr-audio/lib/CMakeLists.txt @@ -20,46 +20,38 @@ include(GrComponent) ######################################################################## -# Setup the include and linker paths +# Setup library ######################################################################## -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${GR_AUDIO_INCLUDE_DIRS} - ${GNURADIO_RUNTIME_INCLUDE_DIRS} - ${Boost_INCLUDE_DIRS} -) - -link_directories(${Boost_LIBRARY_DIRS}) +add_library(gnuradio-audio audio_registry.cc) +target_link_libraries(gnuradio-audio PUBLIC gnuradio-runtime) +target_include_directories(gnuradio-audio + PUBLIC + $<INSTALL_INTERFACE:include> + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> + ) -list(APPEND gr_audio_libs gnuradio-runtime ${Boost_LIBRARIES}) -list(APPEND gr_audio_sources audio_registry.cc) list(APPEND gr_audio_confs ${CMAKE_CURRENT_SOURCE_DIR}/gr-audio.conf) -if(ENABLE_GR_CTRLPORT) - ADD_DEFINITIONS(-DGR_CTRLPORT) -endif(ENABLE_GR_CTRLPORT) - ######################################################################## ## ALSA Support ######################################################################## find_package(ALSA) -if((ALSA_FOUND) AND NOT (CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD") AND NOT (CMAKE_SYSTEM_NAME STREQUAL GNU)) - - add_definitions(-DALSA_FOUND) - GR_APPEND_SUBCOMPONENT("alsa") +set(audio_deps "") - include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/alsa) - include_directories(${ALSA_INCLUDE_DIRS}) - list(APPEND gr_audio_libs ${ALSA_LIBRARIES}) - list(APPEND gr_audio_sources +if((ALSA_FOUND) AND NOT (CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD") AND NOT (CMAKE_SYSTEM_NAME STREQUAL GNU)) + target_compile_definitions(gnuradio-audio PRIVATE -DALSA_FOUND) + target_link_libraries(gnuradio-audio PUBLIC ALSA::ALSA) + target_sources(gnuradio-audio PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/alsa/alsa_impl.cc ${CMAKE_CURRENT_SOURCE_DIR}/alsa/alsa_source.cc ${CMAKE_CURRENT_SOURCE_DIR}/alsa/alsa_sink.cc - ) - list(APPEND gr_audio_confs ${CMAKE_CURRENT_SOURCE_DIR}/alsa/gr-audio-alsa.conf) + ) -endif((ALSA_FOUND) AND NOT (CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD") AND NOT (CMAKE_SYSTEM_NAME STREQUAL GNU)) + gr_append_subcomponent("alsa") + list(APPEND audio_deps "ALSA") + list(APPEND gr_audio_confs ${CMAKE_CURRENT_SOURCE_DIR}/alsa/gr-audio-alsa.conf) +endif() ######################################################################## ## OSS Support @@ -67,119 +59,97 @@ endif((ALSA_FOUND) AND NOT (CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD") AND NOT (CMAK find_package(OSS) if(OSS_FOUND) - - add_definitions(-DOSS_FOUND) - GR_APPEND_SUBCOMPONENT("oss") - - include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/oss) - include_directories(${OSS_INCLUDE_DIRS}) - list(APPEND gr_audio_sources + target_compile_definitions(gnuradio-audio PRIVATE -DOSS_FOUND) + target_link_libraries(gnuradio-audio PUBLIC OSS::OSS) + target_sources(gnuradio-audio PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/oss/oss_source.cc ${CMAKE_CURRENT_SOURCE_DIR}/oss/oss_sink.cc - ) - list(APPEND gr_audio_confs ${CMAKE_CURRENT_SOURCE_DIR}/oss/gr-audio-oss.conf) + ) + gr_append_subcomponent("oss") + list(APPEND audio_deps "OSS") + list(APPEND gr_audio_confs ${CMAKE_CURRENT_SOURCE_DIR}/oss/gr-audio-oss.conf) endif(OSS_FOUND) ######################################################################## ## Jack Support ######################################################################## -find_package(Jack) +find_package(JACK) if(JACK_FOUND) - - add_definitions(-DJACK_FOUND) - GR_APPEND_SUBCOMPONENT("jack") - - include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/jack) - include_directories(${JACK_INCLUDE_DIRS}) - list(APPEND gr_audio_libs ${JACK_LIBRARIES}) - add_definitions(${JACK_DEFINITIONS}) - list(APPEND gr_audio_sources + target_compile_definitions(gnuradio-audio PRIVATE -DJACK_FOUND) + target_link_libraries(gnuradio-audio PUBLIC JACK::JACK) + target_sources(gnuradio-audio PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/jack/jack_impl.cc ${CMAKE_CURRENT_SOURCE_DIR}/jack/jack_source.cc ${CMAKE_CURRENT_SOURCE_DIR}/jack/jack_sink.cc ) + gr_append_subcomponent("jack") + list(APPEND audio_deps "JACK") list(APPEND gr_audio_confs ${CMAKE_CURRENT_SOURCE_DIR}/jack/gr-audio-jack.conf) - endif(JACK_FOUND) ######################################################################## ## OSX Support ######################################################################## include(CheckIncludeFileCXX) -CHECK_INCLUDE_FILE_CXX(AudioUnit/AudioUnit.h AUDIO_UNIT_H) -CHECK_INCLUDE_FILE_CXX(AudioToolbox/AudioToolbox.h AUDIO_TOOLBOX_H) +check_include_file_cxx(AudioUnit/AudioUnit.h AUDIO_UNIT_H) +check_include_file_cxx(AudioToolbox/AudioToolbox.h AUDIO_TOOLBOX_H) if(AUDIO_UNIT_H AND AUDIO_TOOLBOX_H) - - add_definitions(-DOSX_FOUND) - GR_APPEND_SUBCOMPONENT("osx") - - set(OSX_AUDIO_VALID 1 CACHE INTERNAL "OSX Audio is valid") - - include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/osx) - list(APPEND gr_audio_libs + target_compile_definitions(gnuradio-audio PRIVATE -DOSX_FOUND) + target_link_libraries(gnuradio-audio + PUBLIC "-framework AudioUnit" "-framework CoreAudio" "-framework AudioToolbox" "-framework Carbon" - ) - list(APPEND gr_audio_sources + ) + target_sources(gnuradio-audio PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/osx/osx_impl.cc ${CMAKE_CURRENT_SOURCE_DIR}/osx/osx_source.cc ${CMAKE_CURRENT_SOURCE_DIR}/osx/osx_sink.cc ) + gr_append_subcomponent("osx") + set(OSX_AUDIO_VALID 1 CACHE INTERNAL "OSX Audio is valid") list(APPEND gr_audio_confs ${CMAKE_CURRENT_SOURCE_DIR}/osx/gr-audio-osx.conf) - -else(AUDIO_UNIT_H AND AUDIO_TOOLBOX_H) - +else() set(OSX_AUDIO_VALID 0 CACHE INTERNAL "OSX Audio is not valid") - -endif(AUDIO_UNIT_H AND AUDIO_TOOLBOX_H) +endif() ######################################################################## ## PortAudio Support ######################################################################## -find_package(Portaudio) +find_package(PORTAUDIO) if(PORTAUDIO2_FOUND) - - add_definitions(-DPORTAUDIO_FOUND) - GR_APPEND_SUBCOMPONENT("portaudio") - - include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/portaudio) - include_directories(${PORTAUDIO_INCLUDE_DIRS}) - list(APPEND gr_audio_libs ${PORTAUDIO_LIBRARIES}) - add_definitions(${PORTAUDIO_DEFINITIONS}) - list(APPEND gr_audio_sources + target_compile_definitions(gnuradio-audio PRIVATE -DPORTAUDIO_FOUND) + target_link_libraries(gnuradio-audio PUBLIC Portaudio::Portaudio) + target_sources(gnuradio-audio PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/portaudio/portaudio_impl.cc ${CMAKE_CURRENT_SOURCE_DIR}/portaudio/portaudio_source.cc ${CMAKE_CURRENT_SOURCE_DIR}/portaudio/portaudio_sink.cc ) + list(APPEND audio_deps "PORTAUDIO") + gr_append_subcomponent("portaudio") list(APPEND gr_audio_confs ${CMAKE_CURRENT_SOURCE_DIR}/portaudio/gr-audio-portaudio.conf) - endif(PORTAUDIO2_FOUND) ######################################################################## ## Windows Support ######################################################################## if(WIN32) - - add_definitions(-DWIN32_FOUND) - GR_APPEND_SUBCOMPONENT("windows") - - include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/windows) - list(APPEND gr_audio_libs winmm.lib) - list(APPEND gr_audio_sources + target_compile_definitions(gnuradio-audio PRIVATE -DWIN32_FOUND) + target_link_libraries(gnuradio-audio PUBLIC winmm.lib) + target_sources(gnuradio-audio PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/windows/windows_source.cc ${CMAKE_CURRENT_SOURCE_DIR}/windows/windows_sink.cc ) - + gr_append_subcomponent("windows") #Add Windows DLL resource file if using MSVC - IF(MSVC) + if(MSVC) include(${CMAKE_SOURCE_DIR}/cmake/Modules/GrVersion.cmake) configure_file( @@ -187,42 +157,11 @@ if(WIN32) ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-audio.rc @ONLY) - list(APPEND gr_audio_sources + target_sources(gnuradio-audio PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-audio.rc ) - ENDIF() - + endif() endif(WIN32) -######################################################################## -# Setup library -######################################################################## -add_library(gnuradio-audio SHARED ${gr_audio_sources}) -target_link_libraries(gnuradio-audio ${gr_audio_libs}) -GR_LIBRARY_FOO(gnuradio-audio) - +gr_library_foo(gnuradio-audio ${audio_deps}) install(FILES ${gr_audio_confs} DESTINATION ${GR_PREFSDIR}) - -if(ENABLE_STATIC_LIBS) - if(ENABLE_GR_CTRLPORT) - # Remove GR_CTRLPORT set this target's definitions. - # Makes sure we don't try to use ControlPort stuff in source files - GET_DIRECTORY_PROPERTY(STATIC_DEFS COMPILE_DEFINITIONS) - list(REMOVE_ITEM STATIC_DEFS "GR_CTRLPORT") - SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS "${STATIC_DEFS}") - - # readd it to the target since we removed it from the directory-wide list. - SET_PROPERTY(TARGET gnuradio-audio APPEND PROPERTY COMPILE_DEFINITIONS "GR_CTRLPORT") - endif(ENABLE_GR_CTRLPORT) - - add_library(gnuradio-audio_static STATIC ${gr_audio_sources}) - - if(NOT WIN32) - set_target_properties(gnuradio-audio_static - PROPERTIES OUTPUT_NAME gnuradio-audio) - endif(NOT WIN32) - - install(TARGETS gnuradio-audio_static - ARCHIVE DESTINATION lib${LIB_SUFFIX} # .lib file - ) -endif(ENABLE_STATIC_LIBS) |