[CMake] cmp0065

Johannes Zarl johannes.zarl-zierl at jku.at
Wed Jul 6 17:49:48 EDT 2016


Hi,

On Wednesday 06 July 2016 08:43:44 you wrote:
> > #if defined(WIN32)
> > #endif
> 
> not WIN32 that way... as in add_executable( something WIN32 ... )  (or not
> WIN32)

I'm not sure I can follow. I thought you want to have compile time definitions 
like "-DSOMETHING" for GCC or "/DSOMETHING" for MSVC.
If that's what you want, then use the already defined macros for your target 
platform/OS. For Windows, the correct macro is "_WIN32" (sorry I forgot the 
underscore before).

A comprehensive list of these macros can be found here:
https://sourceforge.net/p/predef/wiki/OperatingSystems/

If that's not what you want, it would help if you could elaborate a little, or 
maybe even provide a minimum working example.

 
> > target_compile_definitions( yourTarget PRIVATE COMPILE_SHELL)
> > https://cmake.org/cmake/help/v3.4/command/target_compile_definitions.html
> > 
> > Is that what you are searching for?
> 
> it says "tems will populate theCOMPILE_DEFINITIONS
> <https://cmake.org/cmake/help/v3.4/prop_tgt/COMPILE_DEFINITIONS.html#prop_tg
> t:COMPILE_DEFINITIONS> property
> of"
> sounds like that will trigger the same CMP0065 warnings.

Did you verify that? I cannot fathom how using target_compile_definitions 
could trigger a CMP0065 warning. But maybe I'm just reading the docs 
completely wrong...
Btw. the documentation states that CMP0065 does not warn by default, but 
silently reverts to the old behavior if it's not set.


Cheers,
  Johannes


P.S.: Checking this using a minimum example does not trigger any warning for 
me on cmake 3.5.2:

--CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(cmake-test)
add_executable(myExe main.cpp)
target_compile_definitions(myExe PRIVATE MY_DEFINITION)
target_compile_definitions(myExe PRIVATE VERSION_STRING="0.8.15")

--main.cpp:
#include <iostream>
#ifdef _WIN32
#warning "Target platform is windows 32 or 64 bit!"
#endif
int main(int argc, char** argv)
{
#ifdef MY_DEFINITION
   std::cout << argv[0] << "compiled with MY_DEFINITION!" << std::endl;
#endif
   std::cout << argv[0] << VERSION_STRING << std::endl;
   return 0;
}

For quoted definitions, I usually use configure_file to create a platform 
header.


More information about the CMake mailing list