From 8088ba624435aef586be5a08cb60a7910a264451 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 25 Oct 2021 01:48:55 +0100 Subject: [PATCH] Override lzfse CMakeLists.txt. --- 3rdparty/CMakeLists.txt | 5 ++- 3rdparty/lzfse.cmake | 84 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 3rdparty/lzfse.cmake diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 91f24db..60aeb27 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -2,7 +2,10 @@ cmake_policy(SET CMP0077 NEW) include(bzip2.cmake) -#include(lzip.cmake) +include(lzip.cmake) + +include(lzfse.cmake) + # #set(LZFSE_BUNDLE_MODE ON) #add_subdirectory(lzfse) diff --git a/3rdparty/lzfse.cmake b/3rdparty/lzfse.cmake new file mode 100644 index 0000000..f81d9b1 --- /dev/null +++ b/3rdparty/lzfse.cmake @@ -0,0 +1,84 @@ +cmake_minimum_required(VERSION 2.8.12) + +project(lzfse C) +message(STATUS "LZFSE VERSION: Unknown") + +include(CheckCCompilerFlag) + +# If LZFSE is being bundled in another project, we don't want to +# install anything. However, we want to let people override this, so +# we'll use the LZFSE_BUNDLE_MODE variable to let them do that; just +# set it to OFF in your project before you add_subdirectory(lzfse). +get_directory_property(LZFSE_PARENT_DIRECTORY PARENT_DIRECTORY) +if("${LZFSE_BUNDLE_MODE}" STREQUAL "") + # Bundled mode hasn't been set one way or the other, set the default + # depending on whether or not we are the top-level project. + if(LZFSE_PARENT_DIRECTORY) + set(LZFSE_BUNDLE_MODE ON) + else() + set(LZFSE_BUNDLE_MODE OFF) + endif(LZFSE_PARENT_DIRECTORY) +endif() +mark_as_advanced(LZFSE_BUNDLE_MODE) + +if (CMAKE_VERSION VERSION_GREATER 3.2) + cmake_policy (SET CMP0063 NEW) +endif () + +if (CMAKE_VERSION VERSION_GREATER 3.9) + cmake_policy (SET CMP0069 NEW) +endif () + +# Compiler flags +function(lzfse_add_compiler_flags target) + set (flags ${ARGV}) + list (REMOVE_AT flags 0) + + foreach (FLAG ${flags}) + if(CMAKE_C_COMPILER_ID STREQUAL GNU) + # Because https://gcc.gnu.org/wiki/FAQ#wnowarning + string(REGEX REPLACE "\\-Wno\\-(.+)" "-W\\1" flag_to_test "${FLAG}") + else() + set (flag_to_test ${FLAG}) + endif() + + string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" test_name "CFLAG_${flag_to_test}") + + check_c_compiler_flag("${flag_to_test}" "${test_name}") + if(${${test_name}}) + set_property(TARGET "${target}" APPEND_STRING PROPERTY COMPILE_FLAGS " ${FLAG}") + endif() + endforeach() +endfunction() + +if (ENABLE_SANITIZER) + set(CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} -fsanitize=${ENABLE_SANITIZER}") + set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fsanitize=${ENABLE_SANITIZER}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=${ENABLE_SANITIZER}") +endif () + +set(LZFSE_SOURCES + src/lzfse_decode.c + src/lzfse_decode_base.c + src/lzfse_encode.c + src/lzfse_encode_base.c + src/lzfse_fse.c + src/lzvn_decode_base.c + src/lzvn_encode_base.c) + +list(TRANSFORM LZFSE_SOURCES PREPEND "lzfse/") + +add_library(lzfse ${LZFSE_SOURCES}) +lzfse_add_compiler_flags(lzfse -Wall -Wno-unknown-pragmas -Wno-unused-variable) + + +if(CMAKE_VERSION VERSION_LESS 3.1 OR CMAKE_C_COMPLIER_ID STREQUAL "Intel") + lzfse_add_compiler_flags(lzfse -std=c99) +else() + set_property(TARGET lzfse PROPERTY C_STANDARD 99) +endif() + +set_target_properties(lzfse PROPERTIES + POSITION_INDEPENDENT_CODE TRUE + C_VISIBILITY_PRESET hidden + INTERPROCEDURAL_OPTIMIZATION TRUE)