Skip to content

Commit

Permalink
This is to fix MingW building. I also corrected some settings. MingW …
Browse files Browse the repository at this point in the history
…tests are not working yet.
  • Loading branch information
aous72 committed Jan 6, 2024
1 parent 3d8f5c8 commit a3103d6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 85 deletions.
38 changes: 22 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cmake_minimum_required(VERSION 3.11.0)

## Library name/version
include(ojph_libname.cmake)

## project
project (openjph DESCRIPTION "Open source implementation of JPH" LANGUAGES CXX)
project (openjph VERSION ${OPENJPH_VERSION} DESCRIPTION "Open source implementation of JPH" LANGUAGES CXX)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

################################################################################################
Expand Down Expand Up @@ -43,13 +46,10 @@ if (NOT CMAKE_BUILD_TYPE)
endif()
message(STATUS "Building ${CMAKE_BUILD_TYPE}")

## Library name
include(ojph_libname.cmake)

## C++ version and flags
set(CMAKE_CXX_STANDARD 14)
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options(
Expand All @@ -63,14 +63,9 @@ endif()

## The option OJPH_DISABLE_INTEL_SIMD and OJPH_ENABLE_INTEL_AVX512
if (OJPH_DISABLE_INTEL_SIMD)
add_definitions(-DOJPH_DISABLE_INTEL_SIMD)
add_compile_options(-DOJPH_DISABLE_INTEL_SIMD)
elseif (OJPH_ENABLE_INTEL_AVX512)
add_definitions(-DOJPH_ENABLE_INTEL_AVX512)
endif()

## The option BUILD_SHARED_LIBS
if (BUILD_SHARED_LIBS AND MSVC)
add_definitions(-DOJPH_BUILD_SHARED_LIBRARY)
add_compile_options(-DOJPH_ENABLE_INTEL_AVX512)
endif()

## specify output directories
Expand All @@ -89,18 +84,29 @@ endif()
# Install
################################################################################################

set(PKG_CONFIG_INCLUDEDIR "\${prefix}/include")
set(PKG_CONFIG_LIBDIR "\${prefix}/lib")
set(PKG_CONFIG_LIBS "-lopenjph")

include(GNUInstallDirs)
install(TARGETS openjph LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS openjph
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

install (DIRECTORY src/core/common/
install(DIRECTORY src/core/common/
DESTINATION include/openjph
FILES_MATCHING
PATTERN "*.h")

install(FILES "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PROJECT_NAME}.pc"
install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/pkg-config.pc.cmake"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
)

################################################################################################
# Testing (OJPH_BUILD_TESTS)
################################################################################################
Expand Down
2 changes: 1 addition & 1 deletion ojph_libname.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ string(REGEX MATCH "OPENJPH_VERSION_MAJOR ([0-9]*)" _ ${VERFILE})
set(OPENJPH_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "OPENJPH_VERSION_MINOR ([0-9]*)" _ ${VERFILE})
set(OPENJPH_VERSION_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "OPENJPH_VERSION_PATCH ([a-z0-9]*)" _ ${VERFILE})
string(REGEX MATCH "OPENJPH_VERSION_PATCH ([0-9]*)" _ ${VERFILE})
set(OPENJPH_VERSION_PATCH ${CMAKE_MATCH_1})

set(OPENJPH_VERSION "${OPENJPH_VERSION_MAJOR}.${OPENJPH_VERSION_MINOR}.${OPENJPH_VERSION_PATCH}")
Expand Down
4 changes: 2 additions & 2 deletions src/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
############################################################
if( OJPH_ENABLE_TIFF_SUPPORT )

if( WIN32 )
if( MSVC )

set(TIFF_INCLUDE_DIR "C:\\Program Files\\tiff\\include" CACHE PATH "the directory containing the TIFF headers")
set(TIFF_LIBRARY_DEBUG "C:\\Program Files\\tiff\\lib\\tiffd.lib" CACHE FILEPATH "the path to the TIFF library for debug configurations")
Expand All @@ -17,7 +17,7 @@ if( OJPH_ENABLE_TIFF_SUPPORT )
message( STATUS " TIFFXX_LIBRARY_DEBUG : \"${TIFFXX_LIBRARY_DEBUG}\" " )
message( STATUS " TIFFXX_LIBRARY_RELEASE : \"${TIFFXX_LIBRARY_RELEASE}\" " )

endif( WIN32 )
endif( MSVC )

FIND_PACKAGE( TIFF )

Expand Down
10 changes: 5 additions & 5 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ source_group("common" FILES ${COMMON})
source_group("others" FILES ${OTHERS})
source_group("transform" FILES ${TRANSFORM})

configure_file(
"../pkg-config.pc.cmake"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PROJECT_NAME}.pc"
)

if(EMSCRIPTEN)
add_compile_options(-std=c++11 -O3 -fexceptions -DOJPH_DISABLE_INTEL_SIMD)
add_library(openjph ${SOURCES})
Expand All @@ -66,6 +61,11 @@ else()
add_library(openjph ${SOURCES})
endif()

## The option BUILD_SHARED_LIBS
if (BUILD_SHARED_LIBS AND WIN32)
target_compile_definitions(openjph PRIVATE OJPH_BUILD_SHARED_LIBRARY)
endif()

## include library version/name
target_include_directories(openjph PUBLIC common)
target_compile_definitions(openjph PUBLIC _FILE_OFFSET_BITS=64)
Expand Down
87 changes: 27 additions & 60 deletions src/core/common/ojph_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace ojph {


////////////////////////////////////////////////////////////////////////////
class outfile_base
class OJPH_EXPORT outfile_base
{
public:

Expand All @@ -84,24 +84,17 @@ namespace ojph {
};

////////////////////////////////////////////////////////////////////////////
class j2c_outfile : public outfile_base
class OJPH_EXPORT j2c_outfile : public outfile_base
{
public:
OJPH_EXPORT
j2c_outfile() { fh = 0; }
OJPH_EXPORT
~j2c_outfile() { if (fh) fclose(fh); }
~j2c_outfile() override { if (fh) fclose(fh); }

OJPH_EXPORT
void open(const char *filename);
OJPH_EXPORT
virtual size_t write(const void *ptr, size_t size);
OJPH_EXPORT
virtual si64 tell();
OJPH_EXPORT
virtual void flush();
OJPH_EXPORT
virtual void close();
size_t write(const void *ptr, size_t size) override;
si64 tell() override;
void flush() override;
void close() override;

private:
FILE *fh;
Expand All @@ -120,15 +113,13 @@ namespace ojph {
*
* memory data can be accessed using get_data()
*/
class mem_outfile : public outfile_base
class OJPH_EXPORT mem_outfile : public outfile_base
{
public:
/** A constructor */
OJPH_EXPORT
mem_outfile();
/** A destructor */
OJPH_EXPORT
~mem_outfile();
~mem_outfile() override;

/** Call this function to open a memory file.
*
Expand All @@ -138,7 +129,6 @@ namespace ojph {
* @param initial_size is the initial memory buffer size.
* The default value is 2^16.
*/
OJPH_EXPORT
void open(size_t initial_size = 65536);

/** Call this function to write data to the memory file.
Expand All @@ -149,23 +139,20 @@ namespace ojph {
* @param ptr is the address of the new data.
* @param size the number of bytes in the new data.
*/
OJPH_EXPORT
virtual size_t write(const void *ptr, size_t size);
size_t write(const void *ptr, size_t size) override;

/** Call this function to know the file size (i.e., number of bytes used
* to store the file).
*
* @return the file size.
*/
OJPH_EXPORT
virtual si64 tell() { return cur_ptr - buf; }
si64 tell() override { return cur_ptr - buf; }

/** Call this function to close the file and deallocate memory
*
* The object can be used again after calling close
*/
OJPH_EXPORT
virtual void close();
void close() override;

/** Call this function to access memory file data.
*
Expand All @@ -174,7 +161,6 @@ namespace ojph {
*
* @return a constant pointer to the data.
*/
OJPH_EXPORT
const ui8* get_data() { return buf; }

/** Call this function to access memory file data (for const objects)
Expand All @@ -184,7 +170,6 @@ namespace ojph {
*
* @return a constant pointer to the data.
*/
OJPH_EXPORT
const ui8* get_data() const { return buf; }

private:
Expand All @@ -195,7 +180,7 @@ namespace ojph {
};

////////////////////////////////////////////////////////////////////////////
class infile_base
class OJPH_EXPORT infile_base
{
public:
enum seek : int {
Expand All @@ -216,64 +201,46 @@ namespace ojph {
};

////////////////////////////////////////////////////////////////////////////
class j2c_infile : public infile_base
class OJPH_EXPORT j2c_infile : public infile_base
{
public:
OJPH_EXPORT
j2c_infile() { fh = 0; }
OJPH_EXPORT
~j2c_infile() { if (fh) fclose(fh); }
~j2c_infile() override { if (fh) fclose(fh); }

OJPH_EXPORT
void open(const char *filename);

//read reads size bytes, returns the number of bytes read
OJPH_EXPORT
virtual size_t read(void *ptr, size_t size);
size_t read(void *ptr, size_t size) override;
//seek returns 0 on success
OJPH_EXPORT
virtual int seek(si64 offset, enum infile_base::seek origin);
OJPH_EXPORT
virtual si64 tell();
OJPH_EXPORT
virtual bool eof() { return feof(fh) != 0; }
OJPH_EXPORT
virtual void close();
int seek(si64 offset, enum infile_base::seek origin) override;
si64 tell() override;
bool eof() override { return feof(fh) != 0; }
void close() override;

private:
FILE *fh;

};

////////////////////////////////////////////////////////////////////////////
class mem_infile : public infile_base
class OJPH_EXPORT mem_infile : public infile_base
{
public:
OJPH_EXPORT
mem_infile() { close(); }
OJPH_EXPORT
~mem_infile() { }
~mem_infile() override { }

OJPH_EXPORT
void open(const ui8* data, size_t size);

//read reads size bytes, returns the number of bytes read
OJPH_EXPORT
virtual size_t read(void *ptr, size_t size);
size_t read(void *ptr, size_t size) override;
//seek returns 0 on success
OJPH_EXPORT
virtual int seek(si64 offset, enum infile_base::seek origin);
OJPH_EXPORT
virtual si64 tell() { return cur_ptr - data; }
OJPH_EXPORT
virtual bool eof() { return cur_ptr >= data + size; }
OJPH_EXPORT
virtual void close() { data = cur_ptr = NULL; size = 0; }
int seek(si64 offset, enum infile_base::seek origin) override;
si64 tell() override { return cur_ptr - data; }
bool eof() override { return cur_ptr >= data + size; }
void close() override { data = cur_ptr = NULL; size = 0; }

private:
const ui8 *data, *cur_ptr;
size_t size;

};


Expand Down
2 changes: 1 addition & 1 deletion src/core/common/ojph_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@

#define OPENJPH_VERSION_MAJOR 0
#define OPENJPH_VERSION_MINOR 10
#define OPENJPH_VERSION_PATCH beta0
#define OPENJPH_VERSION_PATCH 0

0 comments on commit a3103d6

Please sign in to comment.