-
Notifications
You must be signed in to change notification settings - Fork 15
/
CMakeLists.txt
2391 lines (1949 loc) · 88.8 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
#=============================================================================
# CMake build system files
#
# Copyright (c) 2014-2023 pocl developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#=============================================================================
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
cmake_policy(SET CMP0067 OLD)
project(pocl)
set(CMAKE_PROJECT_DESCRIPTION "pocl is a portable OpenCl runtime.")
MESSAGE(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
MESSAGE(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
MESSAGE(STATUS "CMAKE_LIBRARY_ARCHITECTURE: ${CMAKE_LIBRARY_ARCHITECTURE}")
set(LATEST_KNOWN_CXX_STD_VERSION "20")
set(SUPPORTED_CXX_STD_VERSION "11")
option(ENABLE_LATEST_CXX_STD "Upgrade C++ standard version to ${LATEST_KNOWN_CXX_STD_VERSION}. Required to get rid of unused variables warnings in compilers not supporting [[gnu::*]] attributes. Can bring other benefits, including performance and efficiency ones. Before a pull request build with this disabled." OFF)
if(ENABLE_LATEST_CXX_STD)
set(CMAKE_CXX_STANDARD "${LATEST_KNOWN_CXX_STD_VERSION}")
else()
set(CMAKE_CXX_STANDARD "${SUPPORTED_CXX_STD_VERSION}")
endif()
set(POCL_CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# if variable FEATURE_X isn't defined, sets it to DEFAULT_FEATURE_X;
# also, if DEFAULT_FEATURE_X is 0, prevents FEATURE_X being 1
# since it takes DEFAULT_FEATURE_X=0 to mean "FEATURE_X is unavailable"
macro(setup_cached_var VARNAME DESCRIPTION DOCS_FEATURE_IS_UNAVAILABLE DOCS_REQUESTED_DISABLING_FEATURE)
if(DEFINED ${VARNAME})
set(_CACHED "(cached)")
else()
set(_CACHED "")
set(${VARNAME} ${DEFAULT_${VARNAME}})
endif()
if(${VARNAME} AND (NOT ${DEFAULT_${VARNAME}}))
message(WARNING "${DOCS_FEATURE_IS_UNAVAILABLE}")
set(${VARNAME} 0)
set(_CACHED "(override)")
endif()
if((NOT ${VARNAME}) AND ${DEFAULT_${VARNAME}} )
message(STATUS "${DOCS_REQUESTED_DISABLING_FEATURE}")
endif()
if(${VARNAME})
message(STATUS "${DESCRIPTION} ${_CACHED}: 1")
else()
message(STATUS "${DESCRIPTION} ${_CACHED}: 0")
endif()
endmacro()
include(CheckCCompilerFlag)
include(CPackComponent)
macro(pass_through_cpack_vars)
get_cmake_property(cpackVarsToPassthrough VARIABLES)
foreach(varName ${cpackVarsToPassthrough})
if(varName MATCHES "^CPACK_DEBIAN_")
message(STATUS "${varName}")
set("${varName}" "${${varName}}" PARENT_SCOPE)
endif()
endforeach()
endmacro()
# don't allow implicit function declarations
if(UNIX)
if((CMAKE_C_COMPILER_ID STREQUAL "GNU") OR
(CMAKE_C_COMPILER_ID STREQUAL "Clang"))
check_c_compiler_flag("-Wincompatible-pointer-types" HAVE_WARN_INCOMPATIBLE_POINTER_TYPES)
set(FORBID_IMPLICIT_FUNCTIONS "-Werror=implicit-function-declaration")
if (HAVE_WARN_INCOMPATIBLE_POINTER_TYPES)
set(FORBID_IMPLICIT_FUNCTIONS ${FORBID_IMPLICIT_FUNCTIONS} "-Werror=incompatible-pointer-types")
endif()
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${FORBID_IMPLICIT_FUNCTIONS}>")
add_compile_options("-Wno-ignored-attributes")
else()
message(WARNING "Don't know how to forbid this compiler from allowing implicit function declarations.")
endif()
endif()
set(MAJOR_VERSION 6)
set(MINOR_VERSION 1)
set(VERSION_SUFFIX_FIXED_TEXT "-pre")
set(VERSION_SUFFIX "${VERSION_SUFFIX_FIXED_TEXT}")
set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}${VERSION_SUFFIX})
set(POCL_VERSION_BASE ${VERSION_STRING})
# required b/c SHARED libs defaults to ON while OBJECT defaults to OFF
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# CMake doesn't add "-pie" by default for executables (CMake issue #14983)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
enable_testing()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#####################################################
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(DEFAULT_BUILD_TYPE "Debug")
else()
set(DEFAULT_BUILD_TYPE "RelWithDebInfo")
endif()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(LLVM_VERIFY_MODULE_DEFAULT 1)
else()
set(LLVM_VERIFY_MODULE_DEFAULT 0)
endif()
##################################################################################
macro(set_expr VAR)
if(${ARGN})
set(${VAR} 1)
else()
set(${VAR} 0)
endif()
endmacro()
find_program(BASH "bash")
find_program(MAKE_PROGRAM NAMES "make")
find_program(GIT_CMD "git")
set_expr(HAVE_GIT GIT_CMD)
if(HAVE_GIT)
execute_process(COMMAND "${GIT_CMD}" "rev-parse" "HEAD"
OUTPUT_VARIABLE GIT_COMMIT
RESULT_VARIABLE EXITCODE
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if(HAVE_GIT AND (VERSION_SUFFIX MATCHES "pre") AND (EXITCODE EQUAL 0))
message(STATUS "Pocl source Git commit: ${GIT_COMMIT}")
execute_process(COMMAND "${GIT_CMD}" "branch" "--contains" "${GIT_COMMIT}"
OUTPUT_VARIABLE GIT_BRANCH
RESULT_VARIABLE EXITCODE
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Pocl source Git branch: ${GIT_BRANCH}")
execute_process(COMMAND "${GIT_CMD}" describe "--always" "--long" "--all" "${GIT_COMMIT}"
OUTPUT_VARIABLE GIT_DESCRIBE
RESULT_VARIABLE EXITCODE
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "heads/" "" GIT_DESCRIBE "${GIT_DESCRIBE}")
message(STATUS "Pocl source Git describe: ${GIT_DESCRIBE}")
set(VERSION_SUFFIX "${VERSION_SUFFIX_FIXED_TEXT} ${GIT_DESCRIBE}")
set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}${VERSION_SUFFIX})
set(POCL_VERSION_FULL "${VERSION_STRING}")
else()
message(STATUS "No git and/or not a prerelease -> not adding git commit to version.")
set(POCL_VERSION_FULL "${POCL_VERSION_BASE}")
endif()
set(CPACK_PACKAGE_NAME pocl)
set(CPACK_PACKAGE_VENDOR pocl)
set(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}")
set(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}")
set(CPACK_PACKAGE_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}~${VERSION_SUFFIX_FIXED_TEXT}")
if(HAVE_GIT)
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}.${GIT_COMMIT}")
endif()
##################################################################################
option(ENABLE_LLVM "Build pocl with LLVM. Default is ON." ON)
option(STATIC_LLVM "If ON, link to static LLVM libraries. OFF (default) = link to shared LLVM libraries." OFF)
option(BUILD_SHARED_LIBS "ON=Build shared libs, OFF=static libs" ON)
option(POCL_DEBUG_MESSAGES
"Enable debug messages from pocl (useful for OpenCL developers), must be enabled at runtime, with env var POCL_DEBUG"
ON)
option(ENABLE_LOADABLE_DRIVERS "Enable drivers to be dlopen()-ed at pocl runtime, instead of being linked into libpocl" ON)
option(ENABLE_HSA "Enable the HSA base profile runtime device driver" OFF)
option(ENABLE_CUDA "Enable the CUDA device driver for NVIDIA devices" OFF)
option(ENABLE_CUDNN "Enable the CUDNN for the CUDA device driver, requires CUDA" OFF)
option(ENABLE_VULKAN "Experimental and incomplete driver that uses the Vulkan API for controlling the device. Please refer to the user manual for the status and open tasks" OFF)
option(ENABLE_LEVEL0 "Experimental and incomplete driver that uses the Level Zero API for controlling the device. Please refer to the user manual for the status and open tasks" OFF)
option(ENABLE_TBB_DEVICE "Enable the Intel TBB device driver." OFF)
option(ENABLE_HOST_CPU_DEVICES "Add host CPUs as OpenCL devices (cpu & cpu-minimal)." ON)
option(ENABLE_HOST_CPU_DEVICES_OPENMP "Enables OpenMP support for Host CPU devices (cpu driver only, cpu-minimal driver remains single-threaded)" OFF)
option(ENABLE_PROXY_DEVICE "Enable proxy driver for proxying to another OpenCL implementation" OFF)
option(ENABLE_PROXY_DEVICE_INTEROP "Enable OpenGL- or EGL-interop with the proxy driver" OFF)
option(ENABLE_ALMAIF_DEVICE "Enable the generic hardware accelerator device driver." OFF)
option(KERNEL_CACHE_DEFAULT "Default value for the kernel compile cache. If disabled, pocl will still use kernel cache for intermediate compilation files, but will clean up them on exit. You can still enable keeping the files it at runtime with an env var." ON)
option(ENABLE_REMOTE_SERVER "Build the 'pocld' server daemon for the remote driver" OFF)
option(ENABLE_REMOTE_CLIENT "Build the client library of the remote driver" OFF)
option(POCL_ICD_ABSOLUTE_PATH "Use absolute path in pocl.icd" ON)
option(ENABLE_POCL_BUILDING "When OFF, env var POCL_BUILDING has no effect. Defaults to ON" ON)
option(ENABLE_PRINTF_IMMEDIATE_FLUSH "[currently only applies to CPU drivers] if enabled, printf is flushed immediately when encountered, instead of after all NDRange workgroups are finished" ON)
option(ENABLE_VSOCK "Enable vsock transport in the remote driver" OFF)
if (ENABLE_PROXY_DEVICE)
set(VISIBILITY_HIDDEN_DEFAULT OFF)
else()
set(VISIBILITY_HIDDEN_DEFAULT ON)
endif()
option(VISIBILITY_HIDDEN "Build with -fvisibility=hidden -fvisibility-inlines-hidden" ${VISIBILITY_HIDDEN_DEFAULT})
if(VISIBILITY_HIDDEN)
add_compile_options(-fvisibility=hidden)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fvisibility-inlines-hidden>)
endif()
# Ninja Job Pool support
set(PARALLEL_COMPILE_JOBS "" CACHE STRING
"Define the maximum number of concurrent compilation jobs (Ninja only).")
if(PARALLEL_COMPILE_JOBS)
if(CMAKE_GENERATOR STREQUAL "Ninja")
set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${PARALLEL_COMPILE_JOBS})
set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
endif()
endif()
set(PARALLEL_LINK_JOBS "" CACHE STRING
"Define the maximum number of concurrent link jobs (Ninja only).")
if(CMAKE_GENERATOR STREQUAL "Ninja")
if(PARALLEL_LINK_JOBS)
set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${PARALLEL_LINK_JOBS})
set(CMAKE_JOB_POOL_LINK link_job_pool)
endif()
endif()
if(NOT CMAKE_GENERATOR STREQUAL "Ninja" AND (PARALLEL_COMPILE_JOBS OR PARALLEL_LINK_JOBS))
message(WARNING "Job pooling is only available with Ninja generators.")
endif()
#### these are mostly useful for pocl developers
option(ENABLE_EXTRA_VALIDITY_CHECKS "Enable extra checks on cl_* object validity" OFF)
option(DEVELOPER_MODE "This will SIGNIFICANTLY reduce PoCL's performance, but speeds up its compilation for faster development-test cycles. Only turn on if you know what you're doing." OFF)
option(USE_POCL_MEMMANAGER "Enables custom memory manager. Except for special circumstances, this should be disabled." OFF)
option(EXAMPLES_USE_GIT_MASTER "If enabled, some of the external testsuites in examples/ will try to use sources from Git master, instead of releases. This may result in failure to build or run the examples" OFF)
option(ENABLE_POCLCC "Build poclcc. Defaults to ON" ON)
option(ENABLE_TESTS "Build tests. Defaults to ON" ON)
option(ENABLE_EXAMPLES "Build examples. Defaults to ON" ON)
option(ENABLE_RDMA "Enable usage of RDMA libraries for memory allocations. Requires libRDMAcm and libverbs" OFF)
option(ENABLE_TRAFFIC_MONITOR "Enable network traffic monitoring & logging in remote device" OFF)
OPTION(RENAME_POCL "rename PoCL's ocl functions to PO<ocl_function>. Allows an user to call both PoCL and another ocl application" OFF)
##########################################################
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(HOST_DEVICE_ADDRESS_BITS 64)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(HOST_DEVICE_ADDRESS_BITS 32)
else()
message(FATAL_ERROR "Cannot figure out HOST_DEVICE_ADDRESS_BITS")
endif()
# printf buffer size, in KB
if(NOT DEFINED PRINTF_BUFFER_SIZE)
set(PRINTF_BUFFER_SIZE 16384 CACHE STRING "printf buffer size, in KB")
endif()
##################################################################################
if(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
set(POWERPC 1)
set(POWERPC64LE 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc")
set(POWERPC 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips")
set(MIPS 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm|aarch64)")
set(ARM 1)
if(HOST_DEVICE_ADDRESS_BITS MATCHES "32")
set(ARM32 1)
else()
set(ARM64 1)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(i.86|AMD64|x86_64|amd64)")
set(X86 1)
if(HOST_DEVICE_ADDRESS_BITS MATCHES "32")
set(I386 1)
else()
set(X86_64 1)
endif()
endif()
include(ProcessorCount)
ProcessorCount(HOST_CPU_CORECOUNT)
if(HOST_CPU_CORECOUNT LESS 1)
set(HOST_CPU_CORECOUNT 1)
endif()
message(STATUS "Host CPU cores: ${HOST_CPU_CORECOUNT}")
######################################################################################
function(chmod FILE EXEC)
if(EXEC)
set(PERMS FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
else()
#set(PERMS FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
return()
endif()
if(CMAKE_VERSION VERSION_LESS 3.19.0)
find_program(CHMOD_PROG chmod)
execute_process(COMMAND "${CHMOD_PROG}" "0755" ${FILE})
else()
file(CHMOD "${FILE}" ${PERMS})
endif()
endfunction()
function(rename_if_different SRC DST EXEC)
if(EXISTS "${DST}")
file(MD5 "${SRC}" OLD_MD5)
file(MD5 "${DST}" NEW_MD5)
if(NOT OLD_MD5 STREQUAL NEW_MD5)
file(RENAME "${SRC}" "${DST}")
chmod("${DST}" ${EXEC})
endif()
else()
file(RENAME "${SRC}" "${DST}")
chmod("${DST}" ${EXEC})
endif()
endfunction()
######################################################################################
# Recent versions of CMake can make use of Ninja's console pool to avoid
# buffering the output of particular commands.
set(COMMAND_USES_TERMINAL USES_TERMINAL)
include(GNUInstallDirs)
# for libpocl.so
set(POCL_INSTALL_PUBLIC_LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}" CACHE PATH "POCL public libdir")
# for libpocl-devices-*.so
set(POCL_INSTALL_PRIVATE_LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}/pocl" CACHE PATH "POCL private libdir")
# for pocl.icd
set(POCL_INSTALL_ICD_VENDORDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/OpenCL/vendors" CACHE PATH "POCL ICD file destination")
# for kernel-<target>.bc
set(POCL_INSTALL_PRIVATE_DATADIR "${CMAKE_INSTALL_FULL_DATADIR}/pocl" CACHE PATH "POCL private datadir")
# for poclu.h
set(POCL_INSTALL_PUBLIC_HEADER_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}" CACHE PATH "POCL public header dir")
# for _kernel.h et al
set(POCL_INSTALL_PRIVATE_HEADER_DIR "${POCL_INSTALL_PRIVATE_DATADIR}/include" CACHE PATH "POCL private header dir")
# for pocl-standalone et al
set(POCL_INSTALL_PUBLIC_BINDIR "${CMAKE_INSTALL_FULL_BINDIR}" CACHE PATH "POCL public bindir")
# for PoclConfig.cmake & stuff
set(POCL_INSTALL_CMAKE_CONFIG_DIR "${POCL_INSTALL_PRIVATE_LIBDIR}/cmake" CACHE PATH "Installation directory for CMake files")
# TODO maybe use output of pkg-config --variable=pc_path pkg-config ?
set(POCL_INSTALL_PKGCONFIG_DIR "${POCL_INSTALL_PUBLIC_LIBDIR}/pkgconfig" CACHE PATH "Destination for pocl.pc")
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(POCL_INSTALL_OPENCL_HEADER_DIR "${POCL_INSTALL_PUBLIC_HEADER_DIR}/OpenCL" CACHE PATH "POCL header dir for OpenCL headers")
else()
set(POCL_INSTALL_OPENCL_HEADER_DIR "${POCL_INSTALL_PUBLIC_HEADER_DIR}/CL" CACHE PATH "POCL header dir for OpenCL headers")
endif()
######################################################################################
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
option(HARDENING_ENABLE "Enable hardening against various attacks. May worsen performance" OFF)
if(HARDENING_ENABLE)
include(Hardening)
else()
function(harden target)
endfunction()
endif()
find_package(PkgConfig MODULE)
if(NOT DEFINED DEFAULT_ENABLE_HWLOC)
find_package(Hwloc)
if(NOT Hwloc_FOUND)
message(STATUS "hwloc package not found")
set(DEFAULT_ENABLE_HWLOC OFF CACHE INTERNAL "default hwloc")
else()
if("${Hwloc_VERSION}" VERSION_LESS "1.0")
message(FATAL_ERROR "Hwloc version must be >= 1.0 !")
endif()
message(STATUS "Hwloc_VERSION ${Hwloc_VERSION}")
message(STATUS "Hwloc_LIBRARIES ${Hwloc_LIBRARIES}")
message(STATUS "Hwloc_INCLUDE_DIRS ${Hwloc_INCLUDE_DIRS}")
set(DEFAULT_ENABLE_HWLOC ON CACHE INTERNAL "default hwloc")
endif()
endif()
option(ENABLE_HWLOC "Enable Portable Hardware Locality software package"
${DEFAULT_ENABLE_HWLOC})
setup_cached_var(ENABLE_HWLOC "Using hwloc"
"Requested build with hwloc, but no hwloc found!"
"Hwloc found, but requested build without it")
include(sanitizers)
######################################################################################
if(ENABLE_TBB_DEVICE)
# related documentation: https://github.com/oneapi-src/oneTBB/tree/tbb_2020/cmake#binary-package-integration
find_package(TBB REQUIRED)
if(TARGET TBB::tbb)
set(TBB_IMPORTED_TARGETS TBB::tbb)
elseif(NOT TBB_FOUND AND PKG_CONFIG_FOUND)
message(STATUS "searching for TBB with pkg-config")
pkg_check_modules(TBB tbb>=2015)
if(TBB_FOUND)
set(TBB_IMPORTED_TARGETS "${TBB_LIBRARIES}" CACHE STRING "TBB libraries" FORCE)
endif()
endif()
if(NOT TBB_INCLUDE_DIRS)
get_target_property(TBB_INCLUDE_DIRS TBB::tbb INTERFACE_INCLUDE_DIRECTORIES)
endif()
if(NOT TBB_LIBRARIES)
get_target_property(TBB_LIBRARIES TBB::tbb IMPORTED_LOCATION_RELEASE)
endif()
if(NOT TBB_FOUND)
message(FATAL_ERROR "Can't find TBB libraries")
endif()
message(STATUS "Found TBB library: ${TBB_LIBRARIES} with include dirs: ${TBB_INCLUDE_DIRS}" )
# The tbb device depends on the pthread device which depends on the basic device. ENABLE_HOST_CPU_DEVICES enables both.
set(ENABLE_HOST_CPU_DEVICES 1)
endif()
if(ENABLE_HOST_CPU_DEVICES_OPENMP)
find_package(OpenMP)
if(NOT OpenMP_CXX_FOUND)
message(FATAL_ERROR "ENABLE_HOST_CPU_DEVICES_OPENMP specified but OpenMP not found.")
endif()
endif()
######################################################################################
if(NOT HOST_CPU_CACHELINE_SIZE)
set(CL_SIZE 0)
if(UNIX OR CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|Darwin")
find_program(GETCONF "getconf")
if(GETCONF)
execute_process(COMMAND "getconf" "LEVEL1_DCACHE_LINESIZE"
RESULT_VARIABLE RES OUTPUT_VARIABLE CL_SIZE)
if(RES)
message(WARNING "getconf exited with nonzero status!")
set(CL_SIZE 0)
else()
# getconf may in rare conditions return "undefined" value
if (CL_SIZE STREQUAL "undefined\n")
set(CL_SIZE 0)
endif()
# getconf sometimes just returns zero
if(NOT (CL_SIZE EQUAL 0))
string(STRIP "${CL_SIZE}" CL_SIZE)
message(STATUS "L1D Cacheline size detected: ${CL_SIZE}")
set(HOST_CPU_CACHELINE_SIZE "${CL_SIZE}" CACHE STRING "L1D Cacheline size")
endif()
endif()
endif()
endif()
if(CL_SIZE EQUAL 0)
message(WARNING "Unable to detect cacheline size - assuming 64byte cacheline, override with -DHOST_CPU_CACHELINE_SIZE=<number> (Note: this is merely used for optimization, at worst pocl will be slightly slower)")
set(HOST_CPU_CACHELINE_SIZE "64" CACHE STRING "L1D Cacheline size")
endif()
endif()
######################################################################################
#
# Find executables to few tools required during build
#
find_program(PATCH_EXEC
NAMES patch
HINTS ENV PATH
)
find_program(XARGS_EXEC
NAMES xargs
HINTS ENV PATH
)
if(NOT PATCH_EXEC)
message(FATAL_ERROR "Could not find patch command.")
endif()
if(NOT XARGS_EXEC)
message(FATAL_ERROR "Could not find xargs command.")
endif()
######################################################################################
if(ENABLE_LLVM)
include(LLVM RESULT_VARIABLE RES)
if(NOT RES)
message(FATAL_ERROR "Could not load LLVM.cmake")
endif()
if(ENABLE_HOST_CPU_DEVICES)
if(NOT DEFINED HOST_DEVICE_BUILD_HASH)
set(HOST_DEVICE_BUILD_HASH "${LLC_TRIPLE}")
endif()
if(INTEL_SDE_AVX512)
set(HOST_CPU_FORCED 1 CACHE INTERNAL "CPU is forced by user" FORCE)
set(SELECTED_HOST_CPU "skylake-avx512" CACHE STRING "The Host CPU to use with llc" FORCE)
endif()
endif()
#
# LLVM_OPAQUE_POINTERS
#
# llvm has changed from typed pointers to opaque pointers, their guidance is
#
# From https://llvm.org/docs/OpaquePointers.html, version support
# LLVM 14: Supports all necessary APIs for migrating to opaque pointers and deprecates/removes
# incompatible APIs. However, using opaque pointers in the optimization pipeline is not fully
# supported. This release can be used to make out-of-tree code compatible with opaque
# pointers, but opaque pointers should not be enabled in production.
#
# LLVM 15: Opaque pointers are enabled by default. Typed pointers are still available, but only
# supported on a best-effort basis and may be untested.
#
# LLVM 16: Only opaque pointers will be supported. Typed pointers will not be supported.
#
# Up to llvm 14 including, ENABLE_LLVM_OPAQUE_POINTERS is force-set to OFF
# For llvm 15 ENABLE_LLVM_OPAQUE_POINTERS is a CMake option, defaulting to OFF,
# Post llvm 15, ENABLE_LLVM_OPAQUE_POINTERS is force-set to ON.
# Clang 16 accepts -Xclang -no-opaque-pointers but silently produces bitcode with opaque pointers.
# reason is that 1) it's unfinished 2) for properly handling images, we need opaque types,
# which will only be available in LLVM 16+
# TODO: This should be temporary. After the opaque pointer conversion in PoCL is finished,
# we should remove this macro and use LLVM_OLDER_THAN_X macros only, like in the rest
# of the code, since this macro adds another layer of complexity.
if(LLVM_VERSION VERSION_LESS_EQUAL 14.0)
set(ENABLE_LLVM_OPAQUE_POINTERS OFF CACHE INTERNAL "llvm opaque pointers" FORCE)
elseif(LLVM_VERSION VERSION_EQUAL 15.0)
if(ENABLE_LEVEL0)
set(ENABLE_LLVM_OPAQUE_POINTERS OFF CACHE INTERNAL "llvm opaque pointers" FORCE)
else()
option(ENABLE_LLVM_OPAQUE_POINTERS "Handle the change to llvm opaque pointers." ON)
endif()
else()
set(ENABLE_LLVM_OPAQUE_POINTERS ON CACHE INTERNAL "llvm opaque pointers" FORCE)
endif()
if (ENABLE_LLVM_OPAQUE_POINTERS)
set(LLVM_OPAQUE_POINTERS 1)
endif()
else()
if(ENABLE_HOST_CPU_DEVICES AND (NOT DEFINED HOST_DEVICE_BUILD_HASH))
message(FATAL_ERROR "For compiler-less builds of CPU backend, you must define HOST_DEVICE_BUILD_HASH")
endif()
endif()
######################################################################################
if(ENABLE_HSA)
include(HSA RESULT_VARIABLE RES)
if(NOT RES)
message(FATAL_ERROR "Could not load HSA.cmake")
endif()
endif()
######################################################################################
if (NOT MSVC)
find_program(LINK_COMMAND
NAMES ld${CMAKE_EXECUTABLE_SUFFIX}
HINTS ENV PATH
)
else()
set(LINK_COMMAND "${CLANGXX}")
endif()
######################################################################################
if(UNIX)
include(CheckCSourceCompiles)
include(CheckSymbolExists)
# don't allow implicit function declarations
set(CMAKE_REQUIRED_FLAGS "-std=c99 ${FORBID_IMPLICIT_FUNCTIONS}")
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CMAKE_REQUIRED_LIBRARIES "rt")
endif ()
CHECK_SYMBOL_EXISTS("fork"
"sys/types.h;unistd.h"
HAVE_FORK)
CHECK_SYMBOL_EXISTS("fsync"
"unistd.h"
HAVE_FSYNC)
CHECK_SYMBOL_EXISTS("sleep"
"unistd.h"
HAVE_SLEEP)
CHECK_SYMBOL_EXISTS("getrlimit"
"sys/time.h;sys/resource.h"
HAVE_GETRLIMIT)
CHECK_SYMBOL_EXISTS("utime"
"sys/types.h;utime.h"
HAVE_UTIME)
CHECK_SYMBOL_EXISTS("ANNOTATE_HAPPENS_BEFORE"
"valgrind/helgrind.h"
HAVE_VALGRIND)
set(CMAKE_REQUIRED_DEFINITIONS "-D_POSIX_C_SOURCE=200809L")
CHECK_SYMBOL_EXISTS("futimens"
"fcntl.h;sys/stat.h"
HAVE_FUTIMENS)
set(CMAKE_REQUIRED_DEFINITIONS "-D_POSIX_C_SOURCE=200112L")
CHECK_SYMBOL_EXISTS("posix_memalign"
"stdlib.h"
HAVE_POSIX_MEMALIGN)
set(CMAKE_REQUIRED_DEFINITIONS "-D_POSIX_C_SOURCE=199309L")
CHECK_SYMBOL_EXISTS("clock_gettime"
"time.h"
HAVE_CLOCK_GETTIME)
CHECK_SYMBOL_EXISTS("fdatasync"
"unistd.h"
HAVE_FDATASYNC)
set(CMAKE_REQUIRED_DEFINITIONS "-D_BSD_SOURCE" "-D_DEFAULT_SOURCE")
CHECK_SYMBOL_EXISTS("mkdtemp"
"stdlib.h;unistd.h"
HAVE_MKDTEMP)
CHECK_SYMBOL_EXISTS("mkstemps"
"stdlib.h;unistd.h"
HAVE_MKSTEMPS)
CHECK_SYMBOL_EXISTS("vfork"
"sys/types.h;unistd.h"
HAVE_VFORK)
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
CHECK_SYMBOL_EXISTS("mkostemps"
"stdlib.h"
HAVE_MKOSTEMPS)
set(CMAKE_REQUIRED_LIBRARIES "dl")
CHECK_SYMBOL_EXISTS("dladdr"
"dlfcn.h"
HAVE_DLADDR)
if(ENABLE_VSOCK)
find_file(
HAVE_LINUX_VSOCK_H
NAMES
linux/vm_sockets.h
PATHS
/usr/include
)
if(NOT HAVE_LINUX_VSOCK_H)
message(FATAL_ERROR "Could not find vsock header file. Please \
make sure that the kernel is configured with vsock support.
")
endif()
endif()
unset(CMAKE_REQUIRED_DEFINITIONS)
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LIBRARIES)
else()
set(HAVE_CLOCK_GETTIME 0)
set(HAVE_FDATASYNC 0)
set(HAVE_FSYNC 0)
set(HAVE_SLEEP 0)
set(HAVE_MKOSTEMPS 0)
set(HAVE_MKSTEMPS 0)
set(HAVE_MKDTEMP 0)
set(HAVE_FUTIMENS 0)
set(HAVE_FORK 0)
set(HAVE_GETRLIMIT 0)
set(HAVE_VFORK 0)
set(HAVE_UTIME 0)
set(HAVE_DLADDR 0)
set(HAVE_VALGRIND 0)
endif()
######################################################################################
function(check_64bit_atomics varname)
check_c_source_compiles("
#include <stdint.h>
uint64_t x = 0;
int main()
{
__atomic_add_fetch(&x, 1, __ATOMIC_SEQ_CST);
__atomic_sub_fetch(&x, 1, __ATOMIC_SEQ_CST);
return x;
}
" ${varname})
endfunction(check_64bit_atomics)
# platforms w/o lockfree 64bit atomics need to link with -latomic
if(UNIX)
check_64bit_atomics(HAVE_64BIT_ATOMICS_WITHOUT_LIB)
if(HAVE_64BIT_ATOMICS_WITHOUT_LIB)
set(HAVE_64BIT_ATOMICS_WITH_LIB FALSE)
else()
set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_64bit_atomics(HAVE_64BIT_ATOMICS_WITH_LIB)
set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
if(NOT HAVE_64BIT_ATOMICS_WITH_LIB)
message(SEND_ERROR "Missing 64-bit atomic increment")
endif()
endif()
endif()
######################################################################################
if(UNIX AND ENABLE_LLVM AND HAVE_DLADDR)
option(ENABLE_RELOCATION "make libpocl relocatable" ON)
else()
message(STATUS "Relocation not available")
set(ENABLE_RELOCATION OFF CACHE INTERNAL "libpocl relocatable" FORCE)
endif()
if(ENABLE_RELOCATION)
file(RELATIVE_PATH POCL_INSTALL_PRIVATE_DATADIR_REL ${POCL_INSTALL_PUBLIC_LIBDIR} ${POCL_INSTALL_PRIVATE_DATADIR})
message(STATUS "Private Datadir Relative path: ${POCL_INSTALL_PRIVATE_DATADIR_REL}")
install(FILES ${CLANG_OPENCL_HEADERS}
DESTINATION "${POCL_INSTALL_PRIVATE_DATADIR}/include" COMPONENT "dev")
endif()
file(RELATIVE_PATH POCL_INSTALL_PRIVATE_LIBDIR_REL ${POCL_INSTALL_PUBLIC_LIBDIR} ${POCL_INSTALL_PRIVATE_LIBDIR})
######################################################################################
# IPO support for runtime library
if(POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif()
if(NOT DEFINED DEFAULT_ENABLE_IPO)
set(DEFAULT_ENABLE_IPO OFF CACHE BOOL "IPO" FORCE)
if(NOT CMAKE_VERSION VERSION_LESS "3.9")
if(DEVELOPER_MODE)
set(IPO 0)
else()
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO OUTPUT IPO_OUTPUT)
endif()
set(DEFAULT_ENABLE_IPO ${IPO} CACHE BOOL "IPO" FORCE)
message(STATUS "Compiler supports IPO: ${DEFAULT_ENABLE_IPO}")
#message(STATUS "IPO check message: ${IPO_OUTPUT}")
endif()
endif()
setup_cached_var(ENABLE_IPO "Enable Link-Time Optimization (IPO) while building pocl runtime"
"Requested build with IPO, but IPO is not available"
"IPO available, but requested build without it")
if(HAVE_VALGRIND)
option(ENABLE_VALGRIND "Enable valgrind support (this may slow down PoCL)" OFF)
else()
set(ENABLE_VALGRIND OFF CACHE BOOL "valgrind is not available" FORCE)
endif()
######################################################################################
option(ENABLE_SLEEF "Use SLEEF for kernel library" ON)
option(ENABLE_CONFORMANCE "Enable conformance to OpenCL standard. \
Enabling this option this does not guarantee conformance (depends on hardware), \
but CMake will give errors if options that conflict with conformance \
are used. It also disables advertising incomplete extensions." OFF)
option(ENABLE_UNFINISHED_EXTENSIONS "Advertise extensions in device queries which \
might work partially, but have known unfinished features." OFF)
if(ENABLE_CONFORMANCE AND (NOT ENABLE_SLEEF))
message(FATAL_ERROR "conformance needs enabled SLEEF")
endif()
######################################################################################
# fully device-side printf on devices which support it (only CPU backend ATM), disabled by default.
# this requires 128bit integer support because of the code in "errol" float-to-string conversion routine
# the output is not 100% compatible with glibc's printf (%f with large argument prints zeroes after
# last significant digit - 16-18th digit or so, unlike glibc which prints digits up to decimal point).
if(CLANG_HAS_128B_MATH)
option(ENABLE_POCL_FLOAT_CONVERSION "Enable use of pocl's own float-to-decimal conversion code in OpenCL printf(). Defaults to OFF (uses snprintf from C library). Requires compiler-rt." OFF)
else()
set(ENABLE_POCL_FLOAT_CONVERSION OFF CACHE INTERNAL "pocl's own float-to-decimal conversion code")
endif()
unset(FLOATCONV_FLAG)
if(ENABLE_POCL_FLOAT_CONVERSION)
# force link with Clang; otherwise not needed on x86 but in this case we need rtlib
set(FLOATCONV_FLAG "-DENABLE_POCL_FLOAT_CONVERSION")
endif()
unset(OPAQUE_PTR_FLAGS)
if(LLVM_VERSION VERSION_EQUAL 15.0)
if(LLVM_OPAQUE_POINTERS)
set(OPAQUE_PTR_FLAGS "-Xclang -opaque-pointers")
else()
set(OPAQUE_PTR_FLAGS "-Xclang -no-opaque-pointers")
endif()
endif()
######################################################################################
# for kernel code, disable PIC & stack protector
#
# it seems PIC and stack-protector defaults somehow depend on
# clang build type or environment. PIC causes problems with
# constant addrspace variables, and stack protector likely slows
# down the kernels, so it needs to be determined whether it's worth
# the trouble.
#
# no-jump-tables is to avoid LLVM optimization passes introducing switch tables,
# which the variable uniformity analysis cannot analyze
set(DEFAULT_KERNEL_CL_FLAGS "-xcl -fno-stack-protector -fPIC -fno-jump-tables ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
set(DEFAULT_KERNEL_C_FLAGS "-xc -std=c11 -D__CBUILD__ -fno-math-errno -fno-stack-protector -fPIC -fno-jump-tables ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
set(DEFAULT_KERNEL_CXX_FLAGS "-xc++ -std=c++11 -fno-stack-protector -fPIC -fno-jump-tables ${FLOATCONV_FLAG} ${OPAQUE_PTR_FLAGS}")
set(EXTRA_KERNEL_FLAGS "" CACHE STRING "Extra arguments to all kernel compilation commands (defaults to empty)")
set(EXTRA_KERNEL_CL_FLAGS "" CACHE STRING "Extra arguments to kernel CL compiler (defaults to empty)")
set(EXTRA_KERNEL_CXX_FLAGS "" CACHE STRING "Extra arguments to kernel CXX compiler (defaults to empty)")
set(EXTRA_KERNEL_C_FLAGS "" CACHE STRING "Extra arguments to kernel C compiler (defaults to empty)")
set(KERNEL_CXX_FLAGS "${DEFAULT_KERNEL_CXX_FLAGS}${EXTRA_KERNEL_FLAGS}${EXTRA_KERNEL_CXX_FLAGS}")
set(KERNEL_CL_FLAGS "${DEFAULT_KERNEL_CL_FLAGS}${EXTRA_KERNEL_FLAGS}${EXTRA_KERNEL_CL_FLAGS}")
set(KERNEL_C_FLAGS "${DEFAULT_KERNEL_C_FLAGS}${EXTRA_KERNEL_FLAGS}${EXTRA_KERNEL_C_FLAGS}")
######################################################################################
if(UNIX)
if(APPLE)
# MacOS ld outputs useless warnings like
# ld: warning: -macosx_version_min not specificed, assuming 10.7
# suppress them with -w.
set(DEFAULT_HOST_LD_FLAGS "-dynamiclib -w -lm")
elseif(ANDROID)
set(DEFAULT_HOST_LD_FLAGS "-L/system/lib/ -shared -ldl -lc /system/lib/crtbegin_so.o /system/lib/crtend_so.o")
else()
set(DEFAULT_HOST_LD_FLAGS "-shared")
endif()
set(LIBMATH "-lm")
elseif(WIN32)
set(LIBMATH)
endif()
if(CLANG_NEEDS_RTLIB)
set(DEFAULT_HOST_LD_FLAGS "${DEFAULT_HOST_LD_FLAGS} --rtlib=compiler-rt")
endif()
######################################################################################
if(UNIX)
if(APPLE)
# TODO MACOSX_BUNDLE target prop
set(ICD_LD_FLAGS "-single_module")
else()
set(ICD_LD_FLAGS "-Wl,-Bsymbolic")
endif()
endif()
######################################################################################
set(SPIRV OFF)
# drivers that consume SPIRV directly don't need LLVM or LLVM-SPIRV;
# those that consume SPIRV indirectly need both, but it might be useful to disable LLVM-SPIRV translator
if(ENABLE_LLVM AND LLVM_SPIRV AND (EXISTS "${LLVM_SPIRV}"))
option(ENABLE_SPIRV "Enable SPIR-V support (default ON when available)" ON)
else()
set(ENABLE_SPIRV OFF CACHE INTERNAL "SPIR-V enabled" FORCE)
endif()
if(ENABLE_SPIRV)
# required for the wrapper generator
find_package(Python3 REQUIRED COMPONENTS Interpreter)
endif()
######################################################################################
set(HAVE_DLFCN_H OFF CACHE BOOL "dlopen" FORCE)
if(WIN32 AND (NOT MINGW))
message(STATUS "Using LoadLibrary/FreeLibrary in Windows, libltdl not needed.")
elseif(UNIX)
if (CMAKE_CROSSCOMPILING AND (NOT ENABLE_HOST_CPU_DEVICES) AND (NOT ENABLE_HSA))
message(STATUS "Cross-compiling without CPU/HSA devices -> skipping LIBDL search")
else()
find_library(DL_LIB "dl")
find_file(DL_H "dlfcn.h")
if(DL_LIB AND DL_H)
message(STATUS "libdl found")
else()
message(STATUS "libdl not found, assuming dlopen() is in libc")
set(DL_LIB "")
endif()
if(DL_H)
get_filename_component(DL_H_INCLUDE_DIR "${DL_H}" DIRECTORY)
string(FIND "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}" "${DL_H_INCLUDE_DIR}" LTPOSITION)