Update Findhamlib.cmake with one from George L. Emigh - AB4BD, fix CMakeLists.txt project order

This commit is contained in:
Charles J. Cliffe 2016-01-04 22:50:21 -05:00
parent cb3c899a52
commit 0aa7b572b5
3 changed files with 60 additions and 162 deletions

View File

@ -1,5 +1,9 @@
cmake_minimum_required (VERSION 2.8)
project (CubicSDR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
SET(CUBICSDR_VERSION_MAJOR "0")
SET(CUBICSDR_VERSION_MINOR "1")
SET(CUBICSDR_VERSION_PATCH "20")
@ -34,23 +38,18 @@ ADD_DEFINITIONS(
ENDIF()
ENDIF()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
option(USE_HAMLIB ON "Support hamlib for radio control functions.")
set(USE_HAMLIB ON CACHE BOOL "Support hamlib for radio control functions.")
if (USE_HAMLIB)
find_package(hamlib REQUIRED)
if (NOT hamlib_FOUND)
if (NOT HAMLIB_FOUND)
message(FATAL_ERROR "hamlib development files not found...")
endif ()
include_directories(${hamlib_INCLUDE_DIRS})
if (${hamlib_STATIC_FOUND})
link_libraries(${hamlib_STATIC_LIBRARIES})
else()
link_libraries(${hamlib_LIBRARIES})
endif()
include_directories(${HAMLIB_INCLUDE_DIR})
link_libraries(${HAMLIB_LIBRARY})
ADD_DEFINITIONS(-DUSE_HAMLIB)
endif ()
@ -89,8 +88,6 @@ macro(configure_files_recurse srcDir destDir)
endforeach(templateFile)
endmacro(configure_files_recurse)
project (CubicSDR)
if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
MESSAGE( "64 bit compiler detected" )
SET( EX_PLATFORM 64 )

View File

@ -1,59 +1,59 @@
# - Try to find hamlib
# Once done, this will define:
# - Try to find Hamlib
# Author: George L. Emigh - AB4BD
#
# Change Log: Charles J. Cliffe <cj@cubicproductions.com>
# Updates:
# Jan 2015 - Add /opt/ paths for OSX MacPorts
# TODO:
# Windows support
# Static support
#
# hamlib_FOUND - system has Hamlib-2
# hamlib_INCLUDE_DIRS - the Hamlib-2 include directories
# hamlib_LIBRARIES - link these to use Hamlib-2
# hamlib_STATIC_FOUND - system has Hamlib-2 static archive
# hamlib_STATIC_LIBRARIES - link these to use Hamlib-2 static archive
# HAMLIB_FOUND - system has Hamlib
# HAMLIB_LIBRARY - location of the library for hamlib
# HAMLIB_INCLUDE_DIR - location of the include files for hamlib
include (LibFindMacros)
set(HAMLIB_FOUND FALSE)
# pkg-config?
find_path (__hamlib_pc_path NAMES hamlib.pc
PATH_SUFFIXES lib/pkgconfig
find_path(HAMLIB_INCLUDE_DIR
NAMES rig.h
PATHS
/usr/include/hamlib
/usr/include
/usr/local/include/hamlib
/usr/local/include
/opt/local/include/hamlib
/opt/local/include
/opt/local/include/hamlib
)
if (__hamlib_pc_path)
set (ENV{PKG_CONFIG_PATH} "${__hamlib_pc_path}" "$ENV{PKG_CONFIG_PATH}")
unset (__hamlib_pc_path CACHE)
endif ()
# Use pkg-config to get hints about paths, libs and, flags
unset (__pkg_config_checked_hamlib CACHE)
libfind_pkg_check_modules (PC_HAMLIB hamlib)
find_library(HAMLIB_LIBRARY
NAMES hamlib
PATHS
/usr/lib64/hamlib
/usr/lib/hamlib
/usr/lib64
/usr/lib
/usr/local/lib64/hamlib
/usr/local/lib/hamlib
/usr/local/lib64
/usr/local/lib
/opt/local/lib
/opt/local/lib/hamlib
)
if (NOT PC_HAMLIB_STATIC_LIBRARIES)
if (WIN32)
set (PC_HAMLIB_STATIC_LIBRARIES hamlib ws2_32)
else ()
set (PC_HAMLIB_STATIC_LIBRARIES hamlib m dl usb)
endif ()
endif ()
if(HAMLIB_INCLUDE_DIR AND HAMLIB_LIBRARY)
set(HAMLIB_FOUND TRUE)
message(STATUS "Hamlib version: ${VERSION}")
message(STATUS "Found hamlib library directory at: ${HAMLIB_LIBRARY}")
message(STATUS "Found hamlib include directory at: ${HAMLIB_INCLUDE_DIR}")
endif(HAMLIB_INCLUDE_DIR AND HAMLIB_LIBRARY)
# The libraries
libfind_library (hamlib hamlib)
libfind_library (hamlib_STATIC libhamlib.a)
find_path (hamlib_INCLUDE_DIR hamlib/rig.h)
# Set the include dir variables and the libraries and let libfind_process do the rest
set (hamlib_PROCESS_INCLUDES hamlib_INCLUDE_DIR)
set (hamlib_PROCESS_LIBS hamlib_LIBRARY)
libfind_process (hamlib)
set (hamlib_STATIC_PROCESS_INCLUDES hamlib_STATIC_INCLUDE_DIR)
set (hamlib_STATIC_PROCESS_LIBS hamlib_STATIC_LIBRARY PC_HAMLIB_STATIC_LIBRARIES)
libfind_process (hamlib_STATIC)
# make sure we return a full path for the library we return
if (hamlib_FOUND)
list (REMOVE_ITEM hamlib_LIBRARIES hamlib)
if (hamlib_STATIC_LIBRARIES)
list (REMOVE_ITEM hamlib_STATIC_LIBRARIES hamlib)
endif ()
endif ()
# Handle the QUIETLY and REQUIRED arguments and set HAMLIB_FOUND to
# TRUE if all listed variables are TRUE
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (hamlib DEFAULT_MSG hamlib_INCLUDE_DIRS hamlib_LIBRARY hamlib_LIBRARIES)
IF(NOT HAMLIB_FOUND)
IF(NOT HAMLIB_FIND_QUIETLY)
MESSAGE(STATUS "HAMLIB was not found.")
ELSE(NOT HAMLIB_FIND_QUIETLY)
IF(HAMLIB_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "HAMLIB was not found.")
ENDIF(HAMLIB_FIND_REQUIRED)
ENDIF(NOT HAMLIB_FIND_QUIETLY)
ENDIF(NOT HAMLIB_FOUND)

View File

@ -1,99 +0,0 @@
# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
# used for the current package. For this to work, the first parameter must be the
# prefix of the current package, then the prefix of the new package etc, which are
# passed to find_package.
macro (libfind_package PREFIX)
set (LIBFIND_PACKAGE_ARGS ${ARGN})
if (${PREFIX}_FIND_QUIETLY)
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
endif (${PREFIX}_FIND_QUIETLY)
if (${PREFIX}_FIND_REQUIRED)
set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
endif (${PREFIX}_FIND_REQUIRED)
find_package(${LIBFIND_PACKAGE_ARGS})
endmacro (libfind_package)
# CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
# where they added pkg_check_modules. Consequently I need to support both in my scripts
# to avoid those deprecated warnings. Here's a helper that does just that.
# Works identically to pkg_check_modules, except that no checks are needed prior to use.
macro (libfind_pkg_check_modules PREFIX PKGNAME)
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
include(UsePkgConfig)
pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(${PREFIX} ${PKGNAME})
endif (PKG_CONFIG_FOUND)
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
endmacro (libfind_pkg_check_modules)
# Do the final processing once the paths have been detected.
# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
# all the variables, each of which contain one include directory.
# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
# Also handles errors in case library detection was required, etc.
macro (libfind_process PREFIX)
# Skip processing if already processed during this run
if (NOT ${PREFIX}_FOUND)
# Start with the assumption that the library was found
set (${PREFIX}_FOUND TRUE)
# Process all includes and set _FOUND to false if any are missing
foreach (i ${${PREFIX}_PROCESS_INCLUDES})
if (${i})
set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
mark_as_advanced(${i})
else (${i})
set (${PREFIX}_FOUND FALSE)
endif (${i})
endforeach (i)
# Process all libraries and set _FOUND to false if any are missing
foreach (i ${${PREFIX}_PROCESS_LIBS})
if (${i})
set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
mark_as_advanced(${i})
else (${i})
set (${PREFIX}_FOUND FALSE)
endif (${i})
endforeach (i)
# Print message and/or exit on fatal error
if (${PREFIX}_FOUND)
if (NOT ${PREFIX}_FIND_QUIETLY)
message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
endif (NOT ${PREFIX}_FIND_QUIETLY)
else (${PREFIX}_FOUND)
if (${PREFIX}_FIND_REQUIRED)
foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
message("${i}=${${i}}")
endforeach (i)
message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
endif (${PREFIX}_FIND_REQUIRED)
endif (${PREFIX}_FOUND)
endif (NOT ${PREFIX}_FOUND)
endmacro (libfind_process)
macro(libfind_library PREFIX basename)
set(TMP "")
if(MSVC80)
set(TMP -vc80)
endif(MSVC80)
if(MSVC90)
set(TMP -vc90)
endif(MSVC90)
set(${PREFIX}_LIBNAMES ${basename}${TMP})
if(${ARGC} GREATER 2)
set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
endif(${ARGC} GREATER 2)
find_library(${PREFIX}_LIBRARY
NAMES ${${PREFIX}_LIBNAMES}
PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
)
endmacro(libfind_library)