diff --git a/CMakeLists.txt b/CMakeLists.txt
index 45b0b7be4bdfb82e73ab42030d4e9266253e74d7..29aebd21abb6f4f8d064d16f3a11e0da294c54db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,7 @@
########################################################################
cmake_minimum_required(VERSION 3.8)
project(gr-bladeRF CXX C)
+include(GNUInstallDirs)
enable_testing()
# Install to PyBOMBS target prefix if defined
@@ -48,6 +49,7 @@ if((CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
AND NOT WIN32)
#http://gcc.gnu.org/wiki/Visibility
add_definitions(-fvisibility=hidden)
+ add_definitions(-fvisibility-inlines-hidden)
endif()
IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
@@ -70,6 +72,57 @@ ELSE()
message(WARNING "C standard could not be set because compiler is not GNU, Clang or MSVC.")
ENDIF()
+# Misc options
+if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
+ CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ add_definitions(-Wall)
+ add_definitions(-Wextra)
+ add_definitions(-Wno-unused-parameter)
+ add_definitions(-Wsign-compare)
+ #add_definitions(-Wconversion)
+ #add_definitions(-pedantic)
+ #add_definitions(-ansi)
+endif()
+
+# SIMD
+if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|x86")
+ set(USE_SIMD "SSE2" CACHE STRING "Use SIMD instructions")
+else()
+ set(USE_SIMD "no" CACHE STRING "Use SIMD instructions")
+endif()
+set(USE_SIMD_VALUES "no" "SSE2" "AVX")
+set_property(CACHE USE_SIMD PROPERTY STRINGS ${USE_SIMD_VALUES})
+list(FIND USE_SIMD_VALUES ${USE_SIMD} USE_SIMD_INDEX)
+if(${USE_SIMD_INDEX} EQUAL -1)
+ message(FATAL_ERROR "Option ${USE_SIMD} not supported, valid entries are ${USE_SIMD_VALUES}")
+endif()
+
+if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
+ CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ if(USE_SIMD MATCHES SSE2)
+ add_definitions(-msse2)
+ add_definitions(-DUSE_SSE2)
+ endif()
+ if(USE_SIMD MATCHES AVX)
+ add_definitions(-march=native)
+ add_definitions(-DUSE_AVX)
+ endif()
+elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
+ if(USE_SIMD MATCHES SSE2)
+ add_definitions(/arch:SSE2)
+ add_definitions(-DUSE_SSE2)
+ endif()
+ if(USE_SIMD MATCHES AVX)
+ add_definitions(/arch:AVX)
+ add_definitions(-DUSE_AVX)
+ endif()
+ # boost feels like using lib pragmas to link to libs,
+ # but the boost libs might not even be in the (default) lib search path
+ add_definitions(-DBOOST_ALL_NO_LIB)
+ # macro turns std::min into errors...
+ add_definitions(-DNOMINMAX)
+endif()
+
########################################################################
# Install directories
########################################################################
@@ -81,6 +134,9 @@ include(GrVersion)
include(GrPlatform) #define LIB_SUFFIX
+include(GrComponent)
+
+
if(NOT CMAKE_MODULES_DIR)
set(CMAKE_MODULES_DIR lib${LIB_SUFFIX}/cmake)
endif(NOT CMAKE_MODULES_DIR)
@@ -112,6 +168,10 @@ if(APPLE)
endif(NOT CMAKE_BUILD_WITH_INSTALL_RPATH)
endif(APPLE)
+########################################################################
+# Hardware
+########################################################################
+find_package(LibbladeRF)
########################################################################
# Find gnuradio build dependencies
########################################################################
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 03d7f49e18b0ee6d7c7493088454795e3a6df240..a97293ae7624f9836b763ab894e09e3df7c8db73 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -10,16 +10,16 @@
# Setup library
########################################################################
include(GrPlatform) #define LIB_SUFFIX
-list(APPEND bladeRF_sources
+list(APPEND gr_bladerf_srcs
source_impl.cc
sink_impl.cc
)
-set(bladeRF_sources "${bladeRF_sources}" PARENT_SCOPE)
-if(NOT bladeRF_sources)
- MESSAGE(STATUS "No C++ sources... skipping lib/")
- return()
-endif(NOT bladeRF_sources)
+#-pthread Adds support for multithreading with the pthreads library.
+#This option sets flags for both the preprocessor and linker. (man gcc)
+if(CMAKE_COMPILER_IS_GNUCXX)
+ list(APPEND Boost_LIBRARIES -pthread)
+endif()
MACRO (APPEND_LIB_LIST)
SET (gr_bladerf_libs "${gr_bladerf_libs};${ARGN}" CACHE INTERNAL "lib list")
@@ -27,11 +27,8 @@ ENDMACRO(APPEND_LIB_LIST)
set(gr_bladerf_libs "" CACHE INTERNAL "lib that accumulates link targets")
-APPEND_LIB_LIST(gnuradio::gnuradio-runtime)
-
-add_library(gnuradio-bladeRF SHARED ${bladeRF_sources})
-target_link_libraries(gnuradio-bladeRF ${gr_bladerf_libs})
-
+add_library(gnuradio-bladeRF SHARED)
+APPEND_LIB_LIST(${Boost_LIBRARIES} gnuradio::gnuradio-runtime)
target_include_directories(gnuradio-bladeRF
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC ${Boost_INCLUDE_DIRS}
@@ -46,7 +43,80 @@ if(APPLE)
)
endif(APPLE)
-add_subdirectory(bladerf)
+########################################################################
+# Setup defines for high resolution timing
+########################################################################
+message(STATUS "")
+message(STATUS "Configuring high resolution timing...")
+include(CheckCXXSourceCompiles)
+
+set(CMAKE_REQUIRED_LIBRARIES -lrt)
+CHECK_CXX_SOURCE_COMPILES("
+ #include <ctime>
+ int main(){
+ timespec ts;
+ return clock_gettime(CLOCK_MONOTONIC, &ts);
+ }
+ " HAVE_CLOCK_GETTIME
+)
+unset(CMAKE_REQUIRED_LIBRARIES)
+
+include(CheckCXXSourceCompiles)
+CHECK_CXX_SOURCE_COMPILES("
+ #include <mach/mach_time.h>
+ int main(){
+ mach_timebase_info_data_t info;
+ mach_timebase_info(&info);
+ mach_absolute_time();
+ return 0;
+ }
+ " HAVE_MACH_ABSOLUTE_TIME
+)
+
+CHECK_CXX_SOURCE_COMPILES("
+ #include <Windows.h>
+ int main(){
+ LARGE_INTEGER value;
+ QueryPerformanceCounter(&value);
+ QueryPerformanceFrequency(&value);
+ return 0;
+ }
+ " HAVE_QUERY_PERFORMANCE_COUNTER
+)
+
+if(HAVE_CLOCK_GETTIME)
+ message(STATUS " High resolution timing supported through clock_gettime.")
+ set(TIME_SPEC_DEFS HAVE_CLOCK_GETTIME)
+ APPEND_LIB_LIST( "-lrt")
+elseif(HAVE_MACH_ABSOLUTE_TIME)
+ message(STATUS " High resolution timing supported through mach_absolute_time.")
+ set(TIME_SPEC_DEFS HAVE_MACH_ABSOLUTE_TIME)
+elseif(HAVE_QUERY_PERFORMANCE_COUNTER)
+ message(STATUS " High resolution timing supported through QueryPerformanceCounter.")
+ set(TIME_SPEC_DEFS HAVE_QUERY_PERFORMANCE_COUNTER)
+else()
+ message(STATUS " High resolution timing supported through microsec_clock.")
+ set(TIME_SPEC_DEFS HAVE_MICROSEC_CLOCK)
+endif()
+
+set_source_files_properties(
+ time_spec.cc
+ PROPERTIES COMPILE_DEFINITIONS "${TIME_SPEC_DEFS}"
+)
+
+########################################################################
+# Setup bladeRF component
+########################################################################
+GR_REGISTER_COMPONENT("nuand bladeRF" ENABLE_BLADERF LIBBLADERF_FOUND)
+if(ENABLE_BLADERF)
+ add_subdirectory(bladerf)
+endif(ENABLE_BLADERF)
+
+########################################################################
+# Finalize target
+########################################################################
+set_target_properties(gnuradio-bladeRF PROPERTIES SOURCES "${gr_bladerf_srcs}")
+target_link_libraries(gnuradio-bladeRF ${gr_bladerf_libs})
########################################################################
diff --git a/lib/bladerf/CMakeLists.txt b/lib/bladerf/CMakeLists.txt
index decf2688786faa0a95f8fca54aaed98528851c68..87fe38bbfc366001bb85416ab5896f0818028ba6 100644
--- a/lib/bladerf/CMakeLists.txt
+++ b/lib/bladerf/CMakeLists.txt
@@ -31,9 +31,9 @@ APPEND_LIB_LIST(
${Volk_LIBRARIES}
)
-list(APPEND bladeRF_sources
+list(APPEND gr_bladerf_srcs
${CMAKE_CURRENT_SOURCE_DIR}/bladerf_source_c.cc
${CMAKE_CURRENT_SOURCE_DIR}/bladerf_sink_c.cc
${CMAKE_CURRENT_SOURCE_DIR}/bladerf_common.cc
)
-set(bladeRF_sources ${bladeRF_sources} PARENT_SCOPE)
+set(gr_bladerf_srcs ${gr_bladerf_srcs} PARENT_SCOPE)
diff --git a/python/bindings/CMakeLists.txt b/python/bindings/CMakeLists.txt
index 953006de722da32237c1e9cd3ddc203b61c83d59..39378bf631529782e3f1e40a260db10a47b67cf3 100644
--- a/python/bindings/CMakeLists.txt
+++ b/python/bindings/CMakeLists.txt
@@ -8,10 +8,10 @@
########################################################################
# Check if there is C++ code at all
########################################################################
-if(NOT bladeRF_sources)
+if(NOT gr_bladerf_srcs)
MESSAGE(STATUS "No C++ sources... skipping python bindings")
return()
-endif(NOT bladeRF_sources)
+endif(NOT gr_bladerf_srcs)
########################################################################
# Check for pygccxml