Thanks for your suggestion Filipe.

In my original email I didn't make it very clear that I have multiple targets and I only want to add a symbol definition for a specific target. From my understanding (and testing) the command ADD_DEFINITIONS adds a definition for all targets in the project.

I've decided to use CONFIGURE_FILE and explicitly declare #define ${MY_SYMBOL} which will be filled in at configuration time (rather than build time).

Thanks everyone.

Dan


Filipe Sousa wrote:
On Tuesday 04 April 2006 06:10, Dan Mueller wrote:
  
Hi cmake users:

I am trying to use cmake to define a symbol so that I can use the #if
syntax in C++.

I have read the documentation for the SET_TARGET_PROPERTIES command and
it seems to me that there is a property called DEFINE_SYMBOL which sets
"... /a symbol that is defined when compiling C or C++ sources/"
(http://www.cmake.org/HTML/Documentation.html). However, when I use this
property it does *not *define the symbol. I am using CMake v2.2.3 with
Microsoft Visual Studio 7 .NET 2003 on a Win32 machine.

FYI I can get the LINK_FLAGS property to work, but not the DEFINE_SYMBOL...

Have I misunderstood something? Am I setting the property correctly? Any
help would be appreciated. My cmake file and source is below:

Start CMakeLists.txt ====================================================
# Add Project
PROJECT(TestMain)

# Setup output paths
SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin CACHE PATH "Single
output directory for building all libraries." FORCE)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin CACHE PATH "Single
output directory for building all executables." FORCE)

# Add Executable
ADD_EXECUTABLE(TestMain TestMain.cxx)
*SET_TARGET_PROPERTIES(TestMain PROPERTIES DEFINE_SYMBOL "MY_SYMBOL")*
    

ADD_DEFINITIONS(-DMY_SYMBOL)

  
TARGET_LINK_LIBRARIES(TestMain TestMain)
End CMakeLists.txt ====================================================

Start TestMain.cxx ====================================================
#include <iostream>

int main(int argc, char * argv[])
{
    #if (MY_SYMBOL)
        std::cout << "MY_SYMBOL was defined." << std::endl;
    #else
        std::cout << "MY_SYMBOL was NOT defined." << std::endl;
    #endif
}
End TestMain.cxx ====================================================

NOTE: TestMain.exe prints "MY_SYMBOL was NOT defined."

Regards,

Dan [[EMAIL PROTECTED]]
    

[EMAIL PROTECTED] ~ $ cmake --help-command ADD_DEFINITIONS
cmake version 2.3-20060330
  ADD_DEFINITIONS
       Adds -D define flags to the command line of C and C++ compilers.

         ADD_DEFINITIONS(-DFOO -DBAR ...)

       Adds flags to command line of C and C++ compilers.  This command can
       be used to add any flag to a compile line, but the -D flag is accepted
       most C/C++ compilers.  Other flags may not be as portable.


  

_______________________________________________ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake

--
Dan Mueller
PhD Candidate (02562065)
School of Engineering Systems (ES)
Faculty of Built Environment and Engineering (BEE)
Queensland University of Technology (QUT)
CRICOS No: 00213J

Email: [EMAIL PROTECTED]
Phone: +617 3864 9124
Mobile: +61 0401 451 850
Room: Gardens Point S903.11
_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to