Skip to content

Commit eb1774a

Browse files
authored
Merge pull request #185 from aous72/multi-generation
Add support for macOS multi-generation, and adds -fPIC to library.
2 parents 5df0f8c + 6576c2b commit eb1774a

26 files changed

+163
-28
lines changed

.github/workflows/ccp-workflow.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
matrix:
1515
include: [
1616
{ system: MacOS, runner: macos-latest },
17-
{ system: Ubuntu-20, runner: ubuntu-20.04 },
17+
{ system: Ubuntu-22, runner: ubuntu-22.04 },
1818
{ system: Ubuntu-latest, runner: ubuntu-latest },
1919
]
2020
name: ${{ matrix.system }} Build
@@ -28,6 +28,24 @@ jobs:
2828
run: make
2929
working-directory: build
3030

31+
build_mac:
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
include: [
36+
{ system: MacOS, runner: macos-latest },
37+
]
38+
name: ${{ matrix.system }} Build
39+
runs-on: ${{ matrix.runner }}
40+
steps:
41+
- uses: actions/checkout@v4
42+
- name: cmake
43+
run: cmake -DOJPH_BUILD_STREAM_EXPAND=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DOJPH_ENABLE_TIFF_SUPPORT=OFF ..
44+
working-directory: build
45+
- name: build
46+
run: make
47+
working-directory: build
48+
3149
build_windows:
3250
strategy:
3351
fail-fast: false

CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.11.0)
1+
cmake_minimum_required(VERSION 3.12.0)
22

33
## Library name/version
44
include(ojph_version.cmake)
@@ -19,6 +19,22 @@ include(target_arch.cmake)
1919
target_architecture(OJPH_TARGET_ARCH)
2020
message(STATUS "CPU Architecture is ${OJPH_TARGET_ARCH}")
2121

22+
## Building for multi-generation
23+
# This is useful for when we are building a multi-architecture build, such as when using
24+
# the -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" build configuration
25+
if (CMAKE_OSX_ARCHITECTURES)
26+
list(FIND CMAKE_OSX_ARCHITECTURES "x86_64" x86_64_index)
27+
if (${x86_64_index} GREATER -1)
28+
set(MULTI_GEN_X86_64 TRUE)
29+
endif()
30+
unset(x86_64_index)
31+
list(FIND CMAKE_OSX_ARCHITECTURES "arm64" arm64_index)
32+
if (${arm64_index} GREATER -1)
33+
set(MULTI_GEN_ARM64 TRUE)
34+
endif()
35+
unset(arm64_index)
36+
endif()
37+
2238
## options
2339
option(BUILD_SHARED_LIBS "Shared Libraries" ON)
2440
option(OJPH_ENABLE_TIFF_SUPPORT "Enables input and output support for TIFF files" ON)

src/apps/ojph_compress/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ if(EMSCRIPTEN)
2121
endif()
2222
else()
2323
if (NOT OJPH_DISABLE_SIMD)
24-
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64") OR ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_I386"))
24+
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64")
25+
OR ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_I386")
26+
OR MULTI_GEN_X86_64)
27+
2528
if (NOT OJPH_DISABLE_SSE4)
2629
list(APPEND SOURCES ${OJPH_IMG_IO_SSE4})
2730
source_group("others" FILES ${OJPH_IMG_IO_SSE4})
@@ -38,7 +41,9 @@ else()
3841
set_source_files_properties(${OJPH_IMG_IO_SSE4} PROPERTIES COMPILE_FLAGS -msse4.1)
3942
set_source_files_properties(${OJPH_IMG_IO_AVX2} PROPERTIES COMPILE_FLAGS -mavx2)
4043
endif()
41-
elseif ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_ARM")
44+
endif()
45+
46+
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_ARM") OR MULTI_GEN_ARM64)
4247

4348
endif()
4449

src/apps/ojph_expand/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ if(EMSCRIPTEN)
2121
endif()
2222
else()
2323
if (NOT OJPH_DISABLE_SIMD)
24-
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64") OR ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_I386"))
24+
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64")
25+
OR ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_I386")
26+
OR MULTI_GEN_X86_64)
27+
2528
if (NOT OJPH_DISABLE_SSE4)
2629
list(APPEND SOURCES ${OJPH_IMG_IO_SSE4})
2730
source_group("others" FILES ${OJPH_IMG_IO_SSE4})
@@ -38,7 +41,9 @@ else()
3841
set_source_files_properties(${OJPH_IMG_IO_SSE4} PROPERTIES COMPILE_FLAGS -msse4.1)
3942
set_source_files_properties(${OJPH_IMG_IO_AVX2} PROPERTIES COMPILE_FLAGS -mavx2)
4043
endif()
41-
elseif ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_ARM")
44+
endif()
45+
46+
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_ARM") OR MULTI_GEN_ARM64)
4247

4348
endif()
4449

src/apps/others/ojph_img_io_avx2.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
// Date: 23 May 2022
3636
//***************************************************************************/
3737

38+
#include "ojph_arch.h"
39+
#if defined(OJPH_ARCH_I386) || defined(OJPH_ARCH_X86_64)
3840

3941
#include <cstdlib>
4042
#include <cstring>
@@ -352,3 +354,5 @@ namespace ojph {
352354
}
353355
}
354356
}
357+
358+
#endif

src/apps/others/ojph_img_io_sse41.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
// Date: 23 May 2022
3636
//***************************************************************************/
3737

38+
#include "ojph_arch.h"
39+
#if defined(OJPH_ARCH_I386) \
40+
|| defined(OJPH_ARCH_X86_64) \
41+
|| defined(OJPH_ENABLE_WASM_SIMD)
3842

3943
#include <cstdlib>
4044
#include <cstring>
@@ -505,3 +509,5 @@ namespace ojph {
505509
}
506510
}
507511
}
512+
513+
#endif

src/core/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ if(EMSCRIPTEN)
4040
endif()
4141
else()
4242
if (NOT OJPH_DISABLE_SIMD)
43-
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64") OR ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_I386"))
43+
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64")
44+
OR ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_I386")
45+
OR MULTI_GEN_X86_64)
4446

4547
if (NOT OJPH_DISABLE_SSE)
4648
list(APPEND SOURCES ${CODESTREAM_SSE} ${TRANSFORM_SSE})
@@ -67,7 +69,7 @@ else()
6769
source_group("transform" FILES ${TRANSFORM_AVX2})
6870
source_group("coding" FILES ${CODING_AVX2})
6971
endif()
70-
if ((NOT OJPH_DISABLE_AVX512) AND ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64"))
72+
if (NOT OJPH_DISABLE_AVX512)
7173
list(APPEND SOURCES ${CODING_AVX512} ${TRANSFORM_AVX512})
7274
source_group("coding" FILES ${CODING_AVX512})
7375
source_group("transform" FILES ${TRANSFORM_AVX512})
@@ -104,14 +106,14 @@ else()
104106
set_source_files_properties(transform/ojph_transform_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
105107
set_source_files_properties(transform/ojph_transform_avx512.cpp PROPERTIES COMPILE_FLAGS -mavx512f)
106108
endif()
109+
endif()
107110

108-
elseif ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_ARM")
111+
if (("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_ARM") OR MULTI_GEN_ARM64)
109112

110113
endif()
111114

112115
endif()
113116

114-
115117
endif()
116118

117119
add_library(openjph ${SOURCES})
@@ -122,6 +124,9 @@ if (BUILD_SHARED_LIBS AND WIN32)
122124
endif()
123125

124126
## include library version/name
127+
if (NOT MSVC)
128+
target_compile_options(openjph PRIVATE -fPIC)
129+
endif()
125130
target_compile_definitions(openjph PUBLIC _FILE_OFFSET_BITS=64)
126131
target_include_directories(openjph PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common> $<INSTALL_INTERFACE:include/openjph>)
127132

src/core/codestream/ojph_codestream_avx.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
// Date: 15 May 2022
3636
//***************************************************************************/
3737

38+
#include "ojph_arch.h"
39+
#if defined(OJPH_ARCH_I386) || defined(OJPH_ARCH_X86_64)
3840
#include <immintrin.h>
3941
#include "ojph_defs.h"
4042

@@ -51,4 +53,6 @@ namespace ojph {
5153
}
5254

5355
}
54-
}
56+
}
57+
58+
#endif

src/core/codestream/ojph_codestream_avx2.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
// Date: 15 May 2022
3636
//***************************************************************************/
3737

38+
#include "ojph_arch.h"
39+
#if defined(OJPH_ARCH_I386) || defined(OJPH_ARCH_X86_64)
40+
3841
#include <climits>
3942
#include <immintrin.h>
4043
#include "ojph_defs.h"
@@ -271,3 +274,5 @@ namespace ojph {
271274
}
272275
}
273276
}
277+
278+
#endif

src/core/codestream/ojph_codestream_sse.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
// Date: 15 May 2022
3636
//***************************************************************************/
3737

38+
#include "ojph_arch.h"
39+
#if defined(OJPH_ARCH_I386) || defined(OJPH_ARCH_X86_64)
40+
3841
#include <immintrin.h>
3942
#include "ojph_defs.h"
4043

@@ -50,4 +53,6 @@ namespace ojph {
5053
_mm_storeu_ps(p, zero);
5154
}
5255
}
53-
}
56+
}
57+
58+
#endif

0 commit comments

Comments
 (0)