-
Notifications
You must be signed in to change notification settings - Fork 48
/
CMakeLists.txt
793 lines (701 loc) · 24.9 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
#******************************************************************************
#
# MantaFlow fluid solver framework
#
# Copyright 2011-2020 Tobias Pfaff, Nils Thuerey
#
# This program is free software, distributed under the terms of the
# Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
#******************************************************************************
project (MantaFlow)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tools/cmake/")
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
set(VERBOSE 1)
set(MANTAVERSION "0.13")
#******************************************************************************
# Default paths
# - CMake's path finder is completely useless for Qt5 + Python on Win64
# - allow override from command line on OsX, eg use "cmake .. -DCMAKE_PREFIX_PATH=/Users/someone/qt5.2.1/5.2.1/clang_64/
if(WIN32)
set(WIN_QT_PATH "C:/Qt/5.9/msvc2013_64_opengl") # qt5/win64
set(WIN_PYTHON_PATH "C:/Python36") # choose python version with PYTHON_VERSION above
set(CMAKE_LIBRARY_PATH "C:/Program Files (x86)/Windows Kits/8.0/Lib/win8/um/x64")
set(CMAKE_PREFIX_PATH ${WIN_QT_PATH})
endif()
if(APPLE)
if(NOT CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH "/usr/local/opt/qt5/") # mac/homebrew (version independent)
#set(CMAKE_PREFIX_PATH "/home/myname/qt/5.5/clang_64") # other...
endif()
endif()
#******************************************************************************
# setup default params
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
else()
MESSAGE("Build-type: '${CMAKE_BUILD_TYPE}'")
endif()
# compilation versions
OPTION(DEBUG "Enable debug compilation" OFF)
OPTION(GUI "Compile with GUI (requires QT)" OFF)
OPTION(DOUBLEPRECISION "Compile with double floating point precision" OFF)
# multithreading
OPTION(TBB "Use multi-thread kernels using Intels TBB" OFF)
OPTION(OPENMP "Use multi-thread kernels using OpenMP" OFF)
# The following option will beautify generated files, and link to them for compiler errors instead of the original sources
OPTION(PREPDEBUG "Debug files generated by preprocessor" OFF)
# in debug mode, disable python debug libs (ie, link against release libs)
OPTION(DEBUG_PYTHON_WITH_RELEASE "Special debugging option for python, link with release libs even in debug mode. This can be handy, e.g., for windows." OFF)
# manually select a specific python version
OPTION(PYTHON_VERSION "Manually choose python version" OFF)
# numpy / tensorflow integration
OPTION(NUMPY "Compile with numpy integration?" OFF)
# compile with openVDB support
OPTION(OPENVDB "Exporting OpenVDB files" OFF)
OPTION(OPENVDB_BLOSC "Enable OpenVDB Blosc compression" OFF)
# further options for blender integration
OPTION(BLENDER "Compile for Blender integration" OFF)
# generate static library
OPTION(BUILD_STATIC "Enable building static library" OFF)
# special option to compile manta without any python, disables python glue code (while trying to keep as much of the rest as possible)
# this also means: static lib output , instead of executable
OPTION(NOPYTHON "Compile without python support (limited functionality!)" OFF)
if(NOPYTHON)
set(BUILD_STATIC ON)
endif()
# check consistency of MT options
set(MT OFF)
set(MT_TYPE "NONE")
if(TBB)
set(MT_TYPE "TBB")
set(MT ON)
endif()
if(OPENMP)
set(MT_TYPE "OPENMP")
set(MT ON)
endif()
if(TBB AND OPENMP)
message(FATAL_ERROR "Cannot activate both OPENMP and TBB")
endif()
# make sure debug settings match...
if(NOT DEBUG)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(DEBUG 1)
endif()
endif()
add_definitions ( -DMANTAVERSION="${MANTAVERSION}" )
if(DEBUG)
set(CMAKE_BUILD_TYPE "Debug")
add_definitions ( -DDEBUG=1 )
endif()
if(BLENDER)
add_definitions ( -DBLENDER=1 )
endif()
if(BLENDER AND GUI)
message(FATAL_ERROR "Cannot activate both BLENDER and GUI")
endif()
# translate option into python version string
if(NOT PYTHON_VERSION)
set(PYTHON_VER_ID) # use any...
else()
set(PYTHON_VER_ID ${PYTHON_VERSION})
endif()
if(OPENVDB AND NOT TBB)
message(FATAL_ERROR "Cannot activate OPENVDB without TBB")
endif()
MESSAGE(STATUS "")
MESSAGE(STATUS "Options - "
" -DDEBUG='${DEBUG}' "
" -DGUI='${GUI}' "
" -DTBB='${TBB}' "
" -DOPENMP='${OPENMP}' "
" -DPREPDEBUG='${PREPDEBUG}' "
" -DDOUBLEPRECISION='${DOUBLEPRECISION}' "
" -DPYTHON_VERSION='${PYTHON_VERSION}' "
" -DNUMPY='${NUMPY}' "
" -DNOPYTHON='${NOPYTHON}' "
)
MESSAGE(STATUS "Multithreading type : ${MT_TYPE}")
MESSAGE(STATUS "")
#******************************************************************************
# Pre-processor
# compile prep
set(SOURCES
source/preprocessor/main.cpp
source/preprocessor/code.cpp
source/preprocessor/tokenize.cpp
source/preprocessor/parse.cpp
source/preprocessor/util.cpp
source/preprocessor/merge.cpp
source/preprocessor/codegen_python.cpp
source/preprocessor/codegen_kernel.cpp
)
add_executable(prep ${SOURCES})
if(NOT WIN32)
set_target_properties(prep PROPERTIES COMPILE_FLAGS "-Wall -O2")
endif()
#******************************************************************************
# Setup main project
set(F_LIBS "" )
set(F_LIB_PATHS)
set(F_LINKADD "") # additional linker flags, not a list
set(PP_PATH "pp")
set(SILENT_SOURCES)
# need pre-processing
set(PP_SOURCES
source/general.cpp
source/fluidsolver.cpp
source/conjugategrad.cpp
source/multigrid.cpp
source/grid.cpp
source/grid4d.cpp
source/levelset.cpp
source/fastmarch.cpp
source/shapes.cpp
source/mesh.cpp
source/particle.cpp
source/movingobs.cpp
source/fileio/ioutil.cpp
source/fileio/iogrids.cpp
source/fileio/iomeshes.cpp
source/fileio/ioparticles.cpp
source/fileio/iovdb.cpp
source/fileio/mantaio.cpp
source/noisefield.cpp
source/kernel.cpp
source/vortexsheet.cpp
source/vortexpart.cpp
source/turbulencepart.cpp
source/timing.cpp
source/edgecollapse.cpp
source/plugin/advection.cpp
source/plugin/extforces.cpp
source/plugin/apic.cpp
source/plugin/flip.cpp
source/plugin/fire.cpp
source/plugin/fluidguiding.cpp
source/plugin/kepsilon.cpp
source/plugin/implicitdensityprojection.cpp
source/plugin/initplugins.cpp
source/plugin/meshplugins.cpp
source/plugin/pressure.cpp
source/plugin/ptsplugins.cpp
source/plugin/secondaryparticles.cpp
source/plugin/surfaceturbulence.cpp
source/plugin/vortexplugins.cpp
source/plugin/waveletturbulence.cpp
source/plugin/waves.cpp
source/python/defines.py
source/test.cpp
)
set(PP_HEADERS
source/general.h
source/commonkernels.h
source/conjugategrad.h
source/multigrid.h
source/fastmarch.h
source/fluidsolver.h
source/grid.h
source/grid4d.h
source/mesh.h
source/particle.h
source/levelset.h
source/shapes.h
source/noisefield.h
source/vortexsheet.h
source/kernel.h
source/timing.h
source/movingobs.h
source/fileio/mantaio.h
source/edgecollapse.h
source/vortexpart.h
source/turbulencepart.h
)
# no pre-processing needed
set(NOPP_SOURCES
source/pwrapper/pymain.cpp
source/pwrapper/pclass.cpp
source/pwrapper/pvec3.cpp
source/pwrapper/pconvert.cpp
source/pwrapper/registry.cpp
source/util/vectorbase.cpp
source/util/vector4d.cpp
source/util/simpleimage.cpp
)
set(NOPP_HEADERS
source/pwrapper/pythonInclude.h
source/pwrapper/pclass.h
source/pwrapper/registry.h
source/pwrapper/pconvert.h
source/util/integrator.h
source/util/vectorbase.h
source/util/vector4d.h
source/util/quaternion.h
source/util/interpol.h
source/util/mcubes.h
source/util/randomstream.h
source/util/solvana.h
)
if(GUI)
# need QT preprocessor
set(QT_HEADERS
source/gui/mainwindow.h
source/gui/glwidget.h
source/gui/painter.h
source/gui/meshpainter.h
source/gui/qtmain.h
source/gui/customctrl.h
source/gui/particlepainter.h
)
set(QT_SOURCES
source/gui/customctrl.cpp
source/gui/mainwindow.cpp
source/gui/glwidget.cpp
source/gui/customctrl.cpp
source/gui/painter.cpp
source/gui/meshpainter.cpp
source/gui/particlepainter.cpp
source/gui/qtmain.cpp
)
list(APPEND PP_SOURCES ${QT_SOURCES})
list(APPEND PP_HEADERS ${QT_HEADERS})
endif()
# include dirs
set(INCLUDE_PATHS
${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/source
${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/source/util
${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/source/fileio
source/pwrapper
source/util
source/fileio
)
# reduced version without python
if(NOPYTHON)
# replace some of the source lists
set(NOPP_SOURCES
source/nopython/pclass.cpp
source/util/vectorbase.cpp
source/util/vector4d.cpp
source/util/simpleimage.cpp
)
# update paths to use nopython versions
set(INCLUDE_PATHS
${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/source
${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/source/util
${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/source/fileio
source/nopython
source/util
source/fileio
)
add_definitions( -DNOPYTHON=1 )
endif()
# Multithreading
if(MT)
add_definitions( -DMANTA_MT=1 )
if(TBB)
# Intel TBB
add_definitions( -DTBB=1 )
if(DEBUG)
add_definitions( -DTBB_USE_DEBUG=1 )
endif()
list(APPEND F_LIBS tbb)
if(WIN32)
find_package(TBB REQUIRED)
list(APPEND INCLUDE_PATHS ${TBB_INCLUDE_DIRS})
list(APPEND F_LIB_PATHS ${TBB_LIBRARY_DIRS})
elseif(APPLE)
find_package(TBB REQUIRED)
list(APPEND INCLUDE_PATHS ${TBB_INCLUDE_DIRS})
list(APPEND F_LIB_PATHS ${TBB_LIBRARY_DIRS})
endif()
else()
# OpenMP
add_definitions( -DOPENMP=1 )
if(WIN32)
add_definitions( /openmp)
else()
add_definitions(-fopenmp)
set(F_LINKADD "${F_LINKADD} -fopenmp ")
endif()
endif()
endif()
#******************************************************************************
# optional - openvdb support
if(OPENVDB)
add_definitions(-DOPENVDB=1)
message("Note - mantaflow assumes OpenVDB is installed in '<manta-dir>/openVDB'. For windows you can find an example zip package on the mantaflow homepage under downloads.")
find_package(OpenVDB REQUIRED)
find_package(Boost)
set(BOOST_INCLUDE_DIR "${BOOST_INCLUDE_DIR}" CACHE PATH "")
list(APPEND INCLUDE_PATHS ${BOOST_INCLUDE_DIR})
if(BOOST_FOUND)
message("Found Boost")
set(Boost_LIBRARY_DIRS Boost_LIBRARY_DIRS CACHE PATH "")
endif()
if(OPENVDB_FOUND)
message("Found OpenVDB")
list(APPEND INCLUDE_PATHS ${OPENVDB_INCLUDE_DIR})
list(APPEND F_LIB_PATHS ${OPENVDB_LIBRARY_DIR})
list(APPEND F_LIBS ${OPENVDB_LIBRARY})
add_definitions(${OPENVDB_DEFINITIONS})
else()
if(WIN32)
message(FATAL_ERROR "Cannot find OpenVDB")
else()
message("Warning - OpenVDB not found, trying default paths")
# might be in path...
list(APPEND F_LIBS Half openvdb tbb)
endif()
endif()
# for windos try houdini, otherwise use openExr directly
if(WIN32)
find_package(Houdini REQUIRED)
if(HOUDINI_FOUND)
message("Found Houdini")
list(APPEND INCLUDE_PATHS ${HOUDINI_INCLUDE_DIRS})
list(APPEND INCLUDE_PATHS ${HOUDINI_INCLUDE_DIRS}/OpenEXR)
list(APPEND F_LIB_PATHS ${HOUDINI_LIBRARY_DIRS})
list(APPEND F_LIBS "Half.lib")
endif()
else()
# for open exr - should be in the default path, add includes if necessary
endif()
endif()
if(OPENVDB_BLOSC)
add_definitions(-DOPENVDB_BLOSC=1)
endif()
#******************************************************************************
# add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DX_PATH "doxy")
foreach(it ${PP_SOURCES} ${PP_HEADERS} ${NOPP_SOURCES} ${NOPP_HEADERS})
get_filename_component(CURPATH ${it} PATH)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${DX_PATH}/${CURPATH}")
set(CURDX "${DX_PATH}/${it}")
string(REPLACE "/" "_" TGT ${CURDX})
string(REPLACE "source/" "" INFILE ${it})
add_custom_command(OUTPUT ${TGT}
COMMAND prep docgen "0" ${MT_TYPE} "${CMAKE_CURRENT_SOURCE_DIR}/source/" "${INFILE}" "${CURDX}"
DEPENDS prep
IMPLICIT_DEPENDS CXX ${it}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND TGLIST ${TGT})
endforeach(it)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${TGLIST}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)
#******************************************************************************
# Link libraries
# Python
# note - if configuration fails, comment out the auto block below, and manually set the following two paths:
#set(PYTHON_INCLUDE_DIRS "PYTHON_PATH/include")
#set(PYTHON_LIBRARIES "PYTHON_PATH/libs/pythonX.Y.lib/so")
# auto block
if(WIN32)
# convenience override for windows, typically the auto find doesnt work, so fall back to WIN_PYTHON_PATH
find_package(PythonLibs ${PYTHON_VER_ID} QUIET)
if(NOT PYTHONLIBS_FOUND)
set(PYTHON_INCLUDE_DIRS "${WIN_PYTHON_PATH}/include")
set(PYTHON_LIBRARIES "${WIN_PYTHON_PATH}/libs/python${PYTHON_VER_ID}.lib")
endif()
else()
# try to configure from python itself first
execute_process(COMMAND python${PYTHON_VER_ID} -c "import sys,sysconfig; sys.stdout.write(sysconfig.get_config_var('INCLUDEPY'))" OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS)
execute_process(COMMAND python${PYTHON_VER_ID} -c "import sys,sysconfig; sys.stdout.write(sysconfig.get_config_var('LIBDIR'))" OUTPUT_VARIABLE PYTHON_LIB1)
if(APPLE)
# LDLIBRARY doesnt seem to work for Macs...
set(PYTHON_LIB2 "../Python")
else()
execute_process(COMMAND python${PYTHON_VER_ID} -c "import sys,sysconfig; sys.stdout.write(sysconfig.get_config_var('LDLIBRARY'))" OUTPUT_VARIABLE PYTHON_LIB2)
endif()
set(PYTHON_LIBRARIES "${PYTHON_LIB1}/${PYTHON_LIB2}")
if(EXISTS "${PYTHON_INCLUDE_DIRS}" AND EXISTS "${PYTHON_LIBRARIES}")
message("Found python configuration")
else()
# otherwise, fall back to cmake find
if(NOT PYTHON_VERSION)
find_package(PythonLibs REQUIRED) # use any
else()
find_package(PythonLibs ${PYTHON_VER_ID} EXACT QUIET) # fixed version
endif()
if(NOT PYTHONLIBS_FOUND)
message(FATAL_ERROR "No python found, please manually set PYTHON_VERSION for cmake, or PYTHON_ paths in CMakeLists.txt")
endif()
endif()
endif()
# end auto block, python config done
list(APPEND INCLUDE_PATHS ${PYTHON_INCLUDE_DIRS})
list(APPEND F_LIBS ${PYTHON_LIBRARIES})
message("Using python include path '${PYTHON_INCLUDE_DIRS}' and libs '${PYTHON_LIBRARIES}' ")
#******************************************************************************
# optional - compile with numpy support?
if(NUMPY)
# if the python command below doesnt work, manually set path, e.g., use "numpy.get_include()" to find path
# set(NUMPY_INCLUDE_DIR "${PYTHON_INCLUDE_DIRS}/dist-packages/numpy/core/include")
execute_process(COMMAND python${PYTHON_VER_ID} -c "import numpy, sys; sys.stdout.write(numpy.get_include())" OUTPUT_VARIABLE NUMPY_INCLUDE_DIR)
if("${NUMPY_INCLUDE_DIR}" STREQUAL "")
message(FATAL_ERROR "No numpy path found, please manually set NUMPY_INCLUDE_DIR in CMakeLists.txt")
endif()
message("Using numpy include path '${NUMPY_INCLUDE_DIR}' ")
list(APPEND INCLUDE_PATHS ${NUMPY_INCLUDE_DIR})
list(APPEND PP_SOURCES source/plugin/numpyconvert.cpp)
list(APPEND PP_SOURCES source/plugin/tfplugins.cpp)
list(APPEND NOPP_SOURCES source/pwrapper/numpyWrap.cpp)
list(APPEND NOPP_HEADERS source/pwrapper/numpyWrap.h)
add_definitions( -DNUMPY=1 )
endif()
#******************************************************************************
# Z lib compression
if(1)
# default: build from own sources
set(ZLIB_SRC adler32.c compress.c crc32.c deflate.c gzclose.c gzlib.c gzread.c gzwrite.c
inflate.c infback.c inftrees.c inffast.c trees.c uncompr.c zutil.c)
foreach(it ${ZLIB_SRC})
list(APPEND SILENT_SOURCES dependencies/zlib-1.2.8/${it})
endforeach(it)
set(ZLIB_ADDFLAGS "-Dverbose=-1")
if(NOT WIN32)
# otherwise we get warnings that we could only fix by upgrading zlib to a version > 1.2.8
set(ZLIB_ADDFLAGS "-Wno-implicit-function-declaration -Wno-shift-negative-value -Dverbose=-1")
endif()
set_source_files_properties(${SILENT_SOURCES} PROPERTIES COMPILE_FLAGS "${ZLIB_ADDFLAGS}")
list(APPEND INCLUDE_PATHS dependencies/zlib-1.2.8)
endif()
if(0)
# try to locate and use system libs
include(FindZLIB)
list(APPEND INCLUDE_PATHS ${ZLIB_INCLUDE_DIR})
list(APPEND F_LIBS ${ZLIB_LIBRARIES})
endif()
if(0)
# disable
add_definitions(-DNO_ZLIB=1)
endif()
# increase FP precision?
if(DOUBLEPRECISION)
add_definitions(-DFLOATINGPOINT_PRECISION=2)
endif()
#******************************************************************************
# cnpy support (import/export numpy arrays)
if(TRUE)
# default: build from own sources
list(APPEND SILENT_SOURCES dependencies/cnpy/cnpy.cpp)
set(CNPY_ADDFLAGS "-std=c++11")
set_source_files_properties(dependencies/cnpy/cnpy.cpp PROPERTIES COMPILE_FLAGS "${CNPY_ADDFLAGS}")
list(APPEND INCLUDE_PATHS dependencies/cnpy)
endif()
#******************************************************************************
# generate git repository info , currently only for unix systems
if(NOT WIN32)
set(GITINFO "${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/source/gitinfo.h")
MESSAGE(STATUS "Git info target header ${GITINFO}")
add_custom_command(OUTPUT ${GITINFO}
COMMAND python${PYTHON_VER_ID} "${CMAKE_CURRENT_SOURCE_DIR}/tools/getGitVersion.py" "${GITINFO}"
DEPENDS ${PP_SOURCES} ${PP_HEADERS} ${NOPP_SOURCES} ${NOPP_HEADERS} ${QT_SOURCES} ${QT_HEADERS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} )
endif()
#******************************************************************************
# apply preprocessor
set(SOURCES ${NOPP_SOURCES} ${SILENT_SOURCES})
set(HEADERS ${NOPP_HEADERS})
set(PP_REGCPP)
set(PP_REGS)
set(PP_PREPD "0")
set(PREPPED_SOURCES)
if(PREPDEBUG)
set(PP_PREPD "1")
endif()
FOREACH(it ${PP_SOURCES} ${PP_HEADERS})
get_filename_component(CURPATH ${it} PATH)
get_filename_component(CUREXT ${it} EXT)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/${CURPATH}")
set(CURPP "${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/${it}")
string(REPLACE "source/" "" INFILE ${it})
set(OUTFILES "${CURPP}")
if("${CUREXT}" STREQUAL ".h" OR "${CUREXT}" STREQUAL ".py")
if(NOT NOPYTHON)
list(APPEND PP_REGS "${CURPP}.reg")
list(APPEND PP_REGCPP "${CURPP}.reg.cpp")
endif()
set_source_files_properties("${CURPP}.reg.cpp" OBJECT_DEPENDS "${CURPP}")
list(APPEND OUTFILES "${CURPP}.reg")
endif()
# preprocessor
add_custom_command(OUTPUT ${OUTFILES}
COMMAND prep generate ${PP_PREPD} ${MT_TYPE} "${CMAKE_CURRENT_SOURCE_DIR}/source/" "${INFILE}" "${CURPP}"
DEPENDS prep
IMPLICIT_DEPENDS CXX ${it}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_source_files_properties(${OUTFILES} PROPERTIES GENERATED 1)
list(APPEND PREPPED_SOURCES ${CURPP})
ENDFOREACH(it)
list(APPEND SOURCES ${PREPPED_SOURCES})
# link reg files , for python glue code
if(NOT NOPYTHON)
add_custom_command(OUTPUT ${PP_REGCPP}
COMMAND prep link ${PP_REGS}
DEPENDS prep ${PP_REGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Linking reg files")
list(APPEND SOURCES ${PP_REGCPP})
set_source_files_properties(${PP_REGCPP} PROPERTIES GENERATED 1)
set(PP_REGISTER ${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/source/registration.cpp) # path to register, pass to prep as last argument
add_custom_command(OUTPUT ${PP_REGISTER}
COMMAND prep register ${SOURCES} ${PP_REGISTER}
DEPENDS prep ${PP_REGS} ${SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Ensuring registration functions are not removed by compiler")
list(APPEND SOURCES ${PP_REGISTER})
endif()
#******************************************************************************
# QT for GUI
if(GUI)
# remap
set(QT_REMAP)
foreach(it ${QT_HEADERS})
list(APPEND QT_REMAP "${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/${it}")
endforeach(it)
add_definitions(-DGUI=1)
list(APPEND INCLUDE_PATHS ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/${PP_PATH}/source/gui source/gui)
cmake_policy(SET CMP0020 NEW)
find_package(Qt5Core QUIET)
if(Qt5Core_FOUND)
message("Using Qt5")
find_package(Qt5Widgets REQUIRED)
find_package(Qt5OpenGL REQUIRED)
qt5_wrap_cpp(MOC_OUTFILES ${QT_REMAP} )
qt5_add_resources(QT_RES resources/res.qrc )
add_definitions(${Qt5Widgets_DEFINITIONS})
list(APPEND INCLUDE_PATHS ${Qt5Widgets_INCLUDE_DIRS} ${Qt5OpenGL_INCLUDE_DIRS})
list(APPEND F_LIBS ${Qt5Widgets_LIBRARIES} ${Qt5OpenGL_LIBRARIES})
list(APPEND SOURCES ${MOC_OUTFILES} ${QT_RES})
else()
message("No Qt5 found (recommended!), trying to use Qt4")
find_package(Qt4 REQUIRED)
set(QT_USE_QTOPENGL TRUE)
qt4_wrap_cpp(MOC_OUTFILES ${QT_REMAP} )
qt4_add_resources(QT_RES resources/res.qrc )
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
list(APPEND F_LIBS ${QT_LIBRARIES})
list(APPEND SOURCES ${MOC_OUTFILES} ${QT_RES})
endif()
if(APPLE)
# mac opengl framework
set(F_LINKADD "${F_LINKADD} -framework OpenGL ")
else()
find_package(OpenGL REQUIRED)
list(APPEND F_LIBS ${OPENGL_LIBRARIES})
endif()
endif()
#******************************************************************************
# setup executable
set(EXECCMD manta)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${F_LINKADD} ")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${F_LINKADD} ")
include_directories( ${INCLUDE_PATHS})
link_directories( ${F_LIB_PATHS} )
if(NOT NOPYTHON)
# build regular executable
if(WIN32)
# make nice folders for Visual Studio
set_source_files_properties(${PP_SOURCES} ${PP_HEADERS} ${NOPP_HEADERS} PROPERTIES HEADER_FILE_ONLY TRUE)
add_executable(${EXECCMD} ${SOURCES} ${PP_SOURCES} ${PP_HEADERS})
source_group(Generated FILES ${SOURCES} ${HEADERS})
else()
add_executable(${EXECCMD} ${SOURCES} ${GITINFO})
endif()
target_link_libraries( ${EXECCMD} ${F_LIBS} )
# fix for "el capitan" TBB and changed dynamic library env vars, lookup of TBB can cause problems without @rpath
if(APPLE)
EXEC_PROGRAM(uname ARGS -v OUTPUT_VARIABLE OSX_VERSION)
STRING(REGEX MATCH "[0-9]+" OSX_VERSION ${OSX_VERSION})
if(OSX_VERSION GREATER 14)
ADD_CUSTOM_COMMAND(TARGET manta POST_BUILD COMMAND
${CMAKE_INSTALL_NAME_TOOL} -change libtbb.dylib @rpath/libtbb.dylib $<TARGET_FILE:manta> )
endif()
endif()
elseif(BUILD_STATIC)
# only build static library in nopython mode
set(EXECCMD manta_static)
# only build static library, e.g. for nopython mode
ADD_LIBRARY (core OBJECT ${SOURCES} ${GITINFO})
ADD_LIBRARY (${EXECCMD} STATIC $<TARGET_OBJECTS:core>)
endif()
# gcc compiler flags
if(NOT WIN32)
if(DEBUG)
# stricter: no optimizations and inlining
set_target_properties(${EXECMD} PROPERTIES COMPILE_FLAGS " -O0 -fno-inline -Wall ")
else()
# non-debug, optimized version
set_target_properties(${EXECMD} PROPERTIES COMPILE_FLAGS " -O3 -Wall ")
endif()
endif()
# if supported, use c++14 for all pre-processed c++ sources
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
set(CXX_STANDARD_FLAG " ")
if(COMPILER_SUPPORTS_CXX14)
set(CXX_STANDARD_FLAG " -std=c++14 ")
elseif(COMPILER_SUPPORTS_CXX11)
set(CXX_STANDARD_FLAG " -std=c++11 ")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CXX_STANDARD_FLAG " -std=c++0x ")
endif()
set_source_files_properties(${PREPPED_SOURCES} ${PP_REGCPP} PROPERTIES COMPILE_FLAGS ${CXX_STANDARD_FLAG})
# sanity check for openvdb support
if(OPENVDB AND NOT COMPILER_SUPPORTS_CXX14)
message(FATAL_ERROR "Compilation with OpenVDB requires a compiler with C++14 support")
endif()
# necessary for newer LLVM clang versions, to prevent abundance of "Namify" template warnings... for compatibility disable unknown warnings
if(APPLE)
set_source_files_properties(${PP_REGCPP} ${PREPPED_SOURCES} ${NOPP_SOURCES} PROPERTIES COMPILE_FLAGS " -Wno-undefined-var-template -Wno-unknown-warning-option ${CXX_STANDARD_FLAG}" )
if(GUI)
set_source_files_properties(${MOC_OUTFILES} PROPERTIES COMPILE_FLAGS " -Wno-undefined-var-template -Wno-unknown-warning-option ${CXX_STANDARD_FLAG}" )
endif()
endif()
# thread support for linux
if(NOT APPLE AND NOT WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
# python debugging
if(DEBUG_PYTHON_WITH_RELEASE)
add_definitions(-DDEBUG_PYTHON_WITH_RELEASE=1)
endif()
# MSVC compiler settings
if(WIN32)
# get rid of some MSVC warnings
add_definitions( /wd4018 /wd4146 /wd4800 )
# for zlib
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
# unsigned to signed conversions
add_definitions( /wd4267 )
# double <> single precision
add_definitions( /wd4244 /wd4305 )
# disable warnings for unsecure functions
add_definitions( /D "_CRT_SECURE_NO_WARNINGS" )
if(BLENDER)
set(CMAKE_CXX_FLAGS_DEBUG "/MTd /Od /Ob0 /D_DEBUG /D PLATFORM_WINDOWS /Zi /RTC1 " )
set(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O1 /Ob1 /D NDEBUG /D PLATFORM_WINDOWS " )
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /D NDEBUG /D PLATFORM_WINDOWS " )
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MT /O2 /Ob1 /D NDEBUG /D PLATFORM_WINDOWS /Zi " )
endif()
# enable when using Qt creator:
#add_definitions(/FS)
endif()
# print debug summary
# MESSAGE(STATUS "DEBUG Flag-Summary - Includes: '${INCLUDE_PATHS}' | Libs: '${F_LIBS}' | LibPaths: '${F_LIB_PATHS}' ")