Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass parameter with spaces to CMake ExternalProject_Add BUILD_COMMAND

I'm trying to cross compile bzip2 in Linux utilizing CMake's ExternalProject_Add(...) command.

However, in order to cross-compile libbzip, you must modify some of the Makefile macros to execute the build. Here is my current cross compile variable:

set(bzlib_CROSS CC=${CROSS_PREFIX}gcc AR=${CROSS_PREFIX}ar RANLIB=${CROSS_PREFIX}ranlib LDFLAGS=-L${bzlib_MINGW_SRC}/lib CFLAGS=-Wall -Winline -O2 -g -I${bzlib_MINGW_SRC}/include)

This variable is then used for the build command

set(bzlib_BUILD make ${bzlib_CROSS} PREFIX=${DEPENDENCY_DIR})

CMake errors because it is trying to pass -O2, -g, etc. to make, which of course doesn't work, but when I try to add quotes around the CFLAGS variable it says

cc1: error: unrecognized command line option '-Wall -Winline -O2 -g -I/long/path/here/include'

Is it possible to set a Makefile macro with spaces in it using CMake's BUILD_COMMAND? Thanks!

like image 410
mevatron Avatar asked Nov 15 '11 22:11

mevatron


1 Answers

Figured it out...I needed to split the quoted string into its own variable like this

set(bzlib_CFLAGS "-Wall -Winline -O2 -g -I${bzlib_MINGW_SRC}/include")
set(bzlib_CROSS CC=${CROSS_PREFIX}gcc AR=${CROSS_PREFIX}ar RANLIB=${CROSS_PREFIX}ranlib LDFLAGS=-L${bzlib_MINGW_SRC}/lib CFLAGS=${bzlib_CFLAGS})

This worked!

like image 119
mevatron Avatar answered Sep 25 '22 12:09

mevatron