cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Unable to build libcurl on mingw with curl-7.26.0

From: Doug <douglas.linder_at_gmail.com>
Date: Wed, 18 Jul 2012 11:05:13 +0800

agh. You are completely correct. Thanks a lot fo that hint.
After forcing all the files in the archive to non-CRLF mode, the build
worked perfectly.

Right. Well, for anyone else who hits this issue, here's a cmake
project fragment to build curl in mingw.

It literally parses every single file and then applies dos2unix to
files which seem to contain a '\r'.
I had no luck with msys git and any of the command line options in
removing the CRs. :/

(There are probably better more awesome less cmake ways of doing this,
but this might at least be a starting point for the next poor soul who
stumbles into this issue).

curlConfig.cmake.in:
set(@PROJECT_NAME@_INCLUDE_DIRS "@PROJECT_INCLUDE_DIRS@")
set(@PROJECT_NAME@_LIBRARIES "@PROJECT_LIBRARIES@")

CMakeLists.txt:
cmake_minimum_required (VERSION 2.8)
project(curl)

# Import macros
file(GLOB PROJECT_MACROS "${PROJECT_SOURCE_DIR}/macros/*.cmake")
foreach(ITEM ${PROJECT_MACROS})
  include(${ITEM})
endforeach()

# Config
set(PROJECT_KEY "curl-7.26.0")

# Source and includes
set(PROJECT_REAL_PATH "${PROJECT_SOURCE_DIR}/3rdparty/${PROJECT_KEY}")
get_filename_component(PROJECT_REAL_PATH ${PROJECT_REAL_PATH} ABSOLUTE)
if (${DEBUG_MESSAGES})
  message("Importing ${PROJECT_KEY} from ${PROJECT_REAL_PATH}")
endif()

# Dependency target; skip building if it exists already.
set(PROJECT_LIB_TARGET "${PROJECT_REAL_PATH}/lib/.libs/libcurl.a")
if (NOT EXISTS ${PROJECT_LIB_TARGET})

  # Window doesn't play well with others
  if (WIN32)
    apply_window_cr_fix("${PROJECT_REAL_PATH}")
  endif()

  # Build
  invoke_autotools("${PROJECT_REAL_PATH}" "${BUILD_EXTRA_FLAGS}")

endif()

# Error if the build using autotools failed
if (NOT EXISTS ${PROJECT_LIB_TARGET})
 message(FATAL_ERROR "Autotools fail! Unable to find target:
${PROJECT_LIB_TARGET}")
endif()

# Lib and includes
set(PROJECT_INCLUDE_DIRS "${PROJECT_REAL_PATH}/include")
set(PROJECT_LIBRARIES "${PROJECT_LIB_TARGET}")
set(PROJECT_NAME "CURL")

# Export libraries
CONFIGURE_FILE(curlConfig.cmake.in "${PROJECT_BINARY_DIR}/curlConfig.cmake")

macros.cmake:
## Configuration options
set(MACROS_CONFIG_DISABLE_WINDOWS_CR_CHECK 0)

## Invoke autotools in the given directory with the given extra args
# @param REAL_PATH The path to the directory containing a 'configure' script.
# @param EXTRA_FLAGS The extra flags to pass to autoconf when invoking it.
function(invoke_autotools REAL_PATH EXTRA_FLAGS)

  # Configure; save build command for debugging.
  set(AUTOTOOLS_CONFIG "configure ${EXTRA_FLAGS}")
  file(WRITE ${REAL_PATH}/cmake.configure ${AUTOTOOLS_CONFIG})

  # Make sure things can be run
  execute_process(COMMAND chmod 755 configure WORKING_DIRECTORY ${REAL_PATH})
  execute_process(COMMAND chmod 755 cmake.configure WORKING_DIRECTORY
${REAL_PATH})

  # Invoke configure
  execute_process(COMMAND sh ${REAL_PATH}/cmake.configure
WORKING_DIRECTORY ${REAL_PATH})

  # Build
  execute_process(COMMAND make WORKING_DIRECTORY ${REAL_PATH})
endfunction()

## Replace any file that contains '\r' with a unix file version.
# This is specifically because autoconfig doesn't work with CR's
# @param REAL_PATH The path to the folder with the files in it
function(apply_window_cr_fix REAL_PATH)
  if(NOT MACROS_CONFIG_DISABLE_WINDOWS_CR_CHECK)

    message("Windows doesn't play nicely with others. Checking for
invalid files...")

    # Working files; these shouldn't conflict with anything.
    set(CHECK_CPATH "${REAL_PATH}/cmake.checkfile")
    set(CONF_CPATH "${REAL_PATH}/cmake.configure")

    # Remove working files so they aren't checked
    file(REMOVE "${CHECK_CPATH}")
    file(REMOVE "${CONF_CPATH}")

    # For all files
    file(GLOB_RECURSE PROJECT_FILES "${REAL_PATH}/*")
    foreach(FILE ${PROJECT_FILES})

      # Check if that file has a carriage return
      message("Checking ${FILE}")
      set(CHECK_CMD "od -c ${FILE} | grep '\\\\r' -m 1\nif [[ $? != 0
]]\; then\n exit 1\nfi")
      file(WRITE "${CHECK_CPATH}" ${CHECK_CMD})
      execute_process(COMMAND sh "${CHECK_CPATH}" RESULT_VARIABLE
RESULT OUTPUT_VARIABLE OUTPUT)

      # If there was a file with CR in it, apply fix.
      if(NOT "${OUTPUT}" STREQUAL "")
        message("\nMatching fragment: ${OUTPUT}")
        execute_process(COMMAND dos2unix -f "${FILE}")
      endif()
    endforeach()
  endif()
endfunction()

~
Doug.

On Wed, Jul 18, 2012 at 2:25 AM, Guenter <lists_at_gknw.net> wrote:
> Hi Doug,
> Am 17.07.2012 17:09, schrieb Doug:
>>
>> In summary, trying to build libcurl from source using 7.26.0 and
>> having no luck at all.
>>
>> and when I try to compile I get:
>
> ...
>
>
>> Anyone know how to get this working?
>
> ...
>>
>> Is that normal?
>
> normal it is not, but I guess that it has to do with crlf vs. lf of certain
> files; I'm currently at exactly this issue and see same errors, and see this
> most likely because stupid msys-git converts files to crlf when I clone from
> git (even when explicitely telling 'git clone -c core.eol=lf'); but when I
> fetch a daily snapshot (which is equal to a release tarball) then all works
> fine provided I extract the tarball from msys shell with tar or bsdtar; so
> can you please check if that solves your issue?
>
> Gün.
>
>
>
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-07-18