<div class="gmail_quote">On Fri, Apr 3, 2009 at 11:19 PM, Óscar Fuentes <span dir="ltr">&lt;<a href="mailto:ofv@wanadoo.es">ofv@wanadoo.es</a>&gt;</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 &lt;<a href="mailto:philip@yhbt.com">philip@yhbt.com</a>&gt; writes:<br>
<br>
&gt;&gt; I have this:<br>
&gt;&gt;<br>
&gt;&gt; add_custom_command(OUTPUT ${LLVM_CONFIG}<br>
&gt;&gt;  COMMAND echo &quot;flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CPP_FLAGS}<br>
&gt;&gt; ${CMAKE_C_FLAGS}&quot;<br>
&gt;&gt; .... more stuff ....<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; When the custom command executes, this is the output:<br>
&gt;&gt;<br>
&gt;&gt; flags:<br>
&gt;&gt;<br>
&gt;&gt; i.e. the variables are empty, although I previously used add_definitions<br>
&gt;&gt; to add flags and the makefile uses the optimization flags that<br>
&gt;&gt; corresponds to the selected build type.<br>
&gt;&gt;<br>
&gt;&gt; How can I access the effective values of the flags used when the<br>
&gt;&gt; makefile is generated?<br>
&gt;<br>
</div><div class="im">&gt; CMAKE_CXX_FLAGS / CMAKE_C_FLAGS is empty by default on Linux unless you&#39;ve<br>
&gt; modified it which may have been what happened.  The build type specific<br>
&gt; complilation flags are stored in CMAKE_CXX_FLAGS_&lt;config_type&gt;.<br>
&gt; CMAKE_CXX_FLAGS is a base that gets prepended to all of the build solutions.<br>
&gt;<br>
&gt; The command pasted below works for me on CMake 2.6.4 RC3 Win32 using the<br>
&gt; MinGW generator (it outputs the flags used to compile during a Release<br>
&gt; build).  If something like this doesn&#39;t work for you can you reply with your<br>
&gt; version of CMake and generator you&#39;re using?<br>
&gt;<br>
&gt; add_custom_target(foo COMMAND C:/cygwin/bin/echo.exe flags:<br>
&gt; ${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 &quot;flags: ${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CPP_FLAGS} ${CMAKE_C_FLAGS}&quot;<br>
  COMMAND echo &#39;s!@LLVM_CPPFLAGS@!${CMAKE_CPP_FLAGS}!&#39; &gt; temp.sed<br>
  COMMAND echo &#39;s!@LLVM_CFLAGS@!${CMAKE_C_FLAGS}!&#39; &gt;&gt; temp.sed<br>
  COMMAND echo &#39;s!@LLVM_CXXFLAGS@!${CMAKE_CXX_FLAGS}!&#39; &gt;&gt; temp.sed<br>
  # TODO: Use general flags for linking! not just for shared libs:<br>
  COMMAND echo &#39;s!@LLVM_LDFLAGS@!${CMAKE_SHARED_LINKER_FLAGS}!&#39; &gt;&gt; temp.sed<br>
  COMMAND echo &#39;s!@LIBS@!!&#39; &gt;&gt; temp.sed                    # TODO: System libs<br>
  COMMAND echo &#39;s!@LLVM_BUILDMODE@!${CMAKE_BUILD_TYPE}!&#39; &gt;&gt; temp.sed<br>
  COMMAND sed -f temp.sed &lt; ${LLVM_CONFIG_IN} &gt; ${LLVM_CONFIG}<br>
# some stuff omitted<br>
  DEPENDS ${FINAL_LIBDEPS} ${LLVM_CONFIG_IN}<br>
  COMMENT &quot;Building llvm-config script.&quot;<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&#39; is not okay because the &quot;configuration&quot; must be<br>
executed at build time. CMAKE_CXX_FLAGS and co. are also empty at cmake<br>
time though, so `configure_file&#39; 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&#39;m hung up on what variables you&#39;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>