diff options
-rw-r--r-- | CMakeLists.txt | 241 | ||||
-rw-r--r-- | cmake/Modules/Version.cmake | 115 | ||||
-rw-r--r-- | cmake/cmake_uninstall.cmake.in | 21 | ||||
-rw-r--r-- | libfec.pc.in | 13 |
4 files changed, 390 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5ee93cc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,241 @@ +######################################################################## +# Project setup +######################################################################## +cmake_minimum_required(VERSION 2.8) +project(libfec C) + +# Select the release build type by default to get optimization flags +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") + message(STATUS "Build type not specified: defaulting to release.") +endif(NOT CMAKE_BUILD_TYPE) +set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "") + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) + +if(NOT LIB_INSTALL_DIR) + set(LIB_INSTALL_DIR lib) +endif() + + +######################################################################## +# Version information +######################################################################## +set(VERSION_INFO_MAJOR 3) +set(VERSION_INFO_MINOR 0) +set(VERSION_INFO_PATCH 0) + +if(NOT DEFINED VERSION_INFO_EXTRA) + set(VERSION_INFO_EXTRA "git") +endif() +include(Version) + +if(NOT DEFINED VERSION) + #set(VERSION "\"${VERSION_INFO_MAJOR}.${VERSION_INFO_MINOR}.${VERSION_INFO_PATCH}\"") + set(VERSION "\"${VERSION_INFO}\"") +endif() + + +######################################################################## +# Compiler specific setup +######################################################################## +if((CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|x86|AMD64") AND (CMAKE_SIZEOF_VOID_P EQUAL 4)) + set(TARGET_ARCH "x86") +elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") AND (CMAKE_SIZEOF_VOID_P EQUAL 8)) + set(TARGET_ARCH "x64") +elseif((CMAKE_SYSTEM_PROCESSOR MATCHES "i386") AND (CMAKE_SIZEOF_VOID_P EQUAL 8) AND (APPLE)) + # Mac is weird like that. + set(TARGET_ARCH "x64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*") + set(TARGET_ARCH "ARM") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le") + set(TARGET_ARCH "ppc64" "ppc64le") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64") + set(TARGET_ARCH "ppc64" "ppc") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") + set(TARGET_ARCH "ppc") +endif() + + +if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANGCC) + add_definitions(-Wall) + add_definitions(-Wno-unused) + + if(TARGET_ARCH MATCHES "x64") + add_definitions(-msse2) + elseif(TARGET_ARCH MATCHES "ppc|ppc64") + add_definitions(-fno-common -faltivec) + endif() + +endif() + + +######################################################################## +# config.h +######################################################################## + +#add_definitions(-DHAVE_CONFIG_H) + +# Checks for includes +include(CheckIncludeFile) +check_include_file("getopt.h" HAVE_GETOPT_H) +check_include_file("stdio.h" HAVE_STDIO_H) +check_include_file("stdlib.h" HAVE_STDLIB_H) +check_include_file("memory.h" HAVE_MEMORY_H) +check_include_file("string.h" HAVE_STRING_H) + +# Checks for functions +include(CheckFunctionExists) +check_function_exists("getopt_long" HAVE_GETOPT_LONG) +check_function_exists("memset" HAVE_MEMSET) +check_function_exists("memmove" HAVE_MEMMOVE) + + +######################################################################## +# Setup apps +######################################################################## +if(TARGET_ARCH MATCHES "x64") + list(APPEND libfec_sources + dotprod_port.c + peakval_port.c + sumsq.c + sumsq_port.c + cpu_mode_x86_64.c + ) + +elseif(TARGET_ARCH MATCHES "x86") + list(APPEND libfec_sources + viterbi27_mmx.c + mmxbfly27.c + viterbi27_sse.c + ssebfly27.c + viterbi27_sse2.c + sse2bfly27.c + viterbi29_mmx.c + mmxbfly29.c + viterbi29_sse.c + ssebfly29.c + viterbi29_sse2.c + sse2bfly29.c + viterbi39_sse2.c + viterbi39_sse.c + viterbi39_mmx.c + viterbi615_mmx.c + viterbi615_sse.c + viterbi615_sse2.c + dotprod_mmx.c + dotprod_mmx_assist.c + dotprod_sse2.c + dotprod_sse2_assist.c + peakval_mmx.c + peakval_mmx_assist.c + peakval_sse.c + peakval_sse_assist.c + peakval_sse2.c + peakval_sse2_assist.c + sumsq.c + sumsq_port.c + sumsq_sse2.c + sumsq_sse2_assist.c + sumsq_mmx.c + sumsq_mmx_assist.c + cpu_features.c + cpu_mode_x86.c + ) + +elseif(TARGET_ARCH MATCHES "ppc|ppc64") + list(APPEND libfec_sources + viterbi27_av.c + viterbi29_av.c + viterbi39_av.c + viterbi615_av.c + encode_rs_av.c + dotprod_av.c + sumsq_av.c + peakval_av.c + cpu_mode_ppc.c + ) +else() + list(APPEND libfec_sources + cpu_mode_generic.c + ) + +endif() + + + +################################################################################ +# Generate pkg-config file +################################################################################ +foreach(inc ${LIBFEC_INCLUDE_DIR}) + list(APPEND LIBFEC_PC_CFLAGS "-I${inc}") +endforeach() + +foreach(lib ${LIBFEC_LIBRARY_DIRS}) + list(APPEND LIBFEC_PC_PRIV_LIBS "-L${lib}") +endforeach() + +set(LIBFEC_PC_PREFIX ${CMAKE_INSTALL_PREFIX}) +set(LIBFEC_PC_EXEC_PREFIX \${prefix}) +set(LIBFEC_PC_LIBDIR \${exec_prefix}/${LIB_INSTALL_DIR}) +set(LIBFEC_PC_INCLUDEDIR \${prefix}/include) +set(LIBFEC_PC_VERSION ${VERSION}) +set(LIBFEC_PC_LIBS "-fec") + +# Use space-delimiter in the .pc file, rather than CMake's semicolon separator +string(REPLACE ";" " " LIBFEC_PC_CFLAGS "${LIBFEC_PC_CFLAGS}") +string(REPLACE ";" " " LIBFEC_PC_LIBS "${LIBFEC_PC_LIBS}") + +# Unset these to avoid hard-coded paths in a cross-environment +if(CMAKE_CROSSCOMPILING) + unset(LIBFEC_PC_CFLAGS) + unset(LIBFEC_PC_LIBS) +endif() + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/libfec.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/libfec.pc + @ONLY +) + +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/libfec.pc + DESTINATION ${LIB_INSTALL_DIR}/pkgconfig/ +) + + +######################################################################## +# Setup libraries +######################################################################## +add_library(libfec_shared SHARED ${libfec_sources}) +set_target_properties(libfec_shared PROPERTIES OUTPUT_NAME fec) +set_target_properties(libfec_shared PROPERTIES SOVERSION ${VERSION_INFO_MAJOR}) + +install(TARGETS libfec_shared + DESTINATION lib) +install(FILES "${PROJECT_SOURCE_DIR}/fec.h" + DESTINATION include) + + +######################################################################## +# Create uninstall target +######################################################################## +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) + + +######################################################################## +# Print Summary +######################################################################## +message(STATUS "") +message(STATUS "##########################################################") +message(STATUS "## Building for version: ${VERSION}") +message(STATUS "## Using install prefix: ${CMAKE_INSTALL_PREFIX}") +message(STATUS "##########################################################") +message(STATUS "") + diff --git a/cmake/Modules/Version.cmake b/cmake/Modules/Version.cmake new file mode 100644 index 0000000..96ee6b7 --- /dev/null +++ b/cmake/Modules/Version.cmake @@ -0,0 +1,115 @@ +# Portions of this file have been borrowed from and/or inspired by +# the Version.cmake from the rtl-sdr project. +# http://sdr.osmocom.org/trac/wiki/rtl-sdr +# +# Provides: +# ${VERSION_INFO_BASE} - Major.Minor.Patch +# ${VERSION_INFO} - Major.minor.Patch[-git_info] +# +# Requires values for: +# ${VERSION_INFO_MAJOR} - Increment on API compatibility changes. +# ${VERSION_INFO_MINOR} - Increment when adding features. +# ${VERSION_INFO_PATCH} - Increment for bug and documentation changes. +# +# Optional: +# ${VERSION_INFO_EXTRA} - Set to "git" to append git info. This is +# intended only for non-versioned development +# builds +# ${VERSION_INFO_OVERRIDE} - Set to a non-null value to override the +# VERSION_INFO_EXTRA logic. This is intended +# for automated snapshot builds from exported +# trees, to pass in the git revision info. +# +if(DEFINED __INCLUDED_TOOLAME-DAB_VERSION_CMAKE) + return() +endif() +set(__INCLUDED_TOOLAME-DAB_VERSION_CMAKE TRUE) + +################################################################################ +# Gather up variables provided by parent script +################################################################################ + +if(NOT DEFINED VERSION_INFO_MAJOR) + message(FATAL_ERROR "VERSION_INFO_MAJOR is not defined") +else() + set(VER_MAJ ${VERSION_INFO_MAJOR}) +endif() + +if(NOT DEFINED VERSION_INFO_MINOR) + message(FATAL_ERROR "VERSION_INFO_MINOR is not defined") +else() + set(VER_MIN ${VERSION_INFO_MINOR}) +endif() + +if(NOT DEFINED VERSION_INFO_PATCH) + message(FATAL_ERROR "VERSION_INFO_PATCH is not defined") +else() + set(VER_PAT ${VERSION_INFO_PATCH}) +endif() + + +################################################################################ +# Craft version number, using git, if needed +################################################################################ +find_package(Git QUIET) + +if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse -- + ERROR_QUIET + RESULT_VARIABLE NOT_GIT_REPOSITORY + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ) + + if(NOT_GIT_REPOSITORY) + set(GIT_INFO "-unknown") + else() + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD -- + OUTPUT_VARIABLE GIT_REV OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ) + + execute_process( + COMMAND ${GIT_EXECUTABLE} diff-index --quiet HEAD -- + RESULT_VARIABLE GIT_DIRTY + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ) + + if(GIT_DIRTY) + set(GIT_INFO "-${GIT_REV}-dirty") + else() + set(GIT_INFO "-${GIT_REV}") + endif() + endif() + +else() + message(WARNING "git missing -- unable to check libladeRF version.") + unset(NOT_GIT_REPOSITORY) + unset(GIT_REV) + unset(GIT_DIRTY) +endif() + + +################################################################################ +# Provide +################################################################################ +set(VERSION_INFO_BASE "${VER_MAJ}.${VER_MIN}.${VER_PAT}") + +# Force the version suffix. Used for automated export builds. +if(VERSION_INFO_OVERRIDE) + set(VERSION_INFO "${VERSION_INFO_BASE}-${VERSION_INFO_OVERRIDE}") + +# Intra-release builds +elseif("${VERSION_INFO_EXTRA}" STREQUAL "git") + set(VERSION_INFO "${VERSION_INFO_BASE}-git${GIT_INFO}") + +# Versioned releases +elseif("${VERSION_INFO_EXTRA}" STREQUAL "") + set(VERSION_INFO "${VERSION_INFO_BASE}") + +# Invalid +else() + message(FATAL_ERROR + "Unexpected definition of VERSION_INFO_EXTRA: ${VERSION_INFO_EXTRA}") +endif() diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in new file mode 100644 index 0000000..2037e36 --- /dev/null +++ b/cmake/cmake_uninstall.cmake.in @@ -0,0 +1,21 @@ +if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") +endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling $ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif(NOT "${rm_retval}" STREQUAL 0) + else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) diff --git a/libfec.pc.in b/libfec.pc.in new file mode 100644 index 0000000..c569da9 --- /dev/null +++ b/libfec.pc.in @@ -0,0 +1,13 @@ +prefix=@LIBFEC_PC_PREFIX@ +exec_prefix=@LIBFEC_PC_EXEC_PREFIX@ +libdir=@LIBFEC_PC_LIBDIR@ +includedir=@LIBFEC_PC_INCLUDEDIR@ + +Name: FEC library +Description: A fork of KA9Q's FEC library +Version: @LIBFEC_PC_VERSION@ +URL: http://opendigitalradio.org +Cflags: -I${includedir}/ @LIBFEC_PC_CFLAGS@ +Libs: -L${libdir}/ @LIBFEC_PC_LIBS@ +Libs.private: @LIBFEC_PC_PRIV_LIBS@ + |