# How to only preprocess and link some of the files in cmake

**URL:** https://discourse.cmake.org/t/how-to-only-preprocess-and-link-some-of-the-files-in-cmake/2812
**Category:** Usage
**Tags:** os:windows, gen:makefiles
**Created:** [February 23, 2021, 4:33am UTC](https://discourse.cmake.org/t/how-to-only-preprocess-and-link-some-of-the-files-in-cmake/2812 "2021-02-23T04:33:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![deepan](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/7bcc69/32.png) [@deepan](https://discourse.cmake.org/u/deepan)
#### Post date: [February 23, 2021, 4:33am UTC](https://discourse.cmake.org/t/how-to-only-preprocess-and-link-some-of-the-files-in-cmake/2812/1 "2021-02-23T04:33:59Z")

</div>

I want some of my files only to be preprocessed and linked(.ld files) and others(.c) has to be fully compiled. How to do this in cmake ?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 23, 2021, 6:56pm UTC](https://discourse.cmake.org/t/how-to-only-preprocess-and-link-some-of-the-files-in-cmake/2812/2 "2021-02-23T18:56:41Z")

</div>

I think the best way is something involving `target_link_options`. CMake doesn’t have an abstraction for linker scripts at all and doesn’t have a way to preprocess them. You’ll probably want something like this:

```cmake
add_custom_command(
  DEPENDS linker.ld
  OUTPUT "${output}"
  COMMAND
    cpp # probably coming from `find_program`
    $<COMPILE_DEFINITIONS:mytgt> # might need string manip to add `-D` prefixes
    linker.ld
    -o "${output}")
target_linker_options(mytgt
  PRIVATE
    "LINKER:--script=${output}")

```
