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

  • SEARCH
  • Home
  • 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 6649247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:45:04+00:00 2026-05-26T00:45:04+00:00

In my particular CMake project, I have three C++ files: a.cpp b.cpp c.cpp I

  • 0

In my particular CMake project, I have three C++ files:

a.cpp
b.cpp
c.cpp

I want ‘a.cpp’ to be compiled in all configurations (release & debug).
I only want ‘b.cpp’ to be compiled in DEBUG configuration.
I only want ‘c.cpp’ to be compiled in RELEASE configuration.

How can I do this? I need something similar to the debug and optimized keywords that are accepted by the target_link_libraries() CMake operation.

  • 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-26T00:45:04+00:00Added an answer on May 26, 2026 at 12:45 am

    As far as I know cmake does not provide a way to exclude some files based on configuration. So you need a workaround to achieve this behavior.

    For example, you can wrap the whole content of b.cpp and c.cpp with some guard macro:

    #ifdef BUILD_ME
    //original content of your file
    #endif
    

    and next set configuration-specific compiler definitions in cmake:

    if (${CMAKE_GENERATOR} MATCHES "Make" AND "${CMAKE_BUILD_TYPE}" STREQUAL "")
        # This block might be needed because CMAKE_BUILD_TYPE is usually
        # undefined for makefiles.
        # And COMPILE_DEFINITIONS_RELEASE are not chosen by default.
        set(CMAKE_BUILD_TYPE RELEASE)
    endif()
    
    set_source_files_properties(b.cpp PROPERTIES COMPILE_DEFINITIONS_DEBUG BUILD_ME )
    set_source_files_properties(c.cpp PROPERTIES COMPILE_DEFINITIONS_RELEASE BUILD_ME )
    add_executable(target_name a.cpp b.cpp c.cpp)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a particular project I have, no server side code is allowed. How can
I have one particular file in my project which is being worked on by
In particular what strengths does it have over caching features of Asp.net
In particular, would it be possible to have code similar to this c++ code
My particular problem: I have a string which specifies an aribitrary type in a
My particular scenario: I want to spin up a new Linode VM solo for
So I have some particular variables that mess up the content management system I'm
Suppose I want a particular format of date of birth, like (mm-dd-yyyy). How can
In particular, I want to make sure to avoid the mistake made in Microsoft's
In particular, I want to generate a tolerance interval, for which I would need

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.