-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4265 from rouault/embed
Add CMake options EMBED_RESOURCE_FILES and USE_ONLY_EMBEDDED_RESOURCE_FILES for proj.db and proj.ini embedding
- Loading branch information
Showing
20 changed files
with
1,030 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Fedora Rawhide | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- 'docs/**' | ||
pull_request: | ||
paths-ignore: | ||
- 'docs/**' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
|
||
fedora_rawhide: | ||
runs-on: ubuntu-latest | ||
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')" | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Cache | ||
uses: actions/cache@v4 | ||
id: cache | ||
with: | ||
path: | | ||
${{ github.workspace }}/ccache.tar.gz | ||
key: ${{ runner.os }}-cache-fedora_rawhide-${{ github.run_id }} | ||
restore-keys: ${{ runner.os }}-cache-fedora_rawhide- | ||
|
||
- name: Run | ||
run: docker run -e CI -e WORK_DIR="$PWD" -v $PWD:$PWD fedora:rawhide $PWD/.github/workflows/fedora_rawhide/start.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
dnf install -y cmake clang ccache ninja-build sqlite-devel libtiff-devel libcurl-devel diffutils | ||
|
||
cd "$WORK_DIR" | ||
|
||
if test -f "$WORK_DIR/ccache.tar.gz"; then | ||
echo "Restoring ccache..." | ||
(cd $HOME && tar xzf "$WORK_DIR/ccache.tar.gz") | ||
fi | ||
|
||
export CCACHE_CPP2=yes | ||
|
||
ccache -M 500M | ||
ccache -s | ||
|
||
mkdir build | ||
cd build | ||
CC=clang CXX=clang++ cmake .. \ | ||
-DEMBED_RESOURCE_FILES=ON -DUSE_ONLY_EMBEDDED_RESOURCE_FILES=ON -DUSE_CCACHE=ON -DPROJ_DB_CACHE_DIR=$HOME/.ccache .. | ||
make -j$(nproc) | ||
ctest -j$(nproc) | ||
cd .. | ||
|
||
ccache -s | ||
|
||
echo "Saving ccache..." | ||
rm -f "$WORK_DIR/ccache.tar.gz" | ||
(cd $HOME && tar czf "$WORK_DIR/ccache.tar.gz" .cache) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Derived from https://gitlab.com/jhamberg/cmake-examples/-/blob/master/cmake/FileEmbed.cmake | ||
# MIT licensed | ||
# Copyright (c) 2022 Jonathan Hamberg | ||
|
||
function(FileEmbedSetup) | ||
|
||
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/file_embed) | ||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}file_embed) | ||
endif () | ||
|
||
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/file_embed/file_embed_empty.c) | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/file_embed/file_embed_empty.c "") | ||
endif () | ||
|
||
add_library(file_embed ${CMAKE_CURRENT_BINARY_DIR}/file_embed/file_embed_empty.c) | ||
target_include_directories(file_embed PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/file_embed) | ||
|
||
endfunction() | ||
|
||
function(FileEmbedAdd file) | ||
FileEmbedGenerate(${file} var) | ||
target_sources(file_embed PUBLIC ${var}) | ||
|
||
add_custom_command( | ||
OUTPUT ${var} | ||
COMMAND ${CMAKE_COMMAND} | ||
-DRUN_FILE_EMBED_GENERATE=1 | ||
"-DFILE_EMBED_GENERATE_PATH=${file}" | ||
-P ${PROJECT_SOURCE_DIR}/cmake/FileEmbed.cmake | ||
MAIN_DEPENDENCY ${file} | ||
) | ||
endfunction() | ||
|
||
function(FileEmbedGenerate file generated_c) | ||
|
||
get_filename_component(base_filename ${file} NAME) | ||
set(output_filename "${base_filename}.c") | ||
string(MAKE_C_IDENTIFIER ${base_filename} c_name) | ||
file(READ ${file} content HEX) | ||
|
||
string(LENGTH "${content}" size) | ||
math(EXPR size_mult_16 "${size} - (${size} % 16)") | ||
string(SUBSTRING "${content}" 0 ${size_mult_16} content_mult_16) | ||
|
||
string(REGEX REPLACE | ||
"([A-Fa-f0-9][A-Fa-f0-9])\ | ||
([A-Fa-f0-9][A-Fa-f0-9])\ | ||
([A-Fa-f0-9][A-Fa-f0-9])\ | ||
([A-Fa-f0-9][A-Fa-f0-9])\ | ||
([A-Fa-f0-9][A-Fa-f0-9])\ | ||
([A-Fa-f0-9][A-Fa-f0-9])\ | ||
([A-Fa-f0-9][A-Fa-f0-9])\ | ||
([A-Fa-f0-9][A-Fa-f0-9])" | ||
"0x\\1,0x\\2,0x\\3,0x\\4,0x\\5,0x\\6,0x\\7,0x\\8,\n" SEPARATED_HEX "${content_mult_16}") | ||
|
||
set(SEPARATED_HEX_REMAINDER "") | ||
if (NOT ${size_mult_16} EQUAL ${size}) | ||
string(SUBSTRING "${content}" ${size_mult_16} 16 content_remainder) | ||
string(REGEX REPLACE "([A-Fa-f0-9][A-Fa-f0-9])" "0x\\1," SEPARATED_HEX_REMAINDER "${content_remainder}") | ||
endif() | ||
|
||
set(output_c "${SEPARATED_HEX}${SEPARATED_HEX_REMAINDER}") | ||
|
||
set(output_c " | ||
#include \"${c_name}.h\" | ||
const uint8_t ${c_name}_data[] = { | ||
${output_c} | ||
}\; | ||
const unsigned ${c_name}_size = sizeof(${c_name}_data)\; | ||
") | ||
|
||
set(output_h " | ||
#ifndef ${c_name}_H | ||
#define ${c_name}_H | ||
#include <stdint.h> | ||
extern const uint8_t ${c_name}_data[]\; | ||
extern const unsigned ${c_name}_size\; | ||
#endif // ${c_name}_H | ||
") | ||
|
||
|
||
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/file_embed) | ||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}file_embed) | ||
endif () | ||
|
||
|
||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/file_embed/${c_name}.c | ||
${output_c}) | ||
|
||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/file_embed/${c_name}.h | ||
${output_h}) | ||
|
||
set(${generated_c} ${CMAKE_CURRENT_BINARY_DIR}/file_embed/${c_name}.c PARENT_SCOPE) | ||
|
||
endfunction() | ||
|
||
if (RUN_FILE_EMBED_GENERATE) | ||
FileEmbedGenerate(${FILE_EMBED_GENERATE_PATH} var) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "embedded_resources.h" | ||
|
||
#if USE_SHARP_EMBED | ||
const unsigned char *pj_get_embedded_proj_db(unsigned int *pnSize) { | ||
static const unsigned char proj_db[] = { | ||
#embed PROJ_DB | ||
}; | ||
*pnSize = (unsigned int)sizeof(proj_db); | ||
return proj_db; | ||
} | ||
|
||
const char *pj_get_embedded_proj_ini(unsigned int *pnSize) { | ||
static const char proj_ini[] = { | ||
#embed PROJ_INI | ||
}; | ||
*pnSize = (unsigned int)sizeof(proj_ini); | ||
return proj_ini; | ||
} | ||
|
||
#else | ||
|
||
#include "file_embed/proj_db.h" | ||
const unsigned char *pj_get_embedded_proj_db(unsigned int *pnSize) { | ||
*pnSize = proj_db_size; | ||
return proj_db_data; | ||
} | ||
|
||
#include "file_embed/proj_ini.h" | ||
const char *pj_get_embedded_proj_ini(unsigned int *pnSize) { | ||
*pnSize = proj_ini_size; | ||
return (const char *)proj_ini_data; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef EMBEDDED_RESOURCES_H | ||
#define EMBEDDED_RESOURCES_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
const unsigned char *pj_get_embedded_proj_db(unsigned int *pnSize); | ||
const char *pj_get_embedded_proj_ini(unsigned int *pnSize); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* EMBEDDED_RESOURCES_H */ |
Oops, something went wrong.