Your "project" command should always be the first or second (after cmake_minimum_required) command in your root CMakeLists.txt file, unless you have a very good reason.<br><br><div>Then, on the topic of definitions, this is all you need:</div>
<div>add_definitions("-DLIBRARY_NAME=\"${YOUR_CMAKE_VAR_WITH_LIB_NAME}\"")</div><div><br></div><div>before you add your target (add_library, etc) - CMake will automatically pull the var=value part out, and do quoting appropriate for your compiler.</div>
<div>see also: <a href="http://cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:COMPILE_DEFINITIONS">http://cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:COMPILE_DEFINITIONS</a> (for details and/or another way to achieve the same result, but in a more fine-grained, per-target way that probably is appealing given your goal)</div>
<div><br></div><div>I was hoping that there was an easy solution - hope this helps!</div><div><br></div><div>Ryan</div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br><div class="gmail_quote">On Thu, Sep 16, 2010 at 8:42 PM, J Decker <span dir="ltr"><<a href="mailto:d3ck0r@gmail.com">d3ck0r@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 Thu, Sep 16, 2010 at 6:30 PM, Ryan Pavlik <<a href="mailto:rpavlik@iastate.edu">rpavlik@iastate.edu</a>> wrote:<br>
</div><div class="im">> Why are you trying to do this before the project command?<br>
<br>
<br>
</div><div class="im">To result in a shorthand that I don't HAVE to copy and paste; because<br>
definition of compiler requirements for passing definitions that are<br>
string literals is lacking?<br>
<br>
<br>
</div><div class="im">You can set the<br>
> target name to be something different from the project name, and you can<br>
> even set the output name of the executable/library to be different than what<br>
> would be automatically set by default from the target name.<br>
<br>
<br>
</div><div class="im">Sure... but I don't; so it would be a reasonable shorthand within this<br>
source domain.<br>
<br>
<br>
</div><div class="im">(I've done<br>
> this, to embed the platform into the code and/or output name)<br>
> My guess: you've done a lot of work with makefiles and the C preprocessor.<br>
> It looks like you're overthinking it - CMake is a reasonably high-level<br>
> scripting language, not a macro language or preprocessor.<br>
<br>
<br>
</div><div class="im">Maybe :) That's really the question though - how is this not what I want?<br>
<br>
<br>
</div><div class="im">> Could you share a high-level intended behavior with the list so we might be<br>
> able to give you a more satisfying answer?<br>
<br>
<br>
</div><div class="im">In the end, during compilation I want to define a 'variable' that IS<br>
the name of the library itself. That name is usually only passed to<br>
the linker. different compilers have different syntax for defining<br>
string literals like<br>
<br>
#define TARGET_NAME "MyLibrary.Dll"<br>
<br>
I don't want to define the name in two places, I want it to be<br>
definitively the project name, because why would it be any other name<br>
in a new development?<br>
<br>
gcc[ld] -DTARGET_NAME="\"libsack.so\"" -o libsack.so <sources><br>
<br>
wcc[wlink] -DTARGET_NAME="libsack.so" -o sack.dll <sources><br>
<br>
/* I'm not sure about this one... it might be like gcc, but it may be<br>
version dependant also */<br>
mc[link] -DTARGET_NAME="libsack.so" -o sack.dll <sources><br>
<br>
Since there is no definition in CMAKE for the quote to use to define a<br>
string literal to a definition...<br>
<br>
I think is the syntax to define a macro on the command line that has<br>
spaces, not strings... really probably openwatcom is broken.<br>
<br>
"-DOtherMacro 1+2=3"<br>
</div><div><div></div><div class="h5">_______________________________________________<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><br clear="all"><br>-- <br>Ryan Pavlik<br>HCI Graduate Student<br>Virtual Reality Applications Center<br>Iowa State University<br><br><a href="mailto:rpavlik@iastate.edu">rpavlik@iastate.edu</a><br>
<a href="http://academic.cleardefinition.com">http://academic.cleardefinition.com</a><br>Internal VRAC/HCI Site: <a href="http://tinyurl.com/rpavlik">http://tinyurl.com/rpavlik</a><br>
</div>