-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: migrate build system from the premaek5 to CMake.
Premake5 build is too complex for this project, it showed multiple compile-time errors and link-time erros. Replace the build system with CMake to avoid those errors, CMake is officially supported by Emscripten toolchain, and it worked perfectly.
- Loading branch information
1 parent
2668f45
commit b254593
Showing
12 changed files
with
130 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
build-*/ | ||
cmake-build-*/ |
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,77 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
set(CMAKE_CXX_STANDARD 20) | ||
project(zstd-codec) | ||
|
||
OPTION(ZSTD_CODEC_BUILD_TEST "Build Tests" ON) | ||
|
||
# Zstandard | ||
set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "disable programs") | ||
set(ZSTD_BUILD_CONTRIB OFF CACHE BOOL "disable contrib") | ||
set(ZSTD_BUILD_TESTS OFF CACHE BOOL "disable tests") | ||
set(ZSTD_BUILD_SHARED OFF CACHE BOOL "disable shared library") # use static library only | ||
add_subdirectory(zstd/build/cmake) | ||
|
||
# zstd-codec (common) | ||
add_library(zstd-codec STATIC | ||
src/common-types.h | ||
src/raii-resource.h | ||
src/zstd-codec.cc | ||
src/zstd-codec.h | ||
src/zstd-dict.cc | ||
src/zstd-dict.h | ||
src/zstd-stream.cc | ||
src/zstd-stream.h | ||
) | ||
add_dependencies(zstd-codec libzstd_static) | ||
target_compile_definitions(zstd-codec PUBLIC -DZSTD_STATIC_LINKING_ONLY) | ||
target_include_directories(zstd-codec PUBLIC | ||
${CMAKE_SOURCE_DIR}/zstd/lib | ||
src | ||
) | ||
target_link_libraries(zstd-codec PUBLIC libzstd_static) | ||
|
||
# zstd-codec-binding/zstd-codec-binding-wasm (for Browser) | ||
if (EMSCRIPTEN) | ||
add_executable(zstd-codec-binding src/binding/emscripten/zstd-binding.cc) | ||
target_link_libraries(zstd-codec-binding PRIVATE zstd-codec) | ||
target_link_options(zstd-codec-binding PRIVATE | ||
"SHELL: --bind" | ||
"SHELL: --memory-init-file 0" | ||
"SHELL: -s DEMANGLE_SUPPORT=1" | ||
"SHELL: -s MODULARIZE=1" | ||
"SHELL: -s NODEJS_CATCH_EXIT=0" | ||
"SHELL: -s NODEJS_CATCH_REJECTION=0" | ||
"SHELL: -s WASM=0" | ||
) | ||
|
||
add_executable(zstd-codec-binding-wasm src/binding/emscripten/zstd-binding.cc) | ||
target_link_libraries(zstd-codec-binding-wasm PRIVATE zstd-codec) | ||
target_link_options(zstd-codec-binding-wasm PRIVATE | ||
"SHELL: --bind" | ||
"SHELL: --memory-init-file 0" | ||
"SHELL: -s DEMANGLE_SUPPORT=1" | ||
"SHELL: -s MODULARIZE=1" | ||
"SHELL: -s NODEJS_CATCH_EXIT=0" | ||
"SHELL: -s NODEJS_CATCH_REJECTION=0" | ||
"SHELL: -s WASM=1" | ||
"SHELL: -s SINGLE_FILE=1" | ||
"SHELL: -s BINARYEN_ASYNC_COMPILATION=1" | ||
) | ||
endif (EMSCRIPTEN) | ||
|
||
if (ZSTD_CODEC_BUILD_TEST) | ||
add_executable(test-zstd-codec | ||
test/main.cc | ||
test/catch.hpp | ||
) | ||
target_link_libraries(test-zstd-codec PUBLIC zstd-codec) | ||
if (EMSCRIPTEN) | ||
target_compile_definitions(test-zstd-codec PRIVATE | ||
"-DHAS_FS_WRITE=0" | ||
) | ||
target_link_options(test-zstd-codec PRIVATE | ||
"SHELL: --embed-file ${CMAKE_SOURCE_DIR}/test/fixtures@test/fixtures" | ||
"SHELL: --memory-init-file 0" | ||
) | ||
endif (EMSCRIPTEN) | ||
endif (ZSTD_CODEC_BUILD_TEST) |
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,14 @@ | ||
#include <cstdio> | ||
#include <emscripten.h> | ||
|
||
#include "zstd.h" | ||
|
||
EMSCRIPTEN_KEEPALIVE | ||
extern "C" void say_hello() { | ||
printf("Hello, World!\n"); | ||
} | ||
|
||
EMSCRIPTEN_KEEPALIVE | ||
extern "C" unsigned int zstd_version() { | ||
return ZSTD_versionNumber(); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include <cstdio> | ||
#include <climits> | ||
#include <functional> | ||
|
||
#include "zstd.h" | ||
|
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#include <algorithm> | ||
#include "zstd-dict.h" | ||
#include "zstd-stream.h" | ||
#include "zstd.h" | ||
|
||
// | ||
// ZstdCompressStream | ||
|
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <memory> | ||
|
||
#include "common-types.h" | ||
#include "zstd.h" | ||
|
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