Skip to content

Commit

Permalink
Only use subcomponent if TurboFEC not found
Browse files Browse the repository at this point in the history
  • Loading branch information
ncorgan committed Jul 4, 2020
1 parent a16b93e commit a189746
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
40 changes: 24 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,28 @@ find_package(Threads REQUIRED)
find_package(aff3ct REQUIRED)

########################################################################
# Build TurboFEC
# Find or build TurboFEC
########################################################################
set(turbofec_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/turbofec)
set(turbofec_binary_dir ${CMAKE_CURRENT_BINARY_DIR}/turbofec)
find_package(TurboFEC)
if(NOT TURBOFEC_FOUND)
message(STATUS "TurboFEC not found. Building in-tree static library.")

include(ExternalProject)
ExternalProject_Add(
prj_turbofec
SOURCE_DIR ${turbofec_source_dir}
CONFIGURE_COMMAND autoreconf -i ${turbofec_source_dir} && ${turbofec_source_dir}/configure --enable-shared=no --enable-static=yes --prefix=${turbofec_binary_dir}
PREFIX ${turbofec_source_dir}
BUILD_COMMAND make)
set(turbofec_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/turbofec)
set(turbofec_binary_dir ${CMAKE_CURRENT_BINARY_DIR}/turbofec)

ExternalProject_Get_Property(prj_turbofec install_dir)
add_library(turbofec STATIC IMPORTED)
set_property(TARGET turbofec PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/turbofec/lib/libturbofec.a)
include(ExternalProject)
ExternalProject_Add(
prj_turbofec
SOURCE_DIR ${turbofec_source_dir}
CONFIGURE_COMMAND autoreconf -i ${turbofec_source_dir} && ${turbofec_source_dir}/configure --enable-shared=no --enable-static=yes --prefix=${turbofec_binary_dir}
PREFIX ${turbofec_source_dir}
BUILD_COMMAND make)

ExternalProject_Get_Property(prj_turbofec install_dir)

set(TURBOFEC_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/turbofec/include)
set(TURBOFEC_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/turbofec/lib/libturbofec.a)
endif()

########################################################################
# json.hpp header
Expand All @@ -46,7 +52,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/Source
${CMAKE_CURRENT_SOURCE_DIR}/Testing
${CMAKE_CURRENT_BINARY_DIR}/turbofec/include
${TURBOFEC_INCLUDE_DIRS}
${JSON_HPP_INCLUDE_DIR})

configure_file(
Expand Down Expand Up @@ -76,9 +82,11 @@ POTHOS_MODULE_UTIL(
Testing/TestModuleInfo.cpp
Testing/TestUtility.cpp
LIBRARIES
turbofec
${TURBOFEC_LIBRARIES}
aff3ct::aff3ct-shared-lib
ENABLE_DOCS ON
DESTINATION fec
)
add_dependencies(FECBlocks prj_turbofec)
if(NOT TURBOFEC_FOUND)
add_dependencies(FECBlocks prj_turbofec)
endif()
34 changes: 34 additions & 0 deletions cmake/FindTurboFEC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# - Try to find turbofec
# Once done this will define
#
# TURBOFEC_FOUND - system has turbofec
# TURBOFEC_INCLUDE_DIRS - the turbofec include directory
# TURBOFEC_LIBRARIES - Link these to use turbofec
#
# Redistribution and use is allowed according to the terms of the New BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#

include(FindPkgConfig)
pkg_check_modules(PC_TURBOFEC QUIET turbofec)
set(TURBOFEC_DEFINITIONS ${PC_TURBOFEC_CFLAGS_OTHER})

find_path(TURBOFEC_INCLUDE_DIR turbofec/turbo.h
HINTS ${PC_TURBOFEC_INCLUDEDIR} ${PC_TURBOFEC_INCLUDE_DIRS}
PATH_SUFFIXES turbofec)

find_library(TURBOFEC_LIBRARY NAMES turbofec
HINTS ${PC_TURBOFEC_LIBDIR} ${PC_TURBOFEC_LIBRARY_DIRS})

set(TURBOFEC_VERSION ${PC_TURBOFEC_VERSION})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(turbofec
REQUIRED_VARS TURBOFEC_LIBRARY TURBOFEC_INCLUDE_DIR
VERSION_VAR TURBOFEC_VERSION)

mark_as_advanced(TURBOFEC_INCLUDE_DIR TURBOFEC_LIBRARY)

set(TURBOFEC_LIBRARIES ${TURBOFEC_LIBRARY})
set(TURBOFEC_INCLUDE_DIRS ${TURBOFEC_INCLUDE_DIR})

0 comments on commit a189746

Please sign in to comment.