3

I want to create a cmake script to build the zlib automatically in my project.

I added

externalproject_add(zlib
  PREFIX .
  # download step
  GIT_REPOSITORY git@github.com:madler/zlib.git
  GIT_TAG v1.2.8
  # configure step
  SOURCE_DIR zlib
  CONFIGURE_COMMAND ${CMAKE_SOURCE_DIR}/build/zlib/zlib/configure --archs="-arch ${ARCH}" --static
  # build step
  BUILD_COMMAND make
  BUILD_IN_SOURCE 1
  # install step
  INSTALL_DIR zlib-${ARCH}
  INSTALL_COMMAND make install
  # logging
  LOG_CONFIGURE 1
  LOG_BUILD 1
  LOG_INSTALL 1
  )

But it generate configuration commands like this:

'/Users/david/Documents/cmake_projects/build/zlib/zlib/configure' '--archs=' '-arch' 'x86_64"' '--static"'

Which I think is not properly quoted.

I tried many tricks, but I cannot get the command work. Any idea?

RAM
  • 2,257
  • 2
  • 19
  • 41
David S.
  • 10,578
  • 12
  • 62
  • 104

1 Answers1

-2

Double quotes prevent string from being split. I'd also separate at least ${ARCH_PARAMS} parameter into separate variable, so, You'd have something like this:

set(ARCH_PARAMS "--archs='-arch ${ARCH}'")
...
...
CONFIGURE_COMMAND ${CMAKE_SOURCE_DIR}/build/zlib/zlib/configure ${ARCH_PARAMS} --static

So, it's gonna be passed as this:

'/tmp/so_test/build/zlib/zlib/configure' '--archs='-arch x64_86'' '--static'

On the side note, zlib config seams a bit fishy, because it keeps complaining about compiler error reporting:

$ ./configure --static --archs="-arch x86_64"

Checking for gcc...

Compiler error reporting is too harsh for ./configure (perhaps remove -Werror).

** ./configure aborting.

Relevant questions:

cmake: How to include literal double-quote in custom command?

Community
  • 1
  • 1
Kamiccolo
  • 7,758
  • 3
  • 34
  • 47
  • Actually quoting the entire argument is enough: `"--archs=-arch xxx"`. cmake will do the quoting. And it works pretty work. – David S. Dec 13 '16 at 12:43
  • @davidshen84 mhm. Could You please clarify the version of CMake You're using? Because on my machine it does not. I guess there was some changes mentioned on the CMake's mailing list involving auto-quoting and compatibility with older versions. – Kamiccolo Dec 13 '16 at 12:58
  • I am using `3.6.1`. But I don't think it is new. You can join the irc channel. I learned that trick there. – David S. Dec 14 '16 at 05:11