0

I'm having problem understanding how to correctly set the COMPILE_DEFINITIONS target properti in CMake.

my target is add_library(modelutilities STATIC ${modelutilities_SRCS})

I if use

set(modelutilities_COMPILE_DEFINE ${modelutilities_COMPILE_DEFINE} ${Qt5Widgets_COMPILE_DEFINITIONS}) set_target_properties(modelutilities PROPERTIES VERSION "0.0.1" SOVERSION 0 EXPORT_NAME "ModelUtilities" ARCHIVE_OUTPUT_DIRECTORY "${modelutilities_PlatformDir}/lib" LIBRARY_OUTPUT_DIRECTORY "${modelutilities_PlatformDir}/lib" RUNTIME_OUTPUT_DIRECTORY "${modelutilities_PlatformDir}/bin" COMPILE_DEFINITIONS ${modelutilities_COMPILE_DEFINE} ) 

everything works fine, but if I add another line between them with set(modelutilities_COMPILE_DEFINE ${modelutilities_COMPILE_DEFINE} MODELUTILITIES_LIB) it stops working complaining that set_target_properties was called with the wrong number of arguments.

Anyone can spot what I'm doing wrong?

P.S.

I already tried using doublequotes: set(modelutilities_COMPILE_DEFINE ${modelutilities_COMPILE_DEFINE} "MODELUTILITIES_LIB"). It did not change anything

P.P.S.

If I message(STATUS ${modelutilities_COMPILE_DEFINE}) QT_WIDGETS_LIB;QT_GUI_LIB;QT_CORE_LIB in the first case and QT_WIDGETS_LIB;QT_GUI_LIB;QT_CORE_LIB;MODELUTILITIES_LIB in the second

2
  • 1
    May I suggest using target_compile_definitions() instead: cmake.org/cmake/help/latest/command/… Commented Mar 22, 2018 at 18:19
  • That solved my problem. I know it's a workaround but it does the same thing. If you want to put it in an actual answer I'd be happy to accept it Commented Mar 22, 2018 at 18:45

1 Answer 1

1

With newer version of CMake, what is being preached is the idea of targets. So, for example, instead of include_directories() it's now preferred to use target_include_directories().

That being the case I think you'd be better served using the preferred target_compile_definitions() to set compile definitions for your utilities library.

One advantage you get is that your can scope your compile definitions using the PUBLIC or PRIVATE keywords.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.