forked from Auburn/FastNoiseSIMD
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
488 lines (405 loc) · 15.5 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
cmake_minimum_required(VERSION 3.10)
string(COMPARE EQUAL "$ENV{TRAVIS}" "true" is_travis)
string(COMPARE EQUAL "$ENV{APPVEYOR}" "True" is_appveyor)
option(HN_FAST_INVSQRT "Use fast inverse sqrt" OFF)
option(HN_BUILD_APP "Build test app" OFF)
option(HN_PREVIEW_APP "Build preview app" ON)
#Using FMA instructions with AVX(51)2/NEON provides a small performance increase but can cause
#minute variations in noise output compared to other SIMD levels due to higher calculation precision
#Intel compiler will always generate FMA instructions, use /Qfma- or -no-fma to disable
option(HN_USE_FMA "Use fused multiply/add, adds small performance to avx2/avx512/neon but output will differ minutely to other SIMD versions" ON)
if(is_travis OR is_appveyor)
set(HN_BUILD_APP ON CACHE BOOL "Build test app" FORCE) #force building app on CI
set(HN_PREVIEW_APP OFF CACHE BOOL "Build preview app" FORCE) #don't need for CI
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "is_travis: ${is_travis}")
message(STATUS "is_appveyor: ${is_appveyor}")
message(STATUS "HN_BUILD_APP: ${HN_BUILD_APP}")
message(STATUS "HN_PREVIEW_APP: ${HN_PREVIEW_APP}")
include(${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/HunterGate.cmake)
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.23.181.tar.gz"
SHA1 "270cafa2d67def4ad4d52409ff22a28890d41c84"
LOCAL
)
project(HastyNoise VERSION 0.8.0)
if(MSVC)
#setup pdb info
set(pdb_output_dir "${CMAKE_CURRENT_BINARY_DIR}/pdb-files")
set(CMAKE_PDB_OUTPUT_DIRECTORY "${pdb_output_dir}")
set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY "${pdb_output_dir}")
#need to sync pdp files
add_compile_options("/FS")
else()
#requires c++17 for inline static variable support
set(CMAKE_CXX_STANDARD 17)
endif()
set(HN_SIMD_SSE2 OFF)
set(HN_SIMD_SSE41 OFF)
set(HN_SIMD_AVX2 OFF)
set(HN_SIMD_AVX512 OFF)
set(HN_SIMD_NEON OFF)
set(HN_NO_FILESYSTEM 0)
set(HN_STD_FILESYSTEM 1)
set(HN_EXPERIMENTAL_FILESYSTEM 2)
set(HN_USE_FILESYSTEM ${HN_NO_FILESYSTEM})
set(HN_ARM64 OFF)
if(ANDROID_NDK_VERSION)
string(SUBSTRING ${CMAKE_ANDROID_ARCH_ABI} 0 5 FM_ANDROID_ARCH)
string(TOLOWER ${FM_ANDROID_ARCH} FM_ANDROID_ARCH)
string(COMPARE EQUAL ${FM_ANDROID_ARCH} "arm64" HN_ARM64)
elseif(IOS_SDK_VERSION)
string(SUBSTRING ${IPHONEOS_ARCHS} 0 3 FM_IOS_ARCH)
string(TOLOWER ${FM_IOS_ARCH} FM_IOS_ARCH)
string(COMPARE EQUAL ${FM_IOS_ARCH} "arm" HN_ARM64)
endif()
#get options based on architecture and compilier
if(HN_ARM64)
set(HN_SIMD_NEON ON)
else()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
message(STATUS "MSVC_VERSION: ${MSVC_VERSION}")
add_definitions(-DNOMINMAX)
set(HN_SIMD_SSE2 ON)
set(HN_SIMD_SSE41 ON)
if(MSVC_VERSION GREATER_EQUAL 1900)
set(HN_SIMD_AVX2 ON)
set(HN_USE_FILESYSTEM ${HN_EXPERIMENTAL_FILESYSTEM})
if(MSVC_VERSION GREATER 1900)
set(HN_SIMD_AVX512 ON) #something wrong finding floor function
# include(CheckCXXCompilerFlag)
#
# CHECK_CXX_COMPILER_FLAG("/std:c++17" _cpp_17_flag_supported)
# if(_cpp_17_flag_supported)
# add_compile_options("/std:c++17")
set(HN_USE_FILESYSTEM ${HN_STD_FILESYSTEM})
# endif()
endif()
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(HN_SIMD_SSE2 ON)
set(HN_SIMD_SSE41 ON)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.9)
set(HN_SIMD_AVX2 ON)
set(HN_SIMD_AVX512 ON)
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(HN_SIMD_SSE2 ON)
set(HN_SIMD_SSE41 ON)
set(HN_USE_FILESYSTEM ${HN_EXPERIMENTAL_FILESYSTEM})
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.6)
set(HN_SIMD_AVX2 ON)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9)
set(HN_SIMD_AVX512 ON)
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
set(HN_USE_FILESYSTEM ${HN_STD_FILESYSTEM})
endif()
endif()
endif()
endif()
message(STATUS "HN_SIMD_SSE2: ${HN_SIMD_SSE2}")
message(STATUS "HN_SIMD_SSE41: ${HN_SIMD_SSE41}")
message(STATUS "HN_SIMD_AVX2: ${HN_SIMD_AVX2}")
message(STATUS "HN_SIMD_AVX512: ${HN_SIMD_AVX512}")
message(STATUS "HN_USE_FMA: ${HN_USE_FMA}")
set(hastyNoise_external_lib)
set(hastyNoise_sources
HastyNoise/hastyNoise.cpp
HastyNoise/hastyNoise_none.cpp
)
set(hastyNoise_headers
HastyNoise/hastyNoise.h
HastyNoise/hastyNoise_enums.h
HastyNoise/hastyNoise_export.h
)
set(hastyNoise_inline
HastyNoise/hastyNoise_internal.h
HastyNoise/hastyNoise_internal.inl
HastyNoise/simd_constants.inl
HastyNoise/internal_none.inl
HastyNoise/simd_init.inl
)
#project expects debug libs to have d at the end
if("${CMAKE_DEBUG_POSTFIX}" STREQUAL "")
set(CMAKE_DEBUG_POSTFIX "d")
endif()
add_library(hastyNoise SHARED
${hastyNoise_sources}
${hastyNoise_headers}
${hastyNoise_inline}
)
set(library_targets ${library_targets} hastyNoise)
target_compile_definitions(hastyNoise PRIVATE "-DHN_USE_FILESYSTEM=${HN_USE_FILESYSTEM}")
if(HN_FAST_INVSQRT)
target_compile_definitions(hastyNoise PUBLIC "-DHN_FAST_INVSQRT")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(hastyNoise PUBLIC "/bigobj")
if(MSVC_VERSION GREATER 1900)
target_compile_options(hastyNoise PUBLIC "/std:c++17")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options(hastyNoise PUBLIC "-ldl")
target_link_libraries(hastyNoise ${CMAKE_DL_LIBS})
if(HN_USE_FILESYSTEM GREATER 0)
target_compile_options(hastyNoise PUBLIC "-lstdc++fs")
target_link_libraries(hastyNoise stdc++fs)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND is_travis)
target_compile_options(hastyNoise PUBLIC "-Wno-ignored-attributes") #gcc warnings are mean to travis logs
endif()
endif()
#target_include_directories(hastyNoise PUBLIC ${CMAKE_CURRENT_LIST_DIR})
if(HN_USE_FILESYSTEM EQUAL ${HN_NO_FILESYSTEM})
hunter_add_package(Boost COMPONENTS filesystem)
find_package(Boost CONFIG REQUIRED filesystem)
list(APPEND hastyNoise_external_lib Boost::filesystem)
target_link_libraries(hastyNoise Boost::filesystem)
endif()
if(HN_SIMD_SSE2)
set(hastyNoise_sse2_sources
HastyNoise/hastyNoise_sse2.cpp
)
set(hastyNoise_sse2_headers
HastyNoise/internal_sse2.inl
)
add_library(hastyNoise_sse2 SHARED
${hastyNoise_sse2_sources}
${hastyNoise_sse2_headers}
)
set(library_targets ${library_targets} hastyNoise_sse2)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(hastyNoise_sse2 PUBLIC "/bigobj")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options(hastyNoise_sse2 PRIVATE "-msse2")
endif()
target_link_libraries(hastyNoise_sse2 hastyNoise)
endif()
if(HN_SIMD_SSE41)
set(hastyNoise_sse41_sources
HastyNoise/hastyNoise_sse41.cpp
)
set(hastyNoise_sse41_headers
HastyNoise/internal_sse41.inl
)
add_library(hastyNoise_sse41 SHARED
${hastyNoise_sse41_sources}
${hastyNoise_sse41_headers}
)
set(library_targets ${library_targets} hastyNoise_sse41)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(hastyNoise_sse41 PUBLIC "/bigobj")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options(hastyNoise_sse41 PRIVATE "-msse4.1")
endif()
target_link_libraries(hastyNoise_sse41 hastyNoise)
endif()
if(HN_SIMD_AVX2)
set(hastyNoise_avx2_sources
HastyNoise/hastyNoise_avx2.cpp
)
set(hastyNoise_avx2_headers
HastyNoise/internal_avx2.inl
)
add_library(hastyNoise_avx2 SHARED
${hastyNoise_avx2_sources}
${hastyNoise_avx2_headers}
)
set(library_targets ${library_targets} hastyNoise_avx2)
if(HN_USE_FMA)
target_compile_definitions(hastyNoise_avx2 PUBLIC "-DHN_USE_FMA")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(hastyNoise_avx2 PRIVATE "/arch:AVX2" "/bigobj")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options(hastyNoise_avx2 PRIVATE "-mavx2" "-mfma")
endif()
target_link_libraries(hastyNoise_avx2 hastyNoise)
endif()
if(HN_SIMD_AVX512)
set(hastyNoise_avx512_sources
HastyNoise/hastyNoise_avx512.cpp
)
set(hastyNoise_avx512_headers
HastyNoise/internal_avx512.inl
)
add_library(hastyNoise_avx512 SHARED
${hastyNoise_avx512_sources}
${hastyNoise_avx512_headers}
)
set(library_targets ${library_targets} hastyNoise_avx512)
if(HN_USE_FMA)
target_compile_definitions(hastyNoise_avx512 PUBLIC "-DHN_USE_FMA")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(hastyNoise_avx512 PRIVATE "/arch:AVX512" "/bigobj")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options(hastyNoise_avx512 PRIVATE "-mavx512f" "-mavx512dq" "-mfma")
endif()
target_link_libraries(hastyNoise_avx512 hastyNoise)
endif()
if(HN_BUILD_APP OR HN_PREVIEW_APP)
#add launcher for apps
hunter_add_package(CreateLaunchers)
find_package(CreateLaunchers CONFIG REQUIRED)
include(CreateLaunchers)
endif()
if(HN_BUILD_APP)
include_directories(${CMAKE_CURRENT_LIST_DIR})
add_executable(hastyNoiseApp testApp/main.cpp)
set(library_targets ${library_targets} hastyNoiseApp)
set(hastyNoise_libs
hastyNoise
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(hastyNoise_libs ${hastyNoise_libs}
Mincore.lib
)
endif()
target_link_libraries(hastyNoiseApp ${hastyNoise_libs})
target_compile_definitions(hastyNoiseApp PRIVATE "-DHN_USE_FILESYSTEM=${HN_USE_FILESYSTEM}")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if(HN_USE_FILESYSTEM GREATER 0)
target_compile_options(hastyNoiseApp PUBLIC "-lstdc++fs")
endif()
endif()
if(HN_SIMD_SSE2)
add_dependencies(hastyNoiseApp hastyNoise_sse2)
endif()
if(HN_SIMD_SSE41)
add_dependencies(hastyNoiseApp hastyNoise_sse41)
endif()
if(HN_SIMD_AVX2)
add_dependencies(hastyNoiseApp hastyNoise_avx2)
endif()
if(HN_SIMD_AVX512)
add_dependencies(hastyNoiseApp hastyNoise_avx512)
endif()
set(hastyNoiseApp_enviroment_dir)
foreach(target ${hastyNoise_external_lib})
list(APPEND hastyNoiseApp_enviroment_dir "$<TARGET_FILE_DIR:${target}>")
endforeach()
create_target_launcher(hastyNoiseApp
RUNTIME_LIBRARY_DIRS "${hastyNoiseApp_enviroment_dir}"
WORKING_DIRECTORY "$<TARGET_FILE_DIR:hastyNoiseApp>"
)
endif()
if(HN_PREVIEW_APP)
hunter_add_package(glfw)
find_package(glfw3 REQUIRED)
hunter_add_package(imgui)
find_package(imgui CONFIG REQUIRED)
add_executable(hastyPreviewApp preview/main.cpp)
target_include_directories(hastyPreviewApp PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(hastyPreviewApp hastyNoise glfw imgui::imgui)
if(HN_SIMD_SSE2)
add_dependencies(hastyPreviewApp hastyNoise_sse2)
endif()
if(HN_SIMD_SSE41)
add_dependencies(hastyPreviewApp hastyNoise_sse41)
endif()
if(HN_SIMD_AVX2)
add_dependencies(hastyPreviewApp hastyNoise_avx2)
endif()
if(HN_SIMD_AVX512)
add_dependencies(hastyPreviewApp hastyNoise_avx512)
endif()
#create launcher that will include hunter paths
set(hastyPreviewApp_enviroment_dir)
foreach(target ${hastyNoise_external_lib})
list(APPEND hastyPreviewApp_enviroment_dir "$<TARGET_FILE_DIR:${target}>")
endforeach()
set(hastyPreviewApp_working_dir ${CMAKE_CURRENT_LIST_DIR})
create_target_launcher(hastyPreviewApp
RUNTIME_LIBRARY_DIRS "${hastyPreviewApp_enviroment_dir}"
WORKING_DIRECTORY "$<TARGET_FILE_DIR:hastyPreviewApp>"
)
endif()
#Install -----------------------------------------------------------
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
include(GNUInstallDirs)
# Layout. This works for all platforms:
# * <prefix>/lib*/cmake/<PROJECT-NAME>
# * <prefix>/lib*/
# * <prefix>/include/
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
# Configuration
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
# Include module with fuction 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Use:
# * PROJECT_VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
# Configure '<PROJECT-NAME>Config.cmake'
# Use variables:
# * TARGETS_EXPORT_NAME
# * PROJECT_NAME
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
# Targets:
# * <prefix>/lib/libname.a
# * header location after install: <prefix>/include/${PROJECT_NAME}/include.hpp
# * headers can be included by C++ code `#include <${PROJECT_NAME}/include.hpp>`
install(
TARGETS ${library_targets}
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
# Headers:
install(
FILES ${hastyNoise_headers}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)
# Config
# * <prefix>/lib/cmake/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake
# * <prefix>/lib/cmake/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
# Config
# * <prefix>/lib/cmake/${PROJECT_NAME}/${PROJECT_NAME}Targets.cmake
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
if(MSVC)
#install pdbs
get_cmake_property(is_multi GENERATOR_IS_MULTI_CONFIG)
if(is_multi)
set(config_suffix "$<CONFIG>")
else()
set(config_suffix "")
endif()
if(BUILD_SHARED_LIBS)
set(pdb_dst ${CMAKE_INSTALL_BINDIR})
else()
set(pdb_dst ${CMAKE_INSTALL_LIBDIR})
endif()
install(
DIRECTORY "${pdb_output_dir}/${config_suffix}/"
DESTINATION ${pdb_dst}
)
endif()