# MSVC Flag /TP is set on a C target when added as a subdirectory

**URL:** https://discourse.cmake.org/t/msvc-flag-tp-is-set-on-a-c-target-when-added-as-a-subdirectory/680
**Category:** Usage
**Tags:** comp:msvc, gen:ninja, os:windows
**Created:** [February 21, 2020, 4:49pm UTC](https://discourse.cmake.org/t/msvc-flag-tp-is-set-on-a-c-target-when-added-as-a-subdirectory/680 "2020-02-21T16:49:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Cojosh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/77aa72/32.png) [@Cojosh](https://discourse.cmake.org/u/Cojosh)
#### Post date: [February 21, 2020, 4:49pm UTC](https://discourse.cmake.org/t/msvc-flag-tp-is-set-on-a-c-target-when-added-as-a-subdirectory/680/1 "2020-02-21T16:49:16Z")

</div>

Hi,  
I am currently unable to add a static c library (among other c++ targets) with add\_subdirectory as cmake seems to set /TP (c++ mode) causing the compile to fail, even when explicitly setting LANGUAGE and LINKER\_LANGUAGE to c.

If i run cmake directly in the folder of the c project /TP is not set.

To fix this i have now manually added the compile flag /TC.

C Lib

```
    file(GLOB fooSources CONFIGURE_DEPENDS src/**.c)
    file(GLOB fooHeaders CONFIGURE_DEPENDS include/**.h)

    add_library(foo STATIC ${fooSources} ${fooHeaders})

    target_include_directories(foo PUBLIC include)
    set_target_properties(foo PROPERTIES LANGUAGE C LINKER_LANGUAGE C)
    target_compile_options(foo PRIVATE /TC)

```

C++ lib

```
file(GLOB barSources CONFIGURE_DEPENDS src/**.cpp)
file(GLOB barHeaders CONFIGURE_DEPENDS include/bar/**.hpp )

add_library(bar SHARED ${barSources} ${barHeaders})
target_include_directories(bar PUBLIC include/bar)

```

I am using cmake 3.16.4 with the Ninja Generator and Visual Studio 2010.

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [February 21, 2020, 8:16pm UTC](https://discourse.cmake.org/t/msvc-flag-tp-is-set-on-a-c-target-when-added-as-a-subdirectory/680/2 "2020-02-21T20:16:03Z")

</div>

Is there a call to the `project` command in the top-level `CMakeLists.txt` fold or one of the parent `CMakeLists.txt` files?

Maybe `project` is called in a way that enables only the `CXX` language.

---

<div class="post-metadata">

### Author: ![Cojosh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/77aa72/32.png) [@Cojosh](https://discourse.cmake.org/u/Cojosh)
#### Post date: [February 24, 2020, 2:28pm UTC](https://discourse.cmake.org/t/msvc-flag-tp-is-set-on-a-c-target-when-added-as-a-subdirectory/680/3 "2020-02-24T14:28:27Z")

</div>

Thankyou for your quick response. Making sure all files had a lowercase file ending (`.c` instead of `.C`) etc. seems to have fixed the problem.
