# set\_source\_files\_properties with /Tp and /Tc

**URL:** https://discourse.cmake.org/t/set-source-files-properties-with-tp-and-tc/9533
**Category:** Usage
**Tags:** os:windows, comp:msvc, gen:vs
**Created:** [December 1, 2023, 5:22am UTC](https://discourse.cmake.org/t/set-source-files-properties-with-tp-and-tc/9533 "2023-12-01T05:22:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![n-mam](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/6a8cbe/32.png) [@n-mam](https://discourse.cmake.org/u/n-mam)
#### Post date: [December 1, 2023, 5:22am UTC](https://discourse.cmake.org/t/set-source-files-properties-with-tp-and-tc/9533/1 "2023-12-01T05:22:54Z")

</div>

Hi,

I am in the process of porting my project from sln to cmake and I have a situation where I need to compile 2 specific .c files as cpp. I used set\_source\_files\_properties on these 2 files like so:

set\_source\_files\_properties(  
${CMAKE\_CURRENT\_SOURCE\_DIR}/abc/x.c  
${CMAKE\_CURRENT\_SOURCE\_DIR}/abc/y.c  
PROPERTIES COMPILE\_OPTIONS /Tp)

This generates the following compile line

```auto
.......truncated.....
/external:W3 /Gd /TC /analyze- /errorReport:queue /Tp C:\code\abc\x.c C:\code\abc\y.c
  x.c
  Generating Code...
  Compiling...
  y.c
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\yvals_core.h(27): STL1003: Unexpected comp
  iler, expected C++ compiler.
  Generating Code...
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\yvals_core.h(28,1): error C1189: #error: Error in C++ Standard Library usage 
  (compiling source file '../../Ccode/abc/y.c')

```

As you can see the compilation fails, apparently because the /Tp applies to only the first x.c… I manually pasted the command line by introducing an explicit /Tp before y.c as well and it compiles fine then. The original vcxproj (generated by vs) was using CompileAs stanza under the clcompile task for these 2 files individually as opposed to the AdditionalOptions used by cmake generator… Any thoughts on how I could make this work with cmake ? thank you

Neelabh

additional info:

- cmake version 3.28.0-rc5
- having 2 seperate set\_source\_files\_properties one each on x.c and y.c with /Tp also doesn’t help. the result is the same

---

<div class="post-metadata">

### Author: ![n-mam](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/6a8cbe/32.png) [@n-mam](https://discourse.cmake.org/u/n-mam)
#### Post date: [December 1, 2023, 6:06am UTC](https://discourse.cmake.org/t/set-source-files-properties-with-tp-and-tc/9533/2 "2023-12-01T06:06:36Z")

</div>

I checked this further and the below works instead of manually specifying platform switches:

```auto
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/abc/x.c PROPERTIES LANGUAGE CXX)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/abc/y.c PROPERTIES LANGUAGE CXX)

```

thank you.
