# Escape \`\\\` for use in \`STREQUAL\`?

**URL:** https://discourse.cmake.org/t/escape-for-use-in-strequal/5362
**Category:** Code
**Created:** [April 3, 2022, 4:32pm UTC](https://discourse.cmake.org/t/escape-for-use-in-strequal/5362 "2022-04-03T16:32:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![SamuelMarks](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuelmarks/32/1619_2.png) [@SamuelMarks](https://discourse.cmake.org/u/SamuelMarks)
#### Post date: [April 3, 2022, 4:32pm UTC](https://discourse.cmake.org/t/escape-for-use-in-strequal/5362/1 "2022-04-03T16:32:18Z")

</div>

I am trying to create a header/source from a header-only C library. To do this I need to parse C code to figure out what parts to extract out.

CMake as a language seems incredibly verbose, but I am making progress:

> <https://github.com/offscale/libacquire/blob/master/acquire/CMakeLists.txt#L112-L173>

Which is conceptually and algorithmically similar to what I did [in Python (for Python)](https://github.com/offscale/cdd-python/blob/d50ec0e/cdd/cst_utils.py#L207).

How do I escape the line-continuation character?

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [April 3, 2022, 5:49pm UTC](https://discourse.cmake.org/t/escape-for-use-in-strequal/5362/2 "2022-04-03T17:49:22Z")

</div>

I would not recommend this. If you need to patch sources, then create a fork of the library and maintain it as a separate git repository.

---

<div class="post-metadata">

### Author: ![SamuelMarks](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuelmarks/32/1619_2.png) [@SamuelMarks](https://discourse.cmake.org/u/SamuelMarks)
#### Post date: [April 3, 2022, 6:14pm UTC](https://discourse.cmake.org/t/escape-for-use-in-strequal/5362/3 "2022-04-03T18:14:23Z")

</div>

@benthevining It’s my library. Planning to offer shared, static, header-only, and amalgamation-header-only variants.

(the shared/static variants are a new option, as I expect that approach to give better errors, along with the advantages of including multiple times without worrying about `#define IMPL`)

I mean, I could refactor the library to be header/source and then write concatenation code (which would be simpler). But I’m almost ready from the other direction route, and it would be more generalisable and thus applicable to other peoples header-only projects also.

**How do I escape the line-continuation character for use in `STREQUAL`?**

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [April 3, 2022, 6:25pm UTC](https://discourse.cmake.org/t/escape-for-use-in-strequal/5362/4 "2022-04-03T18:25:36Z")

</div>

I believe you can use backslashes to escape, so an escaped backslash would be `\\`.

I don’t understand why you would want to offer header only and non-header-only versions of a library, it seems like a maintenance burden without much benefit. But, to each their own…

---

<div class="post-metadata">

### Author: ![SamuelMarks](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuelmarks/32/1619_2.png) [@SamuelMarks](https://discourse.cmake.org/u/SamuelMarks)
#### Post date: [April 3, 2022, 8:09pm UTC](https://discourse.cmake.org/t/escape-for-use-in-strequal/5362/5 "2022-04-03T20:09:47Z")

</div>

@benthevining As you can see from the code quoted in my example, I’ve tried this:

> [@SamuelMarks](#):
>
> ```auto
> OR char STREQUAL '\\'
> OR prev_prev_char STREQUAL '\\' OR prev_char STREQUAL '\\'
> 
> ```

Is there a double-quote / single-quote difference that I’m missing? Why would this not match?

---

<div class="post-metadata">

### Author: ![benthevining](https://discourse.cmake.org/user_avatar/discourse.cmake.org/benthevining/32/1924_2.png) [@benthevining](https://discourse.cmake.org/u/benthevining)
#### Post date: [April 3, 2022, 10:59pm UTC](https://discourse.cmake.org/t/escape-for-use-in-strequal/5362/6 "2022-04-03T22:59:13Z")

</div>

I would try double quotes, most strings in CMake are double quoted

---

<div class="post-metadata">

### Author: ![SamuelMarks](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuelmarks/32/1619_2.png) [@SamuelMarks](https://discourse.cmake.org/u/SamuelMarks)
#### Post date: [April 3, 2022, 11:31pm UTC](https://discourse.cmake.org/t/escape-for-use-in-strequal/5362/7 "2022-04-03T23:31:10Z")

</div>

That doesn’t work, if you see in the output you still get the line-continuation character not being matched:

```auto
-- full_line = "#elif defined( __FreeBSD__ ) || defined( __NetBSD__ ) || defined( __OpenBSD__ ) || \
"
-- prev_prev_char = ' '; prev_char = '\'; char = '
'
-- full_line = " defined( __bsdi__ ) || defined( __DragonFly__ ) || defined(macintosh) || \
    defined( __APPLE__ ) || defined( __APPLE_CC__ )

```

---

<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: [April 4, 2022, 1:25am UTC](https://discourse.cmake.org/t/escape-for-use-in-strequal/5362/8 "2022-04-04T01:25:19Z")

</div>

I don’t think single quoted strings are a thing in CMake; you should use double quotes everywhere.

As for the end goal…I think you want a slightly more powerful language that has a C parser as a library or something. CMake itself seems wholly unsuited for this problem. Maybe Python’s `ffi` module has something you can use? Perl probably has something on CPAN.
