4

I need to compile boost libraries with ExternalProject_Add, and the build command needs c++11 flags on MacOS platform with Clang.

The command should look like this:

./bin/b2 debug release cxxflags="-std=c++11 -stdlib=libc++" linkflags=-stdlib=libc++

But I have a problem with the quotes and space.

set(BOOST_CXX_FLAGS cxxflags="-std=c++11 -stdlib=libc++")
set(BOOST_TOOL_SET toolset=clang ${BOOST_CXX_FLAGS}
linkflags=-stdlib=libc++)
ExternalProject_Add(boost
  ....
  BUILD_COMMAND ./bin/b2 debug release
    ${BOOST_TOOL_SET} 
  ....
)

The ${BOOST_TOOL_SET} value is a list, and cxxflags="-std=c++11 -stdlib=libc++" is one item in it. The generated command line becomes strange:

./bin/b2 debug release "cxxflags=\"-std=c++11 -stdlib=libc++\""
linkflags=-stdlib=libc++

It seems the flag is translated by CMake when it detected the space inside the argument and wrapped it with quote marks, but it's not what I want.

I searched on the Internet, but haven't found any help. Is there any tip about this issue?

RAM
  • 2,257
  • 2
  • 19
  • 41
watson
  • 395
  • 1
  • 5
  • 14
  • Are you sure your desired syntax is actually correct? BTW, on any Unix shell, it is actually equivalent to what CMake produces. – Angew is no longer proud of SO Jun 17 '13 at 09:34
  • I have tried the following command line on macos, and boost building is success: ./bin/b2 debug release cxxflags="-std=c++11 -stdlib=libc++" linkflags=-stdlib=libc++ – watson Jun 17 '13 at 12:44

2 Answers2

3

This should work:

set(BOOST_CXX_FLAGS "cxxflags=-std=c++11 -stdlib=libc++")

This should produce

./bin/b2 debug release "cxxflags=-std=c++11 -stdlib=libc++"

Under normal shell parsing rules, this is equivalent to what works for you:

./bin/b2 debug release cxxflags="-std=c++11 -stdlib=libc++"
Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
1

This doesn't answer your question exactly, as in I can't see a way to get your requested command line to the b2 exe with the cxxflags="-std=c++11 -stdlib=libc++" portion correctly formatted.

However, I believe you can accomplish the desired effect by calling cxxflags= twice. Each argument is appended to the compiler flags eventually invoked by b2.

So you should be able to do:

set(BOOST_CXX_FLAGS cxxflags=-std=c++11 cxxflags=-stdlib=libc++)

and the eventual command invoked by b2 will be something like

"clang++" ... -std=c++11 -stdlib=libc++ ...

To verify this, you can add -d+2 to your command:

BUILD_COMMAND ./bin/b2 debug release ${BOOST_TOOL_SET} -d+2

This causes the full commands to be written to the boost-build-out.log file in your boost-stamp directory.

Fraser
  • 74,704
  • 20
  • 238
  • 215