# Feature Request: CURL\_EXECUTABLE

**URL:** https://discourse.cmake.org/t/feature-request-curl-executable/1619
**Category:** Development
**Created:** [July 24, 2020, 6:50pm UTC](https://discourse.cmake.org/t/feature-request-curl-executable/1619 "2020-07-24T18:50:28Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [July 24, 2020, 6:50pm UTC](https://discourse.cmake.org/t/feature-request-curl-executable/1619/1 "2020-07-24T18:50:28Z")

</div>

I was wondering if it would be possible to add to [FindCURL.cmake](https://cmake.org/cmake/help/latest/module/FindCURL.html) the ability to return `CURL_EXECUTABLE` much like [FindWget.cmake](https://cmake.org/cmake/help/latest/module/FindWget.html) returns `WGET_EXECUTABLE`.

I found myself recently having to figure out how to detect if I am on an AWS EC2 system. As the [preferred method is to query a URL](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html), I wrote something like:

```cmake
   find_package(CURL)
   if (CURL_FOUND)
      execute_process(
         COMMAND curl --connect-timeout 0.1 http://169.254.169.254/latest/meta-data/instance-id
         TIMEOUT 1.0
         OUTPUT_QUIET ERROR_QUIET
         RESULT_VARIABLE STATUS
         )
      if(STATUS AND NOT STATUS EQUAL 0)
         set (DETECTED_SITE ${BUILD_SITE})
      else ()
         set (DETECTED_SITE "AWS")
      endif ()

```

Not pretty, but it works. My only fear is that maybe (?) it is possible for `CURL_FOUND` to be true but `curl` not be in the `PATH`? Maybe not, but using `${CURL_EXECUTABLE}` seems more “right” to me.

(Note: The URL is a bit different because the AWS Guru where I work says he uses that. I follow his lead. 😄)

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [July 24, 2020, 6:56pm UTC](https://discourse.cmake.org/t/feature-request-curl-executable/1619/2 "2020-07-24T18:56:37Z")

</div>

At the moment, `FindCURL` does not search for the `curl` executable. This could be searched for, and provide both a variable and an imported target.

However, there’s an easier way in your case. CMake includes file download capabilities through the [`file(DOWNLOAD)`](https://cmake.org/cmake/help/latest/command/file.html#download) command (it even uses `libcurl` under the hood!)

---

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [July 24, 2020, 7:04pm UTC](https://discourse.cmake.org/t/feature-request-curl-executable/1619/3 "2020-07-24T19:04:16Z")

</div>

@kyle.edwards Hmm. Interesting. I guess I can give that a try. I mainly went with “call curl directly” because I know looking for that URL on a non-AWS system can “lock up” as it retries. But `file(DOWNLOAD)` does provide `TIMEOUT`and `INACTIVITY_TIMEOUT`…

One question: what happens if you are on a system without cURL? Does it fall over to wget?

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [July 24, 2020, 7:05pm UTC](https://discourse.cmake.org/t/feature-request-curl-executable/1619/4 "2020-07-24T19:05:14Z")

</div>

No. CMake requires `libcurl` to build in the first place, so it always has cURL code in the CMake executable - no `curl` command required!

---

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [July 24, 2020, 7:36pm UTC](https://discourse.cmake.org/t/feature-request-curl-executable/1619/5 "2020-07-24T19:36:07Z")

</div>

How very cool 🙂

I’ve now switched to:

```auto
   file(DOWNLOAD http://169.254.169.254/latest/meta-data/instance-id instance-id
      INACTIVITY_TIMEOUT 1.0
      TIMEOUT 1.0
      STATUS DOWNLOAD_STATUS
      )
   list(GET DOWNLOAD_STATUS 0 RETURN_CODE)

   if (RETURN_CODE EQUAL 0)
      set (DETECTED_SITE "AWS")
   else ()
      set (DETECTED_SITE ${BUILD_SITE})
   endif ()

```

which seems to work. I’m debating whether I should `file(REMOVE)` the output. It’s 19 bytes if it exists and I wonder if some day it’ll be useful…

---

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [August 4, 2020, 7:00pm UTC](https://discourse.cmake.org/t/feature-request-curl-executable/1619/6 "2020-08-04T19:00:02Z")

</div>

FYI to those who find this some day, note that if you _do_ use `file(DOWNLOAD)` as I did the _correct_ way to do so is:

```cmake
   file(DOWNLOAD http://169.254.169.254/latest/meta-data/instance-id ${CMAKE_CURRENT_BINARY_DIR}/instance-id
...

```

or the like with a full path. Trying to use this with an Ubuntu image on CircleCI showed this.
