# Why does -D on command line work, but -C with file does not?

**URL:** https://discourse.cmake.org/t/why-does-d-on-command-line-work-but-c-with-file-does-not/7985
**Category:** Usage
**Created:** [April 25, 2023, 9:55pm UTC](https://discourse.cmake.org/t/why-does-d-on-command-line-work-but-c-with-file-does-not/7985 "2023-04-25T21:55:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![RobN](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/e9bcb4/32.png) [@RobN](https://discourse.cmake.org/u/RobN)
#### Post date: [April 25, 2023, 9:55pm UTC](https://discourse.cmake.org/t/why-does-d-on-command-line-work-but-c-with-file-does-not/7985/1 "2023-04-25T21:55:30Z")

</div>

As part of my ongoing flailing and sanity-eroding attempts to compile clang and libc++ for myself, I tried something like this:

```plaintext
% cmake -G Ninja -C phase2.x86.cmake -S runtimes -B build_phase2_x86

```

Where that `phase2.x86.cmake` file contains:

```auto
set(PHASE1_BUILD_DIR /Users/rob/Dev/llvm-project/build_phase1)
set(CMAKE_C_COMPILER ${PHASE1_BUILD_DIR}/bin/clang)
set(CMAKE_CXX_COMPILER ${PHASE1_BUILD_DIR}/bin/clang++)
set(CMAKE_ASM_COMPILER ${PHASE1_BUILD_DIR}/bin/llvm-as)
...

```

But when it runs it ignores that and prints:

```plaintext
-- The C compiler identification is AppleClang 14.0.3.14030022
-- The CXX compiler identification is AppleClang 14.0.3.14030022
...

```

But if I put them on the command line, it seems to work. Well, it errors later, but that’s another problem.

```plaintext
% cmake -G Ninja -C ~/Documents/KnowledgeBase/llvm/phase2.x86.cmake -S runtimes -B build_phase2_x86 -DCMAKE_CXX_COMPILER=${CL_BIN}/clang++ -DCMAKE_C_COMPILER=${CL_BIN}/clang -DCMAKE_ASM_COMPILER=${CL_BIN}/llvm-as
-- The C compiler identification is Clang 17.0.0
-- The CXX compiler identification is Clang 17.0.0
-- The ASM compiler identification is unknown
-- Found assembler: /Users/rob/Dev/llvm-project/build_phase1/bin/llvm-as
...

```

Can someone explain what’s going on there?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [April 26, 2023, 8:56am UTC](https://discourse.cmake.org/t/why-does-d-on-command-line-work-but-c-with-file-does-not/7985/2 "2023-04-26T08:56:00Z")

</div>

As specified in the [cmake documentation](https://cmake.org/cmake/help/latest/manual/cmake.1.html), the [set()](https://cmake.org/cmake/help/latest/command/set.html) commands must have the `CACHE` option…
