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 9243079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:43:44+00:00 2026-06-18T08:43:44+00:00

I am using CMake to define my projects. My goal is to have platform-specific

  • 0

I am using CMake to define my projects. My goal is to have platform-specific files easily accessible for editing, searching, browsing, and source control with across all platforms.

I currently have platform-specific files separated in the cmake description. My CMakeLists.txt file looks something like the following:

 Foo.hpp
 ${platform_directory}/Foo.cpp

Then on disk I have something like this:

 Foo.hpp
 win
  `- Foo.cpp 
 osx
  `- Foo.cpp 

Which in the generated project file looks like:

 Foo.hpp
 Foo.cpp (platform-specific version)

This is perfect for the compiler, but it means that developers lack IDE tooling for non-native platform-specific files.

What I am looking for is something like this (in Xcode):

 Foo.hpp
 Foo.cpp (OS X version)
 win
  `- Foo.cpp (file type set to plain text)

Or in Visual Studio:

 Foo.hpp
 Foo.cpp (Windows version)
 osx
  `- Foo.cpp (build action set to none)

Any ideas on how something like this can be setup CMake?

  • 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-06-18T08:43:46+00:00Added an answer on June 18, 2026 at 8:43 am

    One way would be to add a custom target with no build rules, specifically to hold the files which aren’t part of the given platform’s build; e.g.

    if(WIN32)
      add_library(Foo Foo.hpp win/Foo.cpp)
      add_custom_target(NonWindows SOURCES osx/Foo.cpp)
      source_group("osx" osx/Foo.cpp)
    else(APPLE)
      add_library(Foo Foo.hpp osx/Foo.cpp)
      add_custom_target(NonApple SOURCES win/Foo.cpp)
      source_group("win" win/Foo.cpp)
    endif()
    

    Another option (perhaps closer to what you want, but a bit more “hacky”) is to add all the files to the target, but mark the ones not required for the build as HEADER_FILE_ONLY:

    add_library(Foo Foo.hpp win/Foo.cpp osx/Foo.cpp)
    if(WIN32)
      set_source_files_properties(osx/Foo.cpp PROPERTIES HEADER_FILE_ONLY TRUE)
      source_group("osx" osx/Foo.cpp)
    else(APPLE)
      set_source_files_properties(win/Foo.cpp PROPERTIES HEADER_FILE_ONLY TRUE)
      source_group("win" win/Foo.cpp)
    endif()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently started using CMake for one of my multi-platform projects, but I'm having
I am using CMake to build my project and I have the following line:
gcc 4.4.2 / Visual Studio C++ 2008 I have been using cmake on linux,
I have downloaded mysql-connector-c-6.0.2. I build it using below commands: cmake -G Unix Makefiles
I have tried setting the debug flags using the set command in cmake but
I have an c++ application developed using gcc(4.1) and compiled with CMAKE MakeFiles .
I am using CMake to generate Visual Studio project files. I want to run
Hallo, I'm using CMake as build system in one of my projects which is
Has anyone had luck using CMake to create Ruby bindings via SWIG? I have
We're using CMake to generate solution files for Visual Studio 2008. In addition to

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.