# On usage of ExternalData module

**URL:** https://discourse.cmake.org/t/on-usage-of-externaldata-module/633
**Category:** Usage
**Created:** [February 13, 2020, 4:57pm UTC](https://discourse.cmake.org/t/on-usage-of-externaldata-module/633 "2020-02-13T16:57:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Adem\_Budak](https://discourse.cmake.org/user_avatar/discourse.cmake.org/adem_budak/32/144_2.png) [@Adem\_Budak](https://discourse.cmake.org/u/Adem_Budak)
#### Post date: [February 13, 2020, 4:57pm UTC](https://discourse.cmake.org/t/on-usage-of-externaldata-module/633/1 "2020-02-13T16:57:20Z")

</div>

Hi, I’m trying to fetch an archive file from the remote and want to put it on source directory at build time. So tried the following code:

```
  if(CHIP8_DOWNLOAD_ROMS)                                                                                       
      include(ExternalData)                                                                                     
      # https://archive.org/download/Chip-8RomsThatAreInThePublicDomain/c8games.zip                                
      set(ExternalData_URL_TEMPLATES                                                                               
          "${CMAKE_SOURCE_DIR}/%(algo)/%(hash)"                                                                    
          "https://archive.org/download/Chip-8RomsThatAreInThePublicDomain/%(algo)/%(hash)")                       
      ExternalData_Expand_Arguments(                                                                               
          target                                                                                                   
          roms                                                                                                     
          DATA{c8games.zip})                                                                                       
                                                                                                                   
     ExternalData_Add_Target(target)                                                                               
                                                                                                                   
     add_custom_command(TARGET chip8 POST_BUILD                                                                    
      COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:chip8>/roms                                    
      COMMAND ${CMAKE_COMMAND} -E copy ${c8games} $<TARGET_FILE_DIR:chip8>/roms                                    
      COMMAND ${CMAKE_COMMAND} -E chdir $<TARGET_FILE_DIR:chip8>/roms                                          
      COMMAND ${CMAKE_COMMAND} -E tar x ${c8games})                                                                                                                                           
  endif() 

```

These are not a part of the project so I thought it’s better to give client an option to fetch them.  
I downloaded the files on the link and create SHA1 sum using command line utility:

```auto
$ sha1sum c8games.zip

```

And put the checksum result on top level directory: `c8games.zip.sha1`. This is described by the _ExternalData_ module documentation. But when I run:

```auto
$ cmake -DCHIP8_DOWNLOAD_ROMS=On -S . -B build
$ cmake --build build 

```

I got the following output:

```auto
[33%] Generating /home/adem/github/chip-8/build/c8games.zip
-- Fetching "/home/adem/github/chip-8/SHA1/e50d2923c2b3de084eaa0bc055832f6e27d0b5ec"
-- Fetching "https://archive.org/download/Chip-8RomsThatAreInThePublicDomain/SHA1/e50d2923c2b3de084eaa0bc055832f6e27d0b5ec"
CMake Error at /usr/local/share/cmake-3.15/Modules/ExternalData.cmake:1121 (message):
  

  Object SHA1=e50d2923c2b3de084eaa0bc055832f6e27d0b5ec not found at:

    /home/adem/github/chip-8/SHA1/e50d2923c2b3de084eaa0bc055832f6e27d0b5ec ("URL using bad/illegal format or missing URL")
    https://archive.org/download/Chip-8RomsThatAreInThePublicDomain/SHA1/e50d2923c2b3de084eaa0bc055832f6e27d0b5ec ("Unsupported protocol")

make[2]: *** [CMakeFiles/target.dir/build.make:61: c8games.zip-hash-stamp] Error 1
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/target.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

```

I wonder what I’m doing wrong. Any pointer is really appreciated.

---

<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 13, 2020, 8:51pm UTC](https://discourse.cmake.org/t/on-usage-of-externaldata-module/633/2 "2020-02-13T20:51:35Z")

</div>

> `/home/adem/github/chip-8/SHA1/e50d2923c2b3de084eaa0bc055832f6e27d0b5ec ("URL using bad/illegal format or missing URL")`

Based on the example in [https://cmake.org/cmake/help/latest/module/ExternalData.html#introduction](https://cmake.org/cmake/help/latest/module/ExternalData.html#introduction), URLs should have a protocol. So it should be `"file://${CMAKE_SOURCE_DIR}/%(algo)/%(hash)"`

> `https://archive.org/download/Chip-8RomsThatAreInThePublicDomain/SHA1/e50d2923c2b3de084eaa0bc055832f6e27d0b5ec ("Unsupported protocol")`

It seems that the HTTPS protocol is not supported. I guess you could try HTTP.

---

<div class="post-metadata">

### Author: ![Adem\_Budak](https://discourse.cmake.org/user_avatar/discourse.cmake.org/adem_budak/32/144_2.png) [@Adem\_Budak](https://discourse.cmake.org/u/Adem_Budak)
#### Post date: [February 13, 2020, 9:47pm UTC](https://discourse.cmake.org/t/on-usage-of-externaldata-module/633/3 "2020-02-13T21:47:32Z")

</div>

Thanks for the reply… But now I tried with the following:

```auto
 if(CHIP8_DOWNLOAD_ROMS)                                                                                       
      include(ExternalData)                                                                                     
      # https://archive.org/download/Chip-8RomsThatAreInThePublicDomain/c8games.zip                             
      set(ExternalData_URL_TEMPLATES                                                                            
          "file://${CMAKE_SOURCE_DIR}/%(algo)/%(hash)"                                                                                                        
          "http://archive.org/download/Chip-8RomsThatAreInThePublicDomain/%(algo)/%(hash)")                     
      ExternalData_Expand_Arguments(                                                                            
          target                                                                                                
          roms                                                                                                  
          DATA{c8games.zip})                                                                                    
                                                                                                                
     ExternalData_Add_Target(target)                                                                            
                                                                                                                
                                                                                                                
     #add_custom_command(TARGET chip8 POST_BUILD                                                                
     # COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:chip8>/roms                                
     # COMMAND ${CMAKE_COMMAND} -E copy ${c8games} $<TARGET_FILE_DIR:chip8>/roms                                
     # COMMAND ${CMAKE_COMMAND} -E chdir $<TARGET_FILE_DIR:chip8>/roms                                        
     # COMMAND ${CMAKE_COMMAND} -E tar x ${c8games})                                                            
  endif()  

```

and get:

```auto
$ cmake --build build
[66%] Built target chip8
[100%] Generating /home/adem/github/chip-8/build/c8games.zip
-- Fetching "file:///home/adem/github/chip-8/SHA1/e50d2923c2b3de084eaa0bc055832f6e27d0b5ec"
-- Fetching "http://archive.org/download/Chip-8RomsThatAreInThePublicDomain/SHA1/e50d2923c2b3de084eaa0bc055832f6e27d0b5ec"
CMake Error at /usr/local/share/cmake-3.15/Modules/ExternalData.cmake:1121 (message):
  

  Object SHA1=e50d2923c2b3de084eaa0bc055832f6e27d0b5ec not found at:

    file:///home/adem/github/chip-8/SHA1/e50d2923c2b3de084eaa0bc055832f6e27d0b5ec ("Couldn't read a file:// file")
    http://archive.org/download/Chip-8RomsThatAreInThePublicDomain/SHA1/e50d2923c2b3de084eaa0bc055832f6e27d0b5ec ("HTTP response code said error")

make[2]: *** [CMakeFiles/target.dir/build.make:61: c8games.zip-hash-stamp] Error 1
make[1]: *** [CMakeFiles/Makefile2:109: CMakeFiles/target.dir/all] Error 2
make: *** [Makefile:106: all] Error 2

```

---

<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 16, 2020, 1:10am UTC](https://discourse.cmake.org/t/on-usage-of-externaldata-module/633/4 "2020-02-16T01:10:28Z")

</div>

Hmm. It may be easier to (ab)use `ExternalProject` for this.

```cmake
ExternalProject_Add(pdroms
  URL ...
  SOURCE_DIR "extraction/dir"
  BUILD_IN_SOURCE 1 # avoid creation of a build directory
  CONFIGURE_COMMAND ""
  BUILD_COMMAND ""
  INSTALL_COMMAND "")

```
