forked from KhronosGroup/KTX-Software
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1138 lines (1033 loc) · 38.2 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2015-2020 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.15)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/")
find_package(Bash REQUIRED)
include(cmake/version.cmake)
project(KTX-Software
VERSION ${KTX_VERSION}
DESCRIPTION "Libraries and tools to create and read KTX image texture files."
)
include(CTest)
include(GNUInstallDirs)
include(CMakeDependentOption)
include(cmake/codesign.cmake)
include(cmake/cputypetest.cmake)
find_package(OpenCL)
# OPTIONS
if( IOS OR EMSCRIPTEN )
set( LIB_TYPE_DEFAULT ON )
else()
set( LIB_TYPE_DEFAULT OFF )
endif()
CMAKE_DEPENDENT_OPTION( KTX_FEATURE_TOOLS
"Create KTX tools"
ON
"NOT IOS;NOT ANDROID;NOT EMSCRIPTEN"
OFF
)
option( KTX_FEATURE_DOC "Create KTX documentation" OFF )
option( KTX_FEATURE_LOADTEST_APPS "Create load tests apps that load and display various KTX textures" OFF )
option( KTX_FEATURE_STATIC_LIBRARY "Create static libraries (shared otherwise)" ${LIB_TYPE_DEFAULT} )
option( KTX_FEATURE_TESTS "Create unit tests" ON )
option( KTX_FEATURE_JNI "Create Java bindings for libktx" OFF )
if(POLICY CMP0127)
# cmake_dependent_option() supports full Condition Syntax. Introduced in
# 3.22. Not all build environments have 3.22+. Set policy to avoid warning.
# Seems the parens in the match string trigger the warning.
cmake_policy(SET CMP0127 NEW)
endif()
set_target_processor_type(CPU_ARCHITECTURE)
CMAKE_DEPENDENT_OPTION( BASISU_SUPPORT_SSE
"Compile with SSE support so applications can choose to use it."
ON
"NOT CMAKE_OSX_ARCHITECTURES STREQUAL \"$(ARCHS_STANDARD)\"; CPU_ARCHITECTURE STREQUAL x86_64 OR CPU_ARCHITECTURE STREQUAL x86"
OFF
)
CMAKE_DEPENDENT_OPTION( BASISU_SUPPORT_OPENCL
"Compile with OpenCL support so applications can choose to use it."
OFF
"OpenCL_FOUND OR WIN32"
OFF
)
if(BASISU_SUPPORT_OPENCL AND WIN32 AND NOT OpenCL_FOUND)
# To avoid fiddly setting up of OpenCL on Windows CI VMs, use copy in repo.
set(OpenCL_INCLUDE_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/lib/basisu/opencl"
# FORCE to override *-NOTFOUND set by the failed find.
CACHE PATH "" FORCE
)
set(OpenCL_LIBRARY
"${CMAKE_CURRENT_SOURCE_DIR}/lib/basisu/opencl/lib/OpenCL64.lib"
CACHE FILEPATH "" FORCE
)
set(OpenCL_INCLUDE_DIRS ${OpenCL_INCLUDE_DIR})
set(OpenCL_LIBRARIES ${OpenCL_LIBRARY})
endif()
CMAKE_DEPENDENT_OPTION( KTX_EMBED_BITCODE
"Embed bitcode in binaries"
OFF
"APPLE AND IOS"
OFF
)
option( KTX_FEATURE_KTX1 "Enable KTX 1 support" ON )
option( KTX_FEATURE_KTX2 "Enable KTX 2 support" ON )
option( KTX_FEATURE_VULKAN "Enable Vulkan texture upload" ON )
option( KTX_FEATURE_GL_UPLOAD "Enable OpenGL texture upload" ON )
# Platform specific settings
if(APPLE)
# Signing
set(XCODE_CODE_SIGN_IDENTITY "Development" CACHE STRING "Xcode code sign ID")
set(XCODE_DEVELOPMENT_TEAM "" CACHE STRING "Xcode development team ID")
set(PRODUCTBUILD_IDENTITY_NAME "" CACHE STRING "productbuild identity name")
set(PRODUCTBUILD_KEYCHAIN_PATH "" CACHE FILEPATH "pkgbuild keychain file")
if(IOS)
set(XCODE_PROVISIONING_PROFILE_SPECIFIER "" CACHE STRING "Xcode provisioning profile specifier")
set(MOLTENVK_SDK "$ENV{VULKAN_SDK}/../MoltenVK" CACHE STRING "MoltenVK directory inside the Vulkan SDK")
endif()
# Deployment
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "macOS Deployment Target")
if(IOS)
set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "11.0" CACHE STRING "iOS Deployment Target")
set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO)
endif()
endif()
if (WIN32)
# Signing
set(WIN_CODE_SIGN_IDENTITY "" CACHE STRING "Subject Name of Windows code signing certificate. Displayed in 'Issued To' field of cert{lm,mgr}.")
CMAKE_DEPENDENT_OPTION( WIN_CS_CERT_SEARCH_MACHINE_STORE
"When set, machine store will be searched for signing certificate instead of user store."
OFF
WIN_CODE_SIGN_IDENTITY
OFF
)
if (${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
# Disable OpenGL upload on Universal Windows Platform
set(KTX_FEATURE_GL_UPLOAD OFF)
endif()
endif()
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID)
set(LINUX TRUE)
endif()
if(EMSCRIPTEN)
set( KTX_FEATURE_VULKAN OFF )
endif()
set(bitness 64)
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8 OR FORCE32)
set(bitness 32)
endif()
if(KTX_FEATURE_STATIC_LIBRARY)
set(LIB_TYPE STATIC)
else()
if(IOS OR EMSCRIPTEN)
message(SEND_ERROR "Library type cannot be shared for the current platform. Set KTX_FEATURE_STATIC_LIBRARY to ON!")
endif()
set(LIB_TYPE SHARED)
endif()
# Depends on the settings, so it must be included after
include(cmake/mkvk.cmake)
# Global compile & link options including optimization flags
if(MSVC)
# With /W4 VS2015 (V19.0) issues many warnings that VS2017 & 2019 don't
# so only increase warning level for recent versions.
add_compile_options($<$<VERSION_GREATER_EQUAL:${CMAKE_CXX_COMPILER_VERSION},19.16>:/W4>)
add_compile_options( $<IF:$<CONFIG:Debug>,/Gz,/O2> )
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU"
OR ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_compile_options(-Wall -Wextra)
add_compile_options( $<IF:$<CONFIG:Debug>,-O0,-O3> )
if(EMSCRIPTEN)
add_link_options( $<IF:$<CONFIG:Debug>,-gsource-map,-O3> )
else()
add_link_options( $<IF:$<CONFIG:Debug>,-g,-O3> )
endif()
else()
message(ERROR "${CMAKE_CXX_COMPILER_ID} not yet supported.")
endif()
set(KTX_MAIN_SRC
include/ktx.h
lib/basis_sgd.h
lib/basis_transcode.cpp
lib/basisu/transcoder/basisu_containers.h
lib/basisu/transcoder/basisu_containers_impl.h
lib/basisu/transcoder/basisu_file_headers.h
lib/basisu/transcoder/basisu_transcoder_internal.h
lib/basisu/transcoder/basisu_transcoder_uastc.h
lib/basisu/transcoder/basisu_transcoder.cpp
lib/basisu/transcoder/basisu_transcoder.h
lib/basisu/transcoder/basisu.h
lib/basisu/zstd/zstd.c
lib/checkheader.c
lib/dfdutils/createdfd.c
lib/dfdutils/colourspaces.c
lib/dfdutils/dfd.h
lib/dfdutils/interpretdfd.c
lib/dfdutils/printdfd.c
lib/dfdutils/queries.c
lib/dfdutils/vk2dfd.c
lib/dfdutils/vk2dfd.inl
lib/dfdutils/vulkan/vk_platform.h
lib/dfdutils/vulkan/vulkan_core.h
lib/etcdec.cxx
lib/etcunpack.cxx
lib/filestream.c
lib/filestream.h
lib/formatsize.h
lib/gl_format.h
lib/hashlist.c
lib/info.c
lib/ktxint.h
lib/memstream.c
lib/memstream.h
lib/strings.c
lib/swap.c
lib/texture.c
lib/texture.h
lib/texture2.c
lib/texture2.h
lib/uthash.h
lib/vk_format.h
lib/vkformat_check.c
lib/vkformat_enum.h
lib/vkformat_str.c
)
if(KTX_FEATURE_GL_UPLOAD)
list(APPEND KTX_MAIN_SRC
lib/gl_funcs.c
lib/gl_funcs.h
lib/glloader.c
)
endif()
# Main library
add_library( ktx ${LIB_TYPE}
${KTX_MAIN_SRC}
)
# Read-only library
add_library( ktx_read ${LIB_TYPE}
${KTX_MAIN_SRC}
)
macro(commom_lib_settings lib write)
if(TARGET mkvk)
# Creating vulkan headers is only required when Vulkan SDK updates.
add_dependencies(${lib} mkvk)
endif()
set_target_properties(${lib} PROPERTIES
PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/include/ktx.h
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES"
)
if(IOS)
set_target_properties(${lib} PROPERTIES
FRAMEWORK TRUE
)
endif()
set_code_sign(${lib} "NOPPS")
target_compile_definitions(
${lib}
PUBLIC
"$<$<CONFIG:Debug>:_DEBUG;DEBUG>"
PRIVATE
LIBKTX
)
# C/C++ Standard
target_compile_features(${lib} PUBLIC c_std_99 cxx_std_11)
# Compiler Warning Flags
if(EMSCRIPTEN)
target_compile_options(${lib} PRIVATE
-Wno-nested-anon-types
-Wno-gnu-anonymous-struct
)
else()
target_compile_options(${lib} PRIVATE
# clang options
$<$<CXX_COMPILER_ID:AppleClang,Clang>:
-Wno-nested-anon-types
-Wno-gnu-anonymous-struct
>
$<$<CXX_COMPILER_ID:GNU>:
-Wno-cast-function-type
>
# not clang options
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:
-Wno-pedantic
>
)
endif()
target_include_directories(
${lib}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/basisu/transcoder>
$<INSTALL_INTERFACE:lib/basisu/transcoder>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/basisu/zstd>
$<INSTALL_INTERFACE:lib/basisu/zstd>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/other_include>
$<INSTALL_INTERFACE:other_include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/utils>
$<INSTALL_INTERFACE:utils>
)
if( LIB_TYPE STREQUAL STATIC )
# KHRONOS_STATIC overrides the value of KTX_API set below.
target_compile_definitions(${lib} PUBLIC KHRONOS_STATIC)
endif()
# To reduce size, don't support transcoding to ancient formats.
target_compile_definitions(${lib} PRIVATE BASISD_SUPPORT_FXT1=0)
# TODO: make options for all formats and good per-platform defaults
# - BASISD_SUPPORT_UASTC
# - BASISD_SUPPORT_DXT1 (BC1)
# - BASISD_SUPPORT_DXT5A (BC3/4/5)
# - BASISD_SUPPORT_BC7
# - BASISD_SUPPORT_BC7_MODE5
# - BASISD_SUPPORT_PVRTC1
# - BASISD_SUPPORT_ETC2_EAC_A8
# - BASISD_SUPPORT_ASTC
# - BASISD_SUPPORT_ATC
# - BASISD_SUPPORT_ASTC_HIGHER_OPAQUE_QUALITY
# - BASISD_SUPPORT_ETC2_EAC_RG11
# - BASISD_SUPPORT_FXT1
# - BASISD_SUPPORT_PVRTC2
if(WIN32)
target_compile_definitions(
${lib}
PRIVATE
# KHRONOS_STATIC defined earlier for the static library overrides
# so no need for a generator expression to conditionally set this.
KTX_API=__declspec\(dllexport\)
PUBLIC # only for basisu_c_binding.
BASISU_NO_ITERATOR_DEBUG_LEVEL
)
# The generator automatically sets the needed VCLinker
# option when a .def file is seen in sources.
# The def files that we add have a different syntax depending on the ABI
if(MINGW)
target_sources(
${lib}
PRIVATE
lib/internalexport_mingw.def
$<${write}:lib/internalexport_write_mingw.def>
)
# Need these flags if mingw happens to target the ucrt (new) rather
# than the legacy msvcrt. Otherwise tests will fail to run because
# the necessary dlls will be missing. If we statically link
# them instead it's fine. This does not cause any abberations if
# the mingw toolchain targets msvcrt instead.
target_link_options(${lib} PUBLIC -static-libgcc -static-libstdc++)
else()
target_sources(
${lib}
PRIVATE
lib/internalexport.def
$<${write}:lib/internalexport_write.def>
)
endif()
elseif(EMSCRIPTEN)
target_compile_definitions(${lib} PRIVATE
# To reduce size, don't support transcoding to formats not
# supported # by WebGL.
BASISD_SUPPORT_ATC=0
BASISD_SUPPORT_PVRTC2=0
# Don't support higher quality mode to avoid 64k table.
BASISD_SUPPORT_ASTC_HIGHER_OPAQUE_QUALITY=0
KTX_OMIT_VULKAN=1
)
endif()
if(KTX_FEATURE_KTX1)
target_compile_definitions(${lib} PUBLIC KTX_FEATURE_KTX1)
target_sources(
${lib}
PRIVATE
lib/texture1.c
lib/texture1.h
)
endif()
if(KTX_FEATURE_KTX2)
target_compile_definitions(${lib} PUBLIC KTX_FEATURE_KTX2)
endif()
if(WIN32)
# By wrapping in generator expression we force multi configuration
# generators (like Visual Studio) to take the exact path and not
# change it.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${KTX_BUILD_DIR}/$<CONFIG>>)
if(MINGW)
# Check if the Threads package is provided; if using Mingw it MIGHT be
find_package(Threads)
if(Threads_FOUND)
target_compile_definitions(ktx PRIVATE WIN32_HAS_PTHREADS)
target_link_libraries(ktx PRIVATE Threads::Threads)
endif()
endif()
elseif(APPLE)
if(KTX_EMBED_BITCODE)
target_compile_options(${lib} PRIVATE "-fembed-bitcode")
endif()
if(NOT IOS)
# Set a common RUNTIME_OUTPUT_DIR for all targets, so that
# INSTALL RPATH is functional in build directory as well.
# BUILD_WITH_INSTALL_RPATH is necessary for working code signing.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${KTX_BUILD_DIR}/$<CONFIG>)
endif()
elseif(LINUX)
find_package(Threads REQUIRED)
target_link_libraries(
${lib}
PUBLIC
dl
Threads::Threads
)
endif()
if(KTX_FEATURE_VULKAN)
target_sources(
${lib}
PRIVATE
include/ktxvulkan.h
lib/vk_funcs.c
lib/vk_funcs.h
lib/vkloader.c
)
target_include_directories(
${lib}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/dfdutils>
$<INSTALL_INTERFACE:lib/dfdutils>
)
get_target_property( KTX_PUBLIC_HEADER ${lib} PUBLIC_HEADER )
list(APPEND KTX_PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/include/ktxvulkan.h)
set_target_properties(${lib} PROPERTIES
PUBLIC_HEADER "${KTX_PUBLIC_HEADER}"
)
else()
target_compile_definitions( ${lib} PRIVATE KTX_OMIT_VULKAN=1 )
endif()
endmacro(commom_lib_settings)
set(KTX_BUILD_DIR "${CMAKE_BINARY_DIR}")
commom_lib_settings(ktx 1)
commom_lib_settings(ktx_read 0)
if(KTX_FEATURE_JNI)
add_subdirectory(interface/java_binding)
endif()
create_version_header(lib ktx)
create_version_file()
target_compile_definitions(
ktx_read
PRIVATE
# We're reading the files ourselves so don't need Basis KTX v2 support.
BASISD_SUPPORT_KTX2_ZSTD=0
BASISD_SUPPORT_KTX2=0
)
# Adding write capability to target ktx
set(BASISU_ENCODER_CXX_SRC
lib/basisu/encoder/basisu_backend.cpp
lib/basisu/encoder/basisu_backend.h
lib/basisu/encoder/basisu_basis_file.cpp
lib/basisu/encoder/basisu_basis_file.h
lib/basisu/encoder/basisu_bc7enc.cpp
lib/basisu/encoder/basisu_bc7enc.h
lib/basisu/encoder/basisu_comp.cpp
lib/basisu/encoder/basisu_comp.h
lib/basisu/encoder/basisu_enc.cpp
lib/basisu/encoder/basisu_enc.h
lib/basisu/encoder/basisu_etc.cpp
lib/basisu/encoder/basisu_etc.h
lib/basisu/encoder/basisu_frontend.cpp
lib/basisu/encoder/basisu_frontend.h
lib/basisu/encoder/basisu_gpu_texture.cpp
lib/basisu/encoder/basisu_gpu_texture.h
lib/basisu/encoder/basisu_kernels_declares.h
lib/basisu/encoder/basisu_kernels_imp.h
lib/basisu/encoder/basisu_kernels_sse.cpp
lib/basisu/encoder/basisu_miniz.h
lib/basisu/encoder/basisu_opencl.cpp
lib/basisu/encoder/basisu_opencl.h
lib/basisu/encoder/basisu_pvrtc1_4.cpp
lib/basisu/encoder/basisu_pvrtc1_4.h
lib/basisu/encoder/basisu_resample_filters.cpp
lib/basisu/encoder/basisu_resampler_filters.h
lib/basisu/encoder/basisu_resampler.cpp
lib/basisu/encoder/basisu_resampler.h
lib/basisu/encoder/basisu_ssim.cpp
lib/basisu/encoder/basisu_ssim.h
lib/basisu/encoder/basisu_uastc_enc.cpp
lib/basisu/encoder/basisu_uastc_enc.h
lib/basisu/encoder/cppspmd_flow.h
lib/basisu/encoder/cppspmd_math.h
lib/basisu/encoder/cppspmd_math_declares.h
lib/basisu/encoder/cppspmd_sse.h
lib/basisu/encoder/cppspmd_type_aliases.h
)
target_sources(
ktx
PRIVATE
lib/basis_encode.cpp
lib/astc_encode.cpp
${BASISU_ENCODER_C_SRC}
${BASISU_ENCODER_CXX_SRC}
lib/writer1.c
lib/writer2.c
)
# Turn off these warnings until Rich fixes the occurences.
# It it not clear to me if generator expressions can be used here
# hence the long-winded way.
#message(STATUS
# "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID} "
# "CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}"
#)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# Currently no need to disable any warnings in basisu code. Rich fixed them.
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set_source_files_properties(
# It's too much work to discriminate which files need which warnings
# disabled.
${BASISU_ENCODER_CXX_SRC}
PROPERTIES COMPILE_OPTIONS "-Wno-sign-compare;-Wno-unused-variable;-Wno-class-memaccess;-Wno-misleading-indentation;-Wno-extra;-Wno-deprecated-copy;-Wno-parentheses;-Wno-strict-aliasing"
)
set_source_files_properties(
lib/basisu/transcoder/basisu_transcoder.cpp
PROPERTIES COMPILE_OPTIONS "-Wno-sign-compare;-Wno-unused-function;-Wno-unused-variable;-Wno-class-memaccess;-Wno-maybe-uninitialized"
)
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.0")
set_source_files_properties(
lib/basisu/zstd/zstd.c
PROPERTIES COMPILE_OPTIONS "-Wno-unused-but-set-variable"
)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# Versions equivalency from https://en.wikipedia.org/wiki/Xcode#Xcode_11.x_-_14.x_(since_SwiftUI_framework)_2
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "14")
set( clang_version ${CMAKE_CXX_COMPILER_VERSION})
elseif (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "13.1.0")
set( clang_version "13.0.0")
elseif (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "13.0.0")
set( clang_version "12.0.0")
elseif (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "12.0.5")
set( clang_version "11.1.0")
elseif (${CMAKE_CXX_COMPILER_VERSION} VERSION_EQUAL "12.0.0")
set( clang_version "10.0.0")
else()
message(FATAL "Unsupported AppleClang version")
endif()
else()
set( clang_version ${CMAKE_CXX_COMPILER_VERSION} )
endif()
if (${clang_version} VERSION_GREATER_EQUAL "12.0.0")
set_source_files_properties( lib/basisu/encoder/basisu_kernels_sse.cpp
PROPERTIES COMPILE_OPTIONS "-Wno-unused-parameter;-Wno-deprecated-copy;-Wno-uninitialized-const-reference"
)
# Primarily an issue on windows using clang/clangcl
# Lowest tested clang version was 12.0.0 and highest was 14.0.4
set_source_files_properties(
lib/basisu/zstd/zstd.c
PROPERTIES COMPILE_OPTIONS "-Wno-unused-function"
)
else()
set_source_files_properties( lib/basisu/encoder/basisu_kernels_sse.cpp
PROPERTIES COMPILE_OPTIONS "-Wno-unused-parameter"
)
endif()
if (${clang_version} VERSION_GREATER_EQUAL "13.0.0")
get_source_file_property(zstd_options lib/basisu/zstd/zstd.c COMPILE_OPTIONS)
set_source_files_properties(
# We haven't fixed zstd.c because the fix would have to be applied
# every time the upstream script is used to create an updated
# single file decoder.
lib/basisu/zstd/zstd.c
PROPERTIES COMPILE_OPTIONS "${zstd_options};-Wno-unused-but-set-variable"
)
endif()
if (${clang_version} VERSION_GREATER_EQUAL "15.0")
# These are for Emscripten which is ahead of xcode in its clang
# version. Also future proofing for when xcode catches up.
set_source_files_properties(
${BASISU_ENCODER_CXX_SRC}
PROPERTIES COMPILE_OPTIONS "-Wno-sign-compare;-Wno-unused-variable;-Wno-unused-parameter"
)
set_source_files_properties(
lib/basisu/transcoder/basisu_transcoder.cpp
PROPERTIES COMPILE_OPTIONS "-Wno-sign-compare;-Wno-unused-function;-Wno-unused-variable"
)
set_source_files_properties(
lib/basisu/zstd/zstd.c
PROPERTIES COMPILE_OPTIONS "-Wno-unused-but-set-variable;-Wno-bitwise-instead-of-logical"
)
endif()
else()
message(ERROR "${CMAKE_CXX_COMPILER_ID} not yet supported.")
endif()
target_include_directories(
ktx
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib/basisu>
$<INSTALL_INTERFACE:lib/basisu>
$<$<BOOL:${BASISU_SUPPORT_OPENCL}>:${OpenCL_INCLUDE_DIRS}>
)
target_compile_definitions(
ktx
PUBLIC
KTX_FEATURE_WRITE
PRIVATE
# BASISD_SUPPORT_KTX2 has to be 1 to compile the encoder. We
# don't use it. Hopefully it doesn't add too much code. We're using
# the zstd encoder in basisu by explicitly including the file in our
# source list. We don't need the related code in the encoder.
BASISD_SUPPORT_KTX2_ZSTD=0
BASISD_SUPPORT_KTX2=1
$<$<BOOL:${BASISU_SUPPORT_SSE}>:BASISU_SUPPORT_SSE=1>
$<$<NOT:$<BOOL:${BASISU_SUPPORT_SSE}>>:BASISU_SUPPORT_SSE=0>
$<$<BOOL:${BASISU_SUPPORT_OPENCL}>:BASISU_SUPPORT_OPENCL=1>
$<$<NOT:$<BOOL:${BASISU_SUPPORT_OPENCL}>>:BASISU_SUPPORT_OPENCL=0>
)
target_compile_options(
ktx
PRIVATE
$<$<AND:$<BOOL:${BASISU_SUPPORT_SSE}>,$<CXX_COMPILER_ID:AppleClang,Clang,GNU>>:
-msse4.1
>
)
target_link_libraries(
ktx
PRIVATE
$<$<BOOL:${BASISU_SUPPORT_OPENCL}>:${OpenCL_LIBRARIES}>
)
if(EMSCRIPTEN)
set(
KTX_EMC_LINK_FLAGS
--bind
"SHELL:--source-map-base ./"
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s ASSERTIONS=0"
"SHELL:-s MALLOC=emmalloc"
"SHELL:-s MODULARIZE=1"
"SHELL:-s FULL_ES3=1"
)
add_executable( ktx_js interface/js_binding/ktx_wrapper.cpp )
target_link_libraries( ktx_js ktx_read )
target_include_directories( ktx_js PRIVATE $<TARGET_PROPERTY:ktx_read,INTERFACE_INCLUDE_DIRECTORIES> )
target_link_options(
ktx_js
PUBLIC
${KTX_EMC_LINK_FLAGS}
"SHELL:-s EXPORT_NAME=LIBKTX"
"SHELL:-s EXPORTED_RUNTIME_METHODS=[\'GL\']"
"SHELL:-s GL_PREINITIALIZED_CONTEXT=1"
)
set_target_properties( ktx_js PROPERTIES OUTPUT_NAME "libktx")
add_custom_command(
TARGET ktx_js
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:ktx_js>/$<TARGET_FILE_PREFIX:ktx_js>$<TARGET_FILE_BASE_NAME:ktx_js>.js" "${PROJECT_SOURCE_DIR}/tests/webgl"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:ktx_js>/$<TARGET_FILE_PREFIX:ktx_js>$<TARGET_FILE_BASE_NAME:ktx_js>.wasm" "${PROJECT_SOURCE_DIR}/tests/webgl"
COMMENT "Copy libktx.js and libktx.wasm to tests/webgl"
)
install(TARGETS ktx_js
RUNTIME
DESTINATION .
COMPONENT ktx_js
)
install(FILES ${CMAKE_BINARY_DIR}/libktx.wasm
DESTINATION .
COMPONENT ktx_js
)
add_executable( msc_basis_transcoder_js interface/js_binding/transcoder_wrapper.cpp )
target_link_libraries( msc_basis_transcoder_js ktx_read )
target_include_directories( msc_basis_transcoder_js
PRIVATE
lib
lib/basisu/transcoder
)
# Re-use ktx's compile options
target_compile_options(msc_basis_transcoder_js
PRIVATE
$<TARGET_PROPERTY:ktx_read,INTERFACE_COMPILE_OPTIONS>
)
target_link_options(
msc_basis_transcoder_js
PUBLIC
${KTX_EMC_LINK_FLAGS}
"SHELL:-s EXPORT_NAME=MSC_TRANSCODER"
# Re-use ktx's link options
$<TARGET_PROPERTY:ktx_read,INTERFACE_LINK_OPTIONS>
)
set_target_properties( msc_basis_transcoder_js PROPERTIES OUTPUT_NAME "msc_basis_transcoder")
add_custom_command(
TARGET ktx_js
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:msc_basis_transcoder_js>/$<TARGET_FILE_PREFIX:msc_basis_transcoder_js>$<TARGET_FILE_BASE_NAME:msc_basis_transcoder_js>.js" "${PROJECT_SOURCE_DIR}/tests/webgl"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE_DIR:msc_basis_transcoder_js>/$<TARGET_FILE_PREFIX:msc_basis_transcoder_js>$<TARGET_FILE_BASE_NAME:msc_basis_transcoder_js>.wasm" "${PROJECT_SOURCE_DIR}/tests/webgl"
COMMENT "Copy msc_basis_transcoder.js and msc_basis_transcoder.wasm to tests/webgl"
)
install(TARGETS msc_basis_transcoder_js
RUNTIME
DESTINATION .
COMPONENT msc_basis_transcoder_js
)
install(FILES ${CMAKE_BINARY_DIR}/msc_basis_transcoder.wasm
DESTINATION .
COMPONENT msc_basis_transcoder_js
)
endif()
add_library( objUtil STATIC
utils/argparser.cpp
utils/argparser.h
utils/ktxapp.h
utils/sbufstream.h
utils/scapp.h
utils/stdafx.h
utils/unused.h
)
target_include_directories(
objUtil
PUBLIC
utils
)
# In C++ apps that use statically linked Libraries all compilatiom units must
# be compiled with matching symbol visibility settings to avoid warnings from
# clang. Many 3rd party libraries, including libassimp which is used by the
# load test apps that statically link also to several internal libraries, use
# "hidden" to avoid conflicts with other libraries.
#
# TODO: set "hidden" as a global option. I do not want to take the time right
# now to deal with the fallout from hiding globals in libktx. Apart from
# having to mark all the public symbols of libktx for clang and gcc with
# __attribute__((visibility("default"))) there will be ramifications to
# texturetests and unittests. Marking the public symbols is easy for those
# already tagged with KTX_API. But all the symbols exported via
# internalexport.def and internalexport_write.def have to be tagged with
# KTX_API which may also require additional inclusion of ktx.h to get the
# definition.
set (STATIC_APP_LIB_SYMBOL_VISIBILITY hidden)
set_target_properties(objUtil PROPERTIES
CXX_VISIBILITY_PRESET ${STATIC_APP_LIB_SYMBOL_VISIBILITY}
)
if(KTX_FEATURE_STATIC_LIBRARY AND
(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set_source_files_properties(
lib/astc_encode.cpp
PROPERTIES COMPILE_OPTIONS "-fvisibility=hidden"
)
endif()
add_subdirectory(interface/basisu_c_binding)
# Only one architecture is supported at once, if neither of
# ISA_SSE41 and ISA_SSE2 are defined ISA_AVX2 is chosen.
# If ISA_AVX2 fails to compile user must chose other x86 options.
# On arm based systems ISA_NEON is default
list(FIND CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)" ASTC_BUILD_UNIVERSAL)
list(LENGTH CMAKE_OSX_ARCHITECTURES ARCHITECTURE_COUNT)
if(${ASTC_BUILD_UNIVERSAL} EQUAL -1 AND ARCHITECTURE_COUNT LESS_EQUAL 1)
if (${ISA_NONE})
set(ASTC_LIB_TARGET astcenc-none-static)
else()
if(CPU_ARCHITECTURE STREQUAL x86_64 OR CPU_ARCHITECTURE STREQUAL x86)
if (${ISA_SSE41})
set(ASTC_LIB_TARGET astcenc-sse4.1-static)
elseif (${ISA_SSE2})
set(ASTC_LIB_TARGET astcenc-sse2-static)
else()
set(ISA_AVX2 ON)
set(ASTC_LIB_TARGET astcenc-avx2-static)
endif()
if(CPU_ARCHITECTURE STREQUAL x86)
set(ISA_NONE ON)
set(ISA_AVX2 OFF)
set(ASTCENC_POPCNT 0)
set(ASTC_LIB_TARGET astcenc-none-static)
endif()
elseif(CPU_ARCHITECTURE STREQUAL armv8 OR CPU_ARCHITECTURE STREQUAL arm64)
set(ASTC_LIB_TARGET astcenc-neon-static)
set(ISA_NEON ON)
else()
message(STATUS "Unsupported ISA for ${CPU_ARCHITECTURE} arch, using ISA_NONE.")
set(ASTC_LIB_TARGET astcenc-none-static)
set(ISA_NONE ON)
endif()
endif()
else()
set(ASTC_LIB_TARGET astcenc-static)
endif()
# astcenc
set(CLI OFF) # Only build as library not the CLI astcencoder
add_subdirectory(lib/astc-encoder)
set_property(TARGET ${ASTC_LIB_TARGET} PROPERTY POSITION_INDEPENDENT_CODE ON)
if(KTX_FEATURE_STATIC_LIBRARY AND NOT WIN32 AND NOT EMSCRIPTEN)
# Make a single static library to simplify linking.
add_dependencies(ktx ${ASTC_LIB_TARGET})
set(LIBTOOL_ARGS)
if(LINUX)
set(LIBTOOL_ARGS ${LIBTOOL_ARGS} --mode=link --tag=CC cc)
endif()
set(LIBTOOL_ARGS ${LIBTOOL_ARGS} -static -o
$<TARGET_FILE:ktx> $<TARGET_FILE:ktx> $<TARGET_FILE:${ASTC_LIB_TARGET}>)
add_custom_command( TARGET ktx
POST_BUILD
COMMAND libtool ${LIBTOOL_ARGS}
)
# Don't know libtool equivalent on Windows or Emscripten. Applications
# will have to link with both ktx and ${ASTC_LIB_TARGET}. Static libs
# are unlikely to be used on Windows so not a problem there. For Emscripten
# everything is built into the JS module so not an issue there either.
else()
target_link_libraries(ktx PRIVATE ${ASTC_LIB_TARGET})
endif()
# Tools
if(KTX_FEATURE_TOOLS)
add_subdirectory(tools)
endif()
# Tests
add_subdirectory(tests)
# Documentation
if(KTX_FEATURE_DOC)
include(cmake/docs.cmake)
endif()
set(KTX_INSTALL_TARGETS ktx)
if(KTX_FEATURE_STATIC_LIBRARY AND (WIN32 OR EMSCRIPTEN))
list(APPEND KTX_INSTALL_TARGETS ${ASTC_LIB_TARGET})
endif()
# Install
if(APPLE OR LINUX)
# Have library's name links as separate component
set(KTX_NAMELINKS ON)
install(TARGETS ${KTX_INSTALL_TARGETS}
EXPORT KTXTargets
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
FRAMEWORK
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
NAMELINK_SKIP
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT dev
)
install(TARGETS ${KTX_INSTALL_TARGETS}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
NAMELINK_ONLY
)
else()
# No name links on Windows
set(KTX_NAMELINKS OFF)
install(TARGETS ${KTX_INSTALL_TARGETS}
EXPORT KTXTargets
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT dev
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT library
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT dev
)
endif()
install(EXPORT KTXTargets
FILE KtxTargets.cmake
NAMESPACE KTX::
DESTINATION lib/cmake/ktx
COMPONENT library
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"KtxConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)
install( FILES
"cmake/KtxConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/KtxConfigVersion.cmake"
DESTINATION lib/cmake/ktx
COMPONENT library
)
# CPack
include(CPackComponent)
set(CPACK_PACKAGE_NAME "KTX-Software")
set(CPACK_PACKAGE_VENDOR "Khronos Group")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.khronos.org/KTX-Software")
set(CPACK_PACKAGE_CONTACT "[email protected]" )
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Welcome.rtf")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/cmake/ReadMe.rtf")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/License.rtf")
# Custom package file name
# This does not use the ${CPU_ARCHITECTURE} set earlier because the hope is
# that the BasisU SIMD code will be changed to no longer need compile time
# definitions and we can remove the complex cputypetest.cmake.
if( APPLE AND CMAKE_OSX_ARCHITECTURES )
# CMAKE_SYSTEM_PROCESSOR typically set to build host processor here.
# CMAKE_OSX_ARCHITECTURES governs target of build.
list(LENGTH CMAKE_OSX_ARCHITECTURES archs_len)
list(GET CMAKE_OSX_ARCHITECTURES 0 arch0)
# Cannot use CMAKE_OSX_ARCHITECTURES instead of arch0 due to if() being
# confused by potentially multiple architectures between OR and STREQUAL.
# It's okay in the else() clause but as we've already set arch0...
if( ${archs_len} GREATER 1 OR ${arch0} STREQUAL "$(ARCHS_STANDARD)" )
set(processor_name "universal")
else()
set(processor_name ${arch0})
endif()
elseif(CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
# When targeting Windows arm64 CMAKE_SYSTEM_PROCESSOR will incorrectly
# return AMD64.
# See: https://gitlab.kitware.com/cmake/cmake/-/issues/15170
# We assume that when building for Windows arm64 that we are using MSVC
# so we can detect the processor arch name with CMAKE_CXX_COMPILER_ARCHITECTURE_ID
set(processor_name ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})
elseif( CMAKE_SYSTEM_PROCESSOR )
set(processor_name ${CMAKE_SYSTEM_PROCESSOR})
elseif( IOS )
# CMAKE_SYSTEM_PROCESSOR not set when building for iOS.
set(processor_name "arm64")
endif()
string(TOLOWER "${processor_name}" processor_name)
#message(STATUS "processor_name is ${processor_name}, CPU_ARCHITECTURE is ${CPU_ARCHITECTURE}")
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${KTX_VERSION_FULL}-${CMAKE_SYSTEM_NAME}-${processor_name}")
if(APPLE)
if(NOT IOS)
install(FILES tools/package/mac/ktx-uninstall
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
COMPONENT tools
)
set(CPACK_GENERATOR productbuild)
# Trick the productbuild generator into creating more useful package IDs
set(CPACK_PACKAGE_NAME "ktx")
set(CPACK_PACKAGE_VENDOR "khronos")