# Skipping/selecting platform specific source files

**URL:** https://discourse.cmake.org/t/skipping-selecting-platform-specific-source-files/1702
**Category:** Usage
**Created:** [August 13, 2020, 9:22pm UTC](https://discourse.cmake.org/t/skipping-selecting-platform-specific-source-files/1702 "2020-08-13T21:22:27Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![johan556](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johan556/32/788_2.png) [@johan556](https://discourse.cmake.org/u/johan556)
#### Post date: [August 13, 2020, 9:22pm UTC](https://discourse.cmake.org/t/skipping-selecting-platform-specific-source-files/1702/1 "2020-08-13T21:22:27Z")

</div>

I’m looking for a good way to select when platform specific source files should be included in the build. If I for example have “foo\_linux.cpp” and “foo\_windows.cpp”, I would like to select the appropriate version with as little extra work as possible. Currently I have if() statements in my CMakeLists.txt calling target\_sources() differently depending on platform.

But I was hoping to be able to have files more or less automatically selected based for example on filename suffixes (as in my example names above).

Is there some “best practice” in this area with CMake?

Regards,  
Johan Holmberg

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [August 14, 2020, 5:21am UTC](https://discourse.cmake.org/t/skipping-selecting-platform-specific-source-files/1702/2 "2020-08-14T05:21:27Z")

</div>

I use `CMAKE_SYSTEM_NAME` for that.  
In particular, I set custom variable `PLATFORM_SUFFIX` in a central place based on the `CMAKE_SYSTEM_NAME` (and few others in my case). Later I can use it in the source list like:  
`add_executable(myexe main.cpp something${PLATFORM_SUFFIX}.cpp)`.
