diff --git a/CMakeLists.txt b/CMakeLists.txt index 703acea459..11e78a601b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,25 +83,40 @@ option(PACKAGING_COMMON "Will produce a package containing common target, config option(PACKAGING_USRP "Will produce a package containing usrp target, configuration files and docs" OFF) option(PACKAGING_PHYSIM "Will produce a package containing physim target, configuration files and docs" OFF) - # Check if asn1c is installed, and check if it supports all options we need # a user can provide ASN1C_EXEC to override an asn1c to use (e.g., parallel # installation) find_program(ASN1C_EXEC_PATH asn1c HINTS /opt/asn1c/bin) set(ASN1C_EXEC ${ASN1C_EXEC_PATH} CACHE FILEPATH "path to asn1c executable") -if(NOT ASN1C_EXEC) - message(FATAL_ERROR "No asn1c found! -You might want to re-run ./build_oai -I -Or provide a path to asn1c using -./build_oai ... --cmake-opt -DASN1C_EXEC=/path/to/asn1c -") +option(AUTO_DOWNLOAD_ASN1C "Automatically download asn1c if not found" OFF) +if (ASN1C_EXEC) + check_option(${ASN1C_EXEC} -gen-APER ASN1C_EXEC) + check_option(${ASN1C_EXEC} -no-gen-UPER ASN1C_EXEC) + check_option(${ASN1C_EXEC} -no-gen-JER ASN1C_EXEC) + check_option(${ASN1C_EXEC} -no-gen-BER ASN1C_EXEC) + check_option(${ASN1C_EXEC} -no-gen-OER ASN1C_EXEC) + add_custom_target(asn1c DEPENDS ${ASN1C_EXEC}) +else () + if (NOT AUTO_DOWNLOAD_ASN1C) + message(FATAL_ERROR "asn1c not found. Install it globally or activate AUTO_DOWNLOAD_ASN1C") + endif() + message(STATUS "Downloading and compile asn1c local in this build tree") + include(ExternalProject) + ExternalProject_Add( + asn1c_gen + GIT_REPOSITORY https://github.com/mouse07410/asn1c + GIT_TAG 940dd5fa9f3917913fd487b13dfddfacd0ded06e + GIT_REMOTE_UPDATE_STRATEGY CHECKOUT + BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/bin/asn1c + BUILD_IN_SOURCE True + CONFIGURE_COMMAND autoreconf -i + BUILD_COMMAND ./configure --prefix ${CMAKE_BINARY_DIR} + COMMAND make -j8 CFLAGS=-fno-strict-aliasing -Wmisleading-indentation + STEP_TARGETS build + ) + set(ASN1C_EXEC ${CMAKE_BINARY_DIR}/bin/asn1c) + add_custom_target(asn1c DEPENDS asn1c_gen) endif() -check_option(${ASN1C_EXEC} -gen-APER ASN1C_EXEC) -check_option(${ASN1C_EXEC} -no-gen-UPER ASN1C_EXEC) -check_option(${ASN1C_EXEC} -no-gen-JER ASN1C_EXEC) -check_option(${ASN1C_EXEC} -no-gen-BER ASN1C_EXEC) -check_option(${ASN1C_EXEC} -no-gen-OER ASN1C_EXEC) - ######################################################### # Base directories, compatible with legacy OAI building # ######################################################### diff --git a/cmake_targets/macros.cmake b/cmake_targets/macros.cmake index c19eb285ef..799bb899ef 100644 --- a/cmake_targets/macros.cmake +++ b/cmake_targets/macros.cmake @@ -84,7 +84,7 @@ function(run_asn1c ASN1C_GRAMMAR ASN1C_PREFIX) set(LOGFILE "${CMAKE_CURRENT_BINARY_DIR}/${GRAMMAR_FILE}.log") add_custom_command(OUTPUT ${ASN1C_OUTPUT} COMMAND ASN1C_PREFIX=${ASN1C_PREFIX} ${ASN1C_EXEC} ${ASN1C_OPTIONS} -D ${CMAKE_CURRENT_BINARY_DIR} ${ASN1C_GRAMMAR} > ${LOGFILE} 2>&1 || ( cat ${LOGFILE} && false ) - DEPENDS ${ASN1C_GRAMMAR} + DEPENDS ${ASN1C_GRAMMAR} asn1c COMMENT "Generating ${ASN1C_COMMENT} from ${GRAMMAR_FILE}" ) endfunction()