<div class="gmail_quote">On Fri, Apr 3, 2009 at 11:19 PM, Óscar Fuentes <span dir="ltr"><<a href="mailto:ofv@wanadoo.es">ofv@wanadoo.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Philip.<br>
<div class="im"><br>
Philip Lowman <<a href="mailto:philip@yhbt.com">philip@yhbt.com</a>> writes:<br>
<br>
>> I have this:<br>
>><br>
>> add_custom_command(OUTPUT ${LLVM_CONFIG}<br>
>> COMMAND echo "flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CPP_FLAGS}<br>
>> ${CMAKE_C_FLAGS}"<br>
>> .... more stuff ....<br>
>><br>
>><br>
>> When the custom command executes, this is the output:<br>
>><br>
>> flags:<br>
>><br>
>> i.e. the variables are empty, although I previously used add_definitions<br>
>> to add flags and the makefile uses the optimization flags that<br>
>> corresponds to the selected build type.<br>
>><br>
>> How can I access the effective values of the flags used when the<br>
>> makefile is generated?<br>
><br>
</div><div class="im">> CMAKE_CXX_FLAGS / CMAKE_C_FLAGS is empty by default on Linux unless you've<br>
> modified it which may have been what happened. The build type specific<br>
> complilation flags are stored in CMAKE_CXX_FLAGS_<config_type>.<br>
> CMAKE_CXX_FLAGS is a base that gets prepended to all of the build solutions.<br>
><br>
> The command pasted below works for me on CMake 2.6.4 RC3 Win32 using the<br>
> MinGW generator (it outputs the flags used to compile during a Release<br>
> build). If something like this doesn't work for you can you reply with your<br>
> version of CMake and generator you're using?<br>
><br>
> add_custom_target(foo COMMAND C:/cygwin/bin/echo.exe flags:<br>
> ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})<br>
<br>
</div>CMAKE_CXX_FLAGS_RELEASE works, but it is not enough. It still misses the<br>
definitions and other options which are passed to the<br>
compiler. CMAKE_CXX_FLAGS, as noted on my previous message, is empty. <br></blockquote><div><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
add_custom_command(OUTPUT ${LLVM_CONFIG}<br>
</div> COMMAND echo "flags: ${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CPP_FLAGS} ${CMAKE_C_FLAGS}"<br>
COMMAND echo 's!@LLVM_CPPFLAGS@!${CMAKE_CPP_FLAGS}!' > temp.sed<br>
COMMAND echo 's!@LLVM_CFLAGS@!${CMAKE_C_FLAGS}!' >> temp.sed<br>
COMMAND echo 's!@LLVM_CXXFLAGS@!${CMAKE_CXX_FLAGS}!' >> temp.sed<br>
# TODO: Use general flags for linking! not just for shared libs:<br>
COMMAND echo 's!@LLVM_LDFLAGS@!${CMAKE_SHARED_LINKER_FLAGS}!' >> temp.sed<br>
COMMAND echo 's!@LIBS@!!' >> temp.sed # TODO: System libs<br>
COMMAND echo 's!@LLVM_BUILDMODE@!${CMAKE_BUILD_TYPE}!' >> temp.sed<br>
COMMAND sed -f temp.sed < ${LLVM_CONFIG_IN} > ${LLVM_CONFIG}<br>
# some stuff omitted<br>
DEPENDS ${FINAL_LIBDEPS} ${LLVM_CONFIG_IN}<br>
COMMENT "Building llvm-config script."<br>
)<br>
<br>
This builds an script that knows the compiler and linker options used<br>
for building the libraries. Later, other (third party) software can<br>
query the script and check those options for ensuring compatibility with<br>
the libraries.<br>
<br>
`configure_file' is not okay because the "configuration" must be<br>
executed at build time. CMAKE_CXX_FLAGS and co. are also empty at cmake<br>
time though, so `configure_file' would have the same problem.</blockquote><div><br><br>
You might want to have a look at the COMPILE_DEFINITIONS target property.<br>
<br>
Another option of course is you can use configure_file() and substitute
in the preprocessor definitions you care about with #cmakedefine. Just
have it output to the build tree and read it in with a custom command:<br>
<br>
<a href="http://foo.txt.in">foo.txt.in</a>:<br>
#cmakedefine HAVE_LUA<br>
<br>
CMakeLists.txt:<br>
<br>
configure_file(<a href="http://foo.txt.in">foo.txt.in</a> foo.txt)<br>
foo.txt will be in ${CMAKE_CURRENT_BINARY_DIR}... you can use this in custom commands to your hearts content AFAIK<br><br>configure_file() should work with CMAKE_CXX_FLAGS and company, or at least I think it works. Can you attach a trivial reproducer of your problem? I guess I'm hung up on what variables you're talking about that you think would change between CMake configure time and building time? As far as I know the variables in your Makefile with the sole exception of make variables like VERBOSE=1 are all determined at CMake time. configure_file() should make your life quite a bit easier I think.<br>
</div></div><br><br>-- <br>Philip Lowman<br>