Awesome idea, +1<div><br></div><div>This is probably the best work-around until includes get a target property.<br clear="all"><div><br></div><div>---------</div>Robert Dailey<br>
<br><br><div class="gmail_quote">On Wed, Nov 2, 2011 at 2:43 AM, Michael Wild <span dir="ltr"><<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 11/01/2011 09:49 PM, Robert Dailey wrote:<br>
> Well if you need any help coding the feature let me know. I'm already<br>
> liking the idea of adding features I want myself into CMake :)<br>
><br>
> Thanks!<br>
><br>
> ---------<br>
> Robert Dailey<br>
><br>
><br>
> On Tue, Nov 1, 2011 at 3:47 PM, David Cole <<a href="mailto:david.cole@kitware.com">david.cole@kitware.com</a><br>
</div><div class="im">> <mailto:<a href="mailto:david.cole@kitware.com">david.cole@kitware.com</a>>> wrote:<br>
><br>
> On Tue, Nov 1, 2011 at 4:33 PM, Robert Dailey <<a href="mailto:rcdailey@gmail.com">rcdailey@gmail.com</a><br>
</div><div class="im">> <mailto:<a href="mailto:rcdailey@gmail.com">rcdailey@gmail.com</a>>> wrote:<br>
> > On Tue, Nov 1, 2011 at 3:32 PM, David Cole <<a href="mailto:david.cole@kitware.com">david.cole@kitware.com</a><br>
</div><div class="im">> <mailto:<a href="mailto:david.cole@kitware.com">david.cole@kitware.com</a>>> wrote:<br>
> >><br>
> >> Not yet<br>
> ><br>
> > Meaning there are plans in the works to add such functionality in<br>
> the near<br>
> > future?<br>
> > For now I guess I could actually hard code VS environment<br>
> variables in my<br>
> > include directory strings, such as $(Configuration).<br>
><br>
> There is a feature planned to add per-target include directories (as a<br>
> target property). As part of that work, we will probably naturally<br>
> also add per-configuration values of that new target property. It is<br>
> not yet added as a feature request in the bug tracker, but there are<br>
> related ones that I may "borrow" for the purpose. Stay tuned for more<br>
> info, but it is not coming in the next week or two. Hopefully, in time<br>
> for 2.8.7, but it depends on timing at this point.... so no promises.<br>
><br>
> For now, your $(Configuration) idea is probably your best bet. (And<br>
> would continue to work even after we implement this feature...)<br>
><br>
><br>
> HTH,<br>
> David<br>
<br>
</div>Alternatively, if you want to keep it cross-platform and generator<br>
independent, you could use a proxy header which #include's the correct<br>
header using relative or absolute paths using #ifdef's. Probably that<br>
proxy header would need to be generated by configure_file(). You then<br>
would pass the configuration name by setting the<br>
COMPILE_DEFINITIONS_<CONFIG> property on the directory, target or source<br>
file affected.<br>
<br>
<br>
Say you have the following layout:<br>
<br>
project/<br>
|-- CMakeLists.txt<br>
|-- src/<br>
| |-- frobnicate.c<br>
`-- include/<br>
|-- Debug/<br>
| |-- foo.h<br>
| `-- bar.h<br>
`-- Optimized/<br>
|-- foo.h<br>
`-- bar.h<br>
<br>
Now, you want to include the configuration dependent foo.h and bar.h in<br>
frobnicate.c without having to change frobnicate.c itself and might look<br>
like this:<br>
<br>
frobnicate.c<br>
<<<<<<<<<<<<<br>
#include "foo.h"<br>
#include "bar.h"<br>
<br>
int main(int argc, char** argv)<br>
{<br>
foo();<br>
bar();<br>
return 0;<br>
}<br>
>>>>>>>>>>>><br>
<br>
To get around the issue of needing a configuration-dependent include<br>
path, you could do the following in your CMakeLists.txt file:<br>
<br>
CMakeLists.txt:<br>
<<<<<<<<<<<<<<<<br>
cmake_minimum_required(VERSION 2.6)<br>
project(frobnicate C)<br>
<br>
# loads of stuff ....<br>
<br>
# generate wrapper headers for foo.h and bar.h<br>
foreach(hdr foo.h bar.h)<br>
# find a good include guard name<br>
string(TOUPPER "${hdr}" incguard)<br>
string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" incguard<br>
"PROXY_HDR_${incguard}")<br>
# write the proxy header<br>
file(WRITE "${PROJECT_BINARY_DIR}/include/${hdr}"<br>
"<br>
/* AUTOMATICALLY GENERATED BY CMAKE -- DO NOT EDIT! */<br>
#pragma once<br>
#ifndef ${incguard}<br>
#define ${incguard}<br>
<br>
/* if building debug configuration, include Debug/${hdr},<br>
otherwise Optimized/${hdr} */<br>
#if defined(CONFIG_DEBUG)<br>
# include \"Debug/${hdr}\"<br>
#else<br>
# include \"Optimized/${hdr}\"<br>
#endif<br>
<br>
#endif<br>
")<br>
endforeach()<br>
<br>
# set up the definitions for the switch yard<br>
set_directory_properties(PROPERTIES<br>
COMPILE_DEFINITIONS_DEBUG CONFIG_DEBUG<br>
COMPILE_DEFINITIONS_RELEASE CONFIG_RELEASE<br>
COMPILE_DEFINITIONS_RELWITHDEBINFO CONFIG_RELWITHDEBINFO<br>
COMPILE_DEFINITIONS_MINSIZEREL CONFIG_MINSIZE_REL)<br>
<br>
# set up the include directories so our proxy headers and the actual<br>
# headers can be found by the preprocessor<br>
include_directories(<br>
${PROJECT_BINARY_DIR}/include<br>
${PROJECT_SOURCE_DIR}/include)<br>
<br>
add_executable(frobnicate frobnicate.c)<br>
<br>
>>>>>>>>>>>>>>><br>
<br>
<br>
HTH<br>
<span class="HOEnZb"><font color="#888888"><br>
Michael<br>
</font></span><div class="HOEnZb"><div class="h5">--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div><br></div>