Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7175255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:14:55+00:00 2026-05-28T16:14:55+00:00

How do I define a preprocessor variable through CMake? The equivalent code would be

  • 0

How do I define a preprocessor variable through CMake?

The equivalent code would be #define foo.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:14:57+00:00Added an answer on May 28, 2026 at 4:14 pm

    For a long time, CMake had the add_definitions command for this purpose. However, recently the command has been superseded by a more fine grained approach (separate commands for compile definitions, include directories, and compiler options).

    An example using the new add_compile_definitions:

    add_compile_definitions(OPENCV_VERSION=${OpenCV_VERSION})
    add_compile_definitions(WITH_OPENCV2)
    

    Or:

    add_compile_definitions(OPENCV_VERSION=${OpenCV_VERSION} WITH_OPENCV2)
    

    The good part about this is that it circumvents the shabby trickery CMake has in place for add_definitions. CMake is such a shabby system, but they are finally finding some sanity.

    Find more explanation on which commands to use for compiler flags here: https://cmake.org/cmake/help/latest/command/add_definitions.html

    Likewise, you can do this per-target as explained in Jim Hunziker’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which preprocessor define should be used to specify debug sections of code? Use #ifdef
I am trying to pass a preprocessor define into my native code using the
I'm trying to define a C preprocessor variable DEBUG (#define DEBUG) to activate debug
C++ preprocessor #define is totally different. Is the PHP define() any different than just
I have the following preprocessor divective: #ifndef NDEBUG #define TRACE printf #else #define TRACE(...)
If I write a #define that performs an operation using other preprocessor constants, is
what I need is to match multiline preprocessor's statements such as: #define max(a,b) \
I want some examples of C preprocessor directives, such as: #define pi 3.14 #define
How can I define a preprocessor macro when using xcodebuild? I need to build
I need to do an assertion based on two related macro preprocessor #define 's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.