Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. CMake: Conditionally define symbols based on target platform?
Forum Updated to NodeBB v4.3 + New Features

CMake: Conditionally define symbols based on target platform?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
3 Posts 2 Posters 186 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ron Menelli
    wrote on last edited by
    #1

    I'm new to CMake after using QMake for many years. I mostly have my project working, but I can't find how to conditionally define symbols based on the platform I'm building for. In QMake, I could just do something like this:

    macx: DEFINES += MAC_ONLY_SYMBOL

    What's the equivalent in CMake?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You should read about target_compile_definitions() to add a compile definition to your target and conditions to check for APPLE.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Ron Menelli
        wrote on last edited by Ron Menelli
        #3

        Thanks very much! The other piece I was missing is that CMake uses if/else statements. So, the result is:

        if(APPLE)
            target_compile_options(mytarget PRIVATE -DMAC_ONLY_SYMBOL)
        else()
            target_compile_options(mytarget PRIVATE -DOTHER_SYMBOL)
        endif()
        
        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved