include(ExternalProject)

#set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/leveldb")


include(ProjectSecp256k1)
add_subdirectory(bigd)
add_subdirectory(fmt)
add_subdirectory(openssl)
add_subdirectory(ethash)
add_subdirectory(snappy)
add_subdirectory(leveldb)

add_subdirectory(spdlog)
add_subdirectory(sqlcipher)

set(SQLITE_LIB sqlcipher)

# SOCI configuration
set(SOCI_STATIC ON)
#set(SOCI_SHARED OFF)
set(SOCI_SHARED OFF CACHE BOOL "USE ONLY STATIC" FORCE)

add_subdirectory(soci)
add_subdirectory(soci_sqlite3)

#add_subdirectory(soci_mysql)
include(ExternalProject)

#set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/leveldb")


include(ProjectSecp256k1)
add_subdirectory(bigd)
add_subdirectory(fmt)
add_subdirectory(openssl)
add_subdirectory(ethash)
add_subdirectory(snappy)
add_subdirectory(leveldb)

add_subdirectory(spdlog)

if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
  # On Android, temporary directories are a bit special and are not located in the same place, such
  # as /tmp or /usr/tmp; for this reason, we ask temporary files to be stored in memory instead
  message("Compiling SQLCipher for Android with file temporary directory disabled (all-on-memory).")
  add_definitions(-DSQLITE_TEMP_STORE=3)
endif ()

add_subdirectory(sqlcipher)

set(SQLITE_LIB sqlcipher)

# SOCI configuration
set(SOCI_STATIC ON)
#set(SOCI_SHARED OFF)
set(SOCI_SHARED OFF CACHE BOOL "USE ONLY STATIC" FORCE)

add_subdirectory(soci)
add_subdirectory(soci_sqlite3)

#add_subdirectory(soci_mysql)

Make SQLCipher to use memory to implement temp fs instead of files.
Make SQLCipher to use memory to implement temp fs instead of files.

This might be needed as none of the default SQLite temporary directories
(/usr/tmp, /tmp/, ., etc.) are available to be used as temporary
directories. I still don’t quite get why we haven’t bumped into that
situation yet but after analysis of LLC-292, I ended up by having to
lookup the `SQLITE_IOERR_GETTEPMPATH` error raised by SQLite3. That
error is set, on Unix systems, in the `unixGetTempname` function when it
fails to get a temporary file directory. In order to get it, it uses
internally the `unixTempFileDir` function, which is basicaly:

```c
static const char *unixTempFileDir(void){
  static const char *azDirs[] = {
     0,
     0,
     "/var/tmp",
     "/usr/tmp",
     "/tmp",
     "."
  };
  unsigned int i = 0;
  struct stat buf;
  const char *zDir = sqlite3_temp_directory;

  if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
  if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
  while(1){
    if( zDir!=0
     && osStat(zDir, &buf)==0
     && S_ISDIR(buf.st_mode)
     && osAccess(zDir, 03)==0
    ){
      return zDir;
    }
    if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break;
    zDir = azDirs[i++];
  }
  return 0;
}
```

The `azDirs` array is traversed and exhausted because no environment
variable is passed and none of "/var/tmp", "/usr/tmp", "/tmp" and "."
are available as read-write directories.

One possible alternative to look at: pass en environment variable set to
"/data/local/tmp", but I’m not sure this location is really safe nor
even available on all devices.

Relates to LLC-292.
