From 41158c4bd5d57bed8df78f71c1b197290295cb1f Mon Sep 17 00:00:00 2001 From: Yoann Potinet Date: Mon, 22 Feb 2021 00:24:24 -0500 Subject: [PATCH 1/5] Fix third-party linking --- 3rdparty/jpeg-compressor/CMakeLists.txt | 4 ++-- 3rdparty/lzma/Linux/CMakeLists.txt | 3 +-- 3rdparty/lzma/Windows/CMakeLists.txt | 2 +- 3rdparty/miniz/CMakeLists.txt | 2 +- CMakeLists.txt | 2 +- test_package/test_package.cpp | 1 + 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/3rdparty/jpeg-compressor/CMakeLists.txt b/3rdparty/jpeg-compressor/CMakeLists.txt index d1199ed..b515445 100644 --- a/3rdparty/jpeg-compressor/CMakeLists.txt +++ b/3rdparty/jpeg-compressor/CMakeLists.txt @@ -9,12 +9,12 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(JPGD_SRC_LIST jpgd.cpp) set(JPGD_HDR_LIST jpgd.h jpgd_idct.h) -add_library(jpgd ${JPGD_SRC_LIST} ${JPGD_HDR_LIST}) +add_library(jpgd OBJECT EXCLUDE_FROM_ALL ${JPGD_SRC_LIST} ${JPGD_HDR_LIST}) target_include_directories(jpgd PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) set(JPGE_SRC_LIST jpge.cpp) set(JPGE_HDR_LIST jpge.h jpge.h) -add_library(jpge EXCLUDE_FROM_ALL ${JPGE_SRC_LIST} ${JPGE_HDR_LIST}) +add_library(jpge OBJECT EXCLUDE_FROM_ALL ${JPGE_SRC_LIST} ${JPGE_HDR_LIST}) target_include_directories(jpge PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(jpgd jpge PROPERTIES diff --git a/3rdparty/lzma/Linux/CMakeLists.txt b/3rdparty/lzma/Linux/CMakeLists.txt index 3b6a016..7d424ab 100644 --- a/3rdparty/lzma/Linux/CMakeLists.txt +++ b/3rdparty/lzma/Linux/CMakeLists.txt @@ -31,7 +31,6 @@ set(lzma_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/LzmaTypes.h ) - if(WIN32) list(APPEND lzma_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/LzFindMt.cpp @@ -41,7 +40,7 @@ if(WIN32) ) endif() -add_library(lzma EXCLUDE_FROM_ALL STATIC ${lzma_SOURCES}) +add_library(lzma OBJECT EXCLUDE_FROM_ALL ${lzma_SOURCES}) target_include_directories(lzma PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(lzma PROPERTIES diff --git a/3rdparty/lzma/Windows/CMakeLists.txt b/3rdparty/lzma/Windows/CMakeLists.txt index 6bc281b..1eb3352 100644 --- a/3rdparty/lzma/Windows/CMakeLists.txt +++ b/3rdparty/lzma/Windows/CMakeLists.txt @@ -7,7 +7,7 @@ if(MSVC) list(APPEND lzma_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/7zVersion.rc) endif() -add_library(lzma EXCLUDE_FROM_ALL STATIC ${lzma_SOURCES} ${lzma_HEADERS}) +add_library(lzma OBJECT EXCLUDE_FROM_ALL ${lzma_SOURCES} ${lzma_HEADERS}) target_include_directories(lzma PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(lzma PROPERTIES FOLDER "3rdparty") diff --git a/3rdparty/miniz/CMakeLists.txt b/3rdparty/miniz/CMakeLists.txt index 7cbac1a..40c847a 100644 --- a/3rdparty/miniz/CMakeLists.txt +++ b/3rdparty/miniz/CMakeLists.txt @@ -30,7 +30,7 @@ else() message(STATUS "Miniz not found") message(STATUS "Building miniz from 3rdparty sources") - add_library(miniz STATIC EXCLUDE_FROM_ALL miniz.c miniz.h) + add_library(miniz OBJECT EXCLUDE_FROM_ALL miniz.c miniz.h) target_include_directories(miniz PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(miniz PROPERTIES diff --git a/CMakeLists.txt b/CMakeLists.txt index 82ae64f..36e1d89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.4) +cmake_minimum_required(VERSION 3.12) project(Crunch2 VERSION "1.2.0") if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/conanbuildinfo.cmake") diff --git a/test_package/test_package.cpp b/test_package/test_package.cpp index 3cd509d..302d476 100644 --- a/test_package/test_package.cpp +++ b/test_package/test_package.cpp @@ -4,6 +4,7 @@ int main() { + crn_get_file_type_ext(crn_file_type::cCRNFileTypeCRN); std::cout << "crnlib " << crn_get_version() << std::endl; return 0; } From 8f56454e65bcee9accbde93cc96427e22a4abfa7 Mon Sep 17 00:00:00 2001 From: Yoann Potinet Date: Mon, 22 Feb 2021 00:24:44 -0500 Subject: [PATCH 2/5] Update copyright --- crunch/crunch.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crunch/crunch.cpp b/crunch/crunch.cpp index 9575031..5e8f872 100644 --- a/crunch/crunch.cpp +++ b/crunch/crunch.cpp @@ -5,19 +5,19 @@ * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. - * + * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: - * + * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation or credits * is required. - * + * * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. - * + * * 3. This notice may not be removed or altered from any source distribution. */ @@ -1428,7 +1428,7 @@ static void print_title() console::printf("crunch - Advanced DXTn Texture Compressor - https://github.com/FrozenStormInteractive/Crunch2"); console::printf(""); console::printf("Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC"); - console::printf("Copyright (c) 2020 FrozenStorm Interactive, Yoann Potinet"); + console::printf("Copyright (c) 2020-2021 FrozenStorm Interactive, Yoann Potinet"); console::printf(""); console::printf("crnlib version %s %s Built %s, %s", crn_get_version(), crnlib_is_x64() ? "x64" : "x86", __DATE__, __TIME__); console::printf(""); From 8e2d8d9864d8a45b36f407d079ff213485bc2531 Mon Sep 17 00:00:00 2001 From: Yoann Potinet Date: Mon, 22 Feb 2021 00:43:23 -0500 Subject: [PATCH 3/5] Export cmake targets --- crnlib/CMakeLists.txt | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/crnlib/CMakeLists.txt b/crnlib/CMakeLists.txt index 1a7d9d8..8ed464c 100644 --- a/crnlib/CMakeLists.txt +++ b/crnlib/CMakeLists.txt @@ -162,12 +162,20 @@ add_library(crn ${CRNLIB_SRCS}) set_property(TARGET crn PROPERTY CXX_STANDARD 11) target_include_directories(crn PUBLIC - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/../inc + $ + $ + $ # PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} + $ +) +target_link_libraries(crn + PRIVATE + $ + $ + $ + $ + $ ) -target_link_libraries(crn PRIVATE lzma jpge jpgd miniz stb) include(GenerateExportHeader) generate_export_header(crn) @@ -177,7 +185,12 @@ if(NOT WIN32) target_link_libraries(crn PUBLIC Threads::Threads) endif() -install(TARGETS crn) +install(TARGETS crn EXPORT crnTargets) +install(EXPORT crnTargets + FILE crunchTargets.cmake + NAMESPACE crunch:: + DESTINATION lib/cmake/crunch +) file(GLOB CRN_INC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../inc/*.h) list(APPEND CRN_INC_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/crn_export.h) install(FILES ${CRN_INC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) From 35140528beae97472cc161905997d184aeb04286 Mon Sep 17 00:00:00 2001 From: Yoann Potinet Date: Tue, 23 Feb 2021 22:31:43 -0500 Subject: [PATCH 4/5] Add jpeg-compressor from conan --- 3rdparty/jpeg-compressor/CMakeLists.txt | 61 +++++++++++++++++-------- 3rdparty/miniz/CMakeLists.txt | 2 +- 3rdparty/stb/CMakeLists.txt | 4 +- conanfile.py | 3 +- crnlib/CMakeLists.txt | 3 +- 5 files changed, 47 insertions(+), 26 deletions(-) diff --git a/3rdparty/jpeg-compressor/CMakeLists.txt b/3rdparty/jpeg-compressor/CMakeLists.txt index b515445..d86bb4e 100644 --- a/3rdparty/jpeg-compressor/CMakeLists.txt +++ b/3rdparty/jpeg-compressor/CMakeLists.txt @@ -1,23 +1,44 @@ cmake_minimum_required(VERSION 3.0) project(jpeg-compressor) -set(BUILD_SHARED_LIBS OFF) - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -set(JPGD_SRC_LIST jpgd.cpp) -set(JPGD_HDR_LIST jpgd.h jpgd_idct.h) -add_library(jpgd OBJECT EXCLUDE_FROM_ALL ${JPGD_SRC_LIST} ${JPGD_HDR_LIST}) -target_include_directories(jpgd PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - -set(JPGE_SRC_LIST jpge.cpp) -set(JPGE_HDR_LIST jpge.h jpge.h) -add_library(jpge OBJECT EXCLUDE_FROM_ALL ${JPGE_SRC_LIST} ${JPGE_HDR_LIST}) -target_include_directories(jpge PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - -set_target_properties(jpgd jpge PROPERTIES - FOLDER "3rdparty" - POSITION_INDEPENDENT_CODE ON -) +find_package(jpeg-compressor QUIET) + +if(jpeg-compressor_FOUND) + + if(NOT TARGET jpeg-compressor) + if(TARGET jpeg-compressor::jpeg-compressor) + add_library(jpeg-compressor ALIAS jpeg-compressor::jpeg-compressor) + else() + add_library(jpeg-compressor INTERFACE) + if(jpeg-compressor_INCLUDE_DIRS) + target_include_directories(jpeg-compressor INTERFACE ${jpeg-compressor_INCLUDE_DIRS}) + endif() + if(jpeg-compressor_LIBRARIES) + target_link_libraries(jpeg-compressor INTERFACE ${jpeg-compressor_LIBRARIES}) + endif() + if(jpeg-compressor_COMPILE_DEFINITIONS) + target_compile_definitions(jpeg-compressor INTERFACE ${jpeg-compressor_COMPILE_DEFINITIONS}) + endif() + if(jpeg-compressor_COMPILE_OPTIONS_LIST) + target_compile_options(jpeg-compressor INTERFACE ${jpeg-compressor_COMPILE_OPTIONS_LIST}) + endif() + endif() + endif() + +else() + + message(STATUS "jpeg-compressor not found") + message(STATUS "Building jpeg-compressor from 3rdparty sources") + + set(JPGC_SRC_LIST jpgd.cpp jpge.cpp) + set(JPGC_HDR_LIST jpgd.h jpgd_idct.h jpge.h) + add_library(jpeg-compressor OBJECT EXCLUDE_FROM_ALL ${JPGC_SRC_LIST} ${JPGC_HDR_LIST}) + target_include_directories(jpeg-compressor PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + + set_target_properties(jpeg-compressor PROPERTIES + FOLDER "3rdparty" + POSITION_INDEPENDENT_CODE ON + ) + +endif() + diff --git a/3rdparty/miniz/CMakeLists.txt b/3rdparty/miniz/CMakeLists.txt index 40c847a..3e17b31 100644 --- a/3rdparty/miniz/CMakeLists.txt +++ b/3rdparty/miniz/CMakeLists.txt @@ -27,7 +27,7 @@ if(miniz_FOUND) else() - message(STATUS "Miniz not found") + message(STATUS "miniz not found") message(STATUS "Building miniz from 3rdparty sources") add_library(miniz OBJECT EXCLUDE_FROM_ALL miniz.c miniz.h) diff --git a/3rdparty/stb/CMakeLists.txt b/3rdparty/stb/CMakeLists.txt index 8278701..414f78e 100644 --- a/3rdparty/stb/CMakeLists.txt +++ b/3rdparty/stb/CMakeLists.txt @@ -23,10 +23,10 @@ if(stb_FOUND) else() - message(STATUS "Stb not found") + message(STATUS "stb not found") message(STATUS "Building stb from 3rdparty sources") add_library(stb INTERFACE) - target_include_directories(stb INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) + target_include_directories(stb INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) endif() diff --git a/conanfile.py b/conanfile.py index ddcddde..fda503f 100644 --- a/conanfile.py +++ b/conanfile.py @@ -19,7 +19,7 @@ class Crunch2Conan(ConanFile): "fPIC": True, "shared": False, } - + _cmake = None @property @@ -37,6 +37,7 @@ def configure(self): def requirements(self): self.requires("miniz/2.1.0") self.requires("stb/20200203") + self.requires("jpeg-compressor/cci.20200507") def _configure_cmake(self): if self._cmake: diff --git a/crnlib/CMakeLists.txt b/crnlib/CMakeLists.txt index 8ed464c..7571707 100644 --- a/crnlib/CMakeLists.txt +++ b/crnlib/CMakeLists.txt @@ -171,8 +171,7 @@ target_include_directories(crn target_link_libraries(crn PRIVATE $ - $ - $ + $ $ $ ) From cb22171ff518b063a675d4a5bbef0fb92d112410 Mon Sep 17 00:00:00 2001 From: Yoann Potinet Date: Thu, 25 Feb 2021 23:49:34 -0500 Subject: [PATCH 5/5] Fix operator unlimited recursive calls --- crnlib/crn_hash_map.h | 4 ++-- crnlib/crn_helpers.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crnlib/crn_hash_map.h b/crnlib/crn_hash_map.h index 086391c..73e4100 100644 --- a/crnlib/crn_hash_map.h +++ b/crnlib/crn_hash_map.h @@ -439,7 +439,7 @@ namespace crnlib } inline bool operator!=(const const_iterator& b) const { - return *this != b; + return !(*this == b); } inline bool operator==(const iterator& b) const { @@ -447,7 +447,7 @@ namespace crnlib } inline bool operator!=(const iterator& b) const { - return *this != b; + return !(*this == b); } private: diff --git a/crnlib/crn_helpers.h b/crnlib/crn_helpers.h index 5de0658..d7aa601 100644 --- a/crnlib/crn_helpers.h +++ b/crnlib/crn_helpers.h @@ -40,7 +40,7 @@ namespace crnlib { friend bool operator!=(const T& x, const T& y) { - return x != y; + return (!(x == y)); } friend bool operator>(const T& x, const T& y) { @@ -48,11 +48,11 @@ namespace crnlib } friend bool operator<=(const T& x, const T& y) { - return y >= x; + return (!(y < x)); } friend bool operator>=(const T& x, const T& y) { - return x >= y; + return (!(x < y)); } };