Conditional compilation of local libosmocore depending if there is or is not libosmocore installation present on the system
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 811cd93..8ad3445 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -135,10 +135,11 @@
 find_package(Gnuradio)
 find_package(Volk)
 find_package(CppUnit)
-find_package(Doxygen)
-#find_package(Libosmocore)
-#find_package(Libosmocoding)
-#find_package(Libosmocodec)
+#find_package(Doxygen)
+find_package(Libosmocore)
+find_package(Libosmocodec)
+find_package(Libosmocoding)
+
 
 if(NOT GNURADIO_RUNTIME_FOUND)
     message(FATAL_ERROR "GnuRadio Runtime required to compile gr-gsm")
@@ -146,18 +147,14 @@
 if(NOT VOLK_FOUND)
     message(FATAL_ERROR "Volk library required to compile gr-gsm")
 endif()
-#if(NOT CPPUNIT_FOUND)
-#    message(FATAL_ERROR "CppUnit required to compile gr-gsm")
-#endif()
-#if(NOT LIBOSMOCORE_FOUND)
-#    message(FATAL_ERROR "Libosmocore required to compile gr-gsm")
-#endif()
-#if(NOT LIBOSMOCODEC_FOUND)
-#    message(FATAL_ERROR "Libosmocodec required to compile gr-gsm")
-#endif()
-#if(NOT LIBOSMOCODING_FOUND)
-#    message(FATAL_ERROR "Libosmocoding required to compile gr-gsm")
-#endif()
+if(NOT CPPUNIT_FOUND)
+    message(FATAL_ERROR "CppUnit required to compile gr-gsm")
+endif()
+if(NOT LIBOSMOCORE_FOUND OR NOT LIBOSMOCODEC_FOUND)
+    message(STATUS "Compiling local version of libosmocore and libosmocodec")
+elseif(NOT LIBOSMOCODING_FOUND)
+    message(STATUS "Compiling local version of libosmocoding")
+endif()
 
 ########################################################################
 # Setup doxygen option
@@ -165,13 +162,13 @@
 #if(DOXYGEN_FOUND)
 #	option(ENABLE_DOXYGEN "Build docs using Doxygen" ON)
 #else(DOXYGEN_FOUND)
-	option(ENABLE_DOXYGEN "Build docs using Doxygen" OFF)
+	option(ENABLE_DOXYGEN "Build docs using Doxygen" OFF) #TODO: write doxygen docs
 #endif(DOXYGEN_FOUND)
 
 ########################################################################
 # Setup the include and linker paths
 ########################################################################
-include_directories(
+list (APPEND grgsm_include_directories
     ${CMAKE_SOURCE_DIR}/lib
     ${CMAKE_SOURCE_DIR}/include
     ${CMAKE_BINARY_DIR}/lib
@@ -179,16 +176,35 @@
     ${Boost_INCLUDE_DIRS}
     ${CPPUNIT_INCLUDE_DIRS}
     ${GNURADIO_ALL_INCLUDE_DIRS}
-#    ${LIBOSMOCORE_INCLUDE_DIR}
     ${CMAKE_SOURCE_DIR}/lib/decoding
 )
 
-link_directories(
+if(LIBOSMOCORE_FOUND)
+    list (APPEND grgsm_include_directories
+       ${LIBOSMOCORE_INCLUDE_DIR}
+    )
+endif()
+
+include_directories(
+    ${grgsm_include_directories}
+)
+
+list (APPEND
     ${Boost_LIBRARY_DIRS}
     ${CPPUNIT_LIBRARY_DIRS}
     ${GNURADIO_ALL_LIBRARY_DIRS}
 )
 
+if(LIBOSMOCORE_FOUND)
+    list (APPEND grgsm_link_directories
+       ${LIBOSMOCORE_LIBRARY_DIRS}
+    )
+endif()
+
+link_directories(
+    ${grgsm_link_directories}
+)
+
 # Set component parameters
 set(GR_GSM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE INTERNAL "" FORCE)
 set(GR_GSM_SWIG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/swig CACHE INTERNAL "" FORCE)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 253353b..db440e4 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -81,17 +81,22 @@
 list (APPEND grgsm_link_libraries ${Boost_LIBRARIES})
 list (APPEND grgsm_link_libraries ${GNURADIO_ALL_LIBRARIES})
 list (APPEND grgsm_link_libraries ${VOLK_LIBRARIES})
-list (APPEND grgsm_link_libraries ${Boost_LIBRARIES})
 if(WIN32)
-	list (APPEND grgsm_link_libraries wsock32)
-	list (APPEND grgsm_link_libraries ws2_32)
+    list (APPEND grgsm_link_libraries wsock32)
+    list (APPEND grgsm_link_libraries ws2_32)
+endif()
+
+if(LIBOSMOCORE_FOUND AND LIBOSMOCODEC_FOUND)
+    list (APPEND grgsm_link_libraries ${LIBOSMOCORE_LIBRARIES} ${LIBOSMOCODEC_LIBRARIES})
+    if(LIBOSMOCODING_FOUND)
+        list (APPEND grgsm_link_libraries ${LIBOSMOCODING_LIBRARIES})
+    endif()
 endif()
 
 
+
 add_library(grgsm SHARED ${grgsm_sources})
-target_link_libraries(grgsm ${grgsm_link_libraries} #${LIBOSMOCORE_LIBRARIES}
-# ${LIBOSMOCODEC_LIBRARIES}
-# ${LIBOSMOCODING_LIBRARIES} 
+target_link_libraries(grgsm ${grgsm_link_libraries}
 # libraries required by plotting.h - have troubles to be installed by pybombs
 #    boost_iostreams
 #    boost_system
diff --git a/lib/decoding/CMakeLists.txt b/lib/decoding/CMakeLists.txt
index cbf2a8e..bb5ddde 100644
--- a/lib/decoding/CMakeLists.txt
+++ b/lib/decoding/CMakeLists.txt
@@ -17,11 +17,16 @@
 # the Free Software Foundation, Inc., 51 Franklin Street,
 # Boston, MA 02110-1301, USA.
 
-add_subdirectory(osmocom/coding)
-add_subdirectory(osmocom/core)
-add_subdirectory(osmocom/codec)
-add_subdirectory(osmocom/gsm)
-add_subdirectory(osmocom/crypt)
+if(NOT LIBOSMOCORE_FOUND OR NOT LIBOSMOCODEC_FOUND)
+    message(STATUS "Libosmocore installation not found - compiling local version")
+    add_subdirectory(osmocom/core)
+    add_subdirectory(osmocom/codec)
+    add_subdirectory(osmocom/gsm)
+elseif(NOT LIBOSMOCODING_FOUND)
+    message(STATUS "Libosmocore found but libosmocoding is missing - compiling local version")
+    add_subdirectory(osmocom/coding)
+endif()
+
 add_subdirectory(openbts)
 
 add_sources(