From 663ff1e8c9373e20713fe0dcc95562160efcaf76 Mon Sep 17 00:00:00 2001 From: Benoit Duffez Date: Mon, 8 Mar 2021 09:14:42 -0800 Subject: [PATCH] fix cross compilation see https://github.com/helium/erlang-pbc/pull/15 for details --- c_src/CMakeLists.txt | 6 +++++- c_src/cmake/FindGFComplete.cmake | 9 +++++++-- c_src/cmake/FindJerasure.cmake | 12 +++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/c_src/CMakeLists.txt b/c_src/CMakeLists.txt index 429973e..a986423 100644 --- a/c_src/CMakeLists.txt +++ b/c_src/CMakeLists.txt @@ -1,7 +1,7 @@ ########################################################################## # Project Setup # ########################################################################## -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.11) project(ErlangErasure C) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_C_STANDARD 99) @@ -9,6 +9,10 @@ set(CMAKE_C_STANDARD 99) list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake) include(ASan) +if(DEFINED ENV{CMAKE_TOOLCHAIN_FILE}) + set(CMAKE_TOOLCHAIN_FILE $ENV{CMAKE_TOOLCHAIN_FILE}) +endif() + IF (APPLE) set(CMAKE_MODULE_LINKER_FLAGS "-flat_namespace -undefined suppress") set(CMAKE_MACOSX_RPATH 1) diff --git a/c_src/cmake/FindGFComplete.cmake b/c_src/cmake/FindGFComplete.cmake index af14b2d..61c0039 100644 --- a/c_src/cmake/FindGFComplete.cmake +++ b/c_src/cmake/FindGFComplete.cmake @@ -5,6 +5,11 @@ if(CMAKE_BUILD_TYPE) string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE_UC) endif() +set(CONFIGURE_ARGS $ENV{CONFIGURE_ARGS}) +separate_arguments(CONFIGURE_ARGS) + +set(CONFIGURE_CFLAGS "$ENV{CFLAGS} ${CMAKE_C_FLAGS_${BUILD_TYPE_UC}}") + ExternalProject_Add(gf-complete PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gf-complete GIT_REPOSITORY https://github.com/ceph/gf-complete.git @@ -16,9 +21,9 @@ ExternalProject_Add(gf-complete --prefix=${CMAKE_CURRENT_BINARY_DIR} --with-pic --disable-shared - $ENV{CONFIGURE_ARGS} + ${CONFIGURE_ARGS} CC=${CMAKE_C_COMPILER} - CFLAGS=${CMAKE_C_FLAGS_${BUILD_TYPE_UC}} + CFLAGS=${CONFIGURE_CFLAGS} ${GF_APPLE_ENV} BUILD_COMMAND ${CMAKE_BUILD_TOOL} -j ${GF_APPLE_ENV} BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/lib/libgf_complete.a diff --git a/c_src/cmake/FindJerasure.cmake b/c_src/cmake/FindJerasure.cmake index 7615b40..5c1c2d3 100644 --- a/c_src/cmake/FindJerasure.cmake +++ b/c_src/cmake/FindJerasure.cmake @@ -8,6 +8,12 @@ if(CMAKE_BUILD_TYPE) string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE_UC) endif() +set(CONFIGURE_ARGS $ENV{CONFIGURE_ARGS}) +separate_arguments(CONFIGURE_ARGS) + +set(CONFIGURE_CFLAGS "$ENV{CFLAGS} -I${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_C_FLAGS_${BUILD_TYPE_UC}}") +set(CONFIGURE_LDFLAGS "$ENV{LDFLAGS} -L${CMAKE_CURRENT_BINARY_DIR}/lib") + ExternalProject_Add(jerasure PREFIX ${CMAKE_CURRENT_BINARY_DIR}/jerasure GIT_REPOSITORY http://github.com/ceph/jerasure.git @@ -19,10 +25,10 @@ ExternalProject_Add(jerasure --prefix=${CMAKE_CURRENT_BINARY_DIR} --with-pic --disable-shared - $ENV{CONFIGURE_ARGS} + ${CONFIGURE_ARGS} CC=${CMAKE_C_COMPILER} - "CFLAGS=-I${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_C_FLAGS_${BUILD_TYPE_UC}}" - LDFLAGS=-L${CMAKE_CURRENT_BINARY_DIR}/lib + CFLAGS=${CONFIGURE_CFLAGS} + LDFLAGS=${CONFIGURE_LDFLAGS} ${GF_APPLE_ENV} BUILD_COMMAND ${CMAKE_BUILD_TOOL} -j ${GF_APPLE_ENV} BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/lib/libJerasure.a