forked from opensim-org/opensim-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
840 lines (719 loc) · 34.3 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
project(OpenSim)
#
# Build of OpenSim. There are three steps:
# (1) Choose appropriate platform
# (2) Locate Simbody and its dependent libraries
# (3) Build OpenSim libraries and executables
#
#
#----------------------------------------------------
cmake_minimum_required(VERSION 3.2)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0005 NEW)
endif(COMMAND cmake_policy)
string(CONCAT DEP_BUILD_MSG
"\n-------------------------IMPORTANT----------------------------------\n"
"| Make sure that all OpenSim dependencies are built with the same |\n"
"| CMAKE_BUILD_TYPE (Linux) or CONFIGURATION (Xcode/MSVC) as OpenSim |\n"
"| to avoid mysterious runtime errors. |\n"
"-------------------------IMPORTANT----------------------------------\n")
message(${DEP_BUILD_MSG})
# To create a folder hierarchy within Visual Studio.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# OpenSim version.
# ----------------
set(OPENSIM_MAJOR_VERSION 4)
set(OPENSIM_MINOR_VERSION 0)
set(OPENSIM_PATCH_VERSION 0)
# Don't include the patch version if it is 0.
set(PATCH_VERSION_STRING)
if(OPENSIM_PATCH_VERSION)
set(PATCH_VERSION_STRING ".${OPENSIM_PATCH_VERSION}")
endif()
set(OPENSIM_VERSION
"${OPENSIM_MAJOR_VERSION}.${OPENSIM_MINOR_VERSION}${PATCH_VERSION_STRING}"
)
# CMake module path.
# ------------------
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(OpenSimMacros)
# Directory in which to install.
# ------------------------------
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# On Windows, we override the default value because Visual Studio does
# not, by default, have permission to write to the Program Files
# directory.
# On Linux, we override the default value because our installation does
# not yet conform to the Filesystem Hierarchy Standard (FHS).
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}-install" CACHE PATH
"The directory in which to install this project." FORCE)
endif()
# Make everything go in the same binary directory.
# ------------------------------------------------
# These are CMake-defined variables.
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
link_directories(${CMAKE_BINARY_DIR})
# OpenSim options.
# ----------------
# Specify number of cores to run tests.
set(PROCESSOR_COUNT 8 CACHE STRING
"Number of concurrent jobs when running tests via RUN_TESTS_PARALLEL target.")
mark_as_advanced(PROCESSOR_COUNT)
# Try to use MathJax for Doxygen equations.
option(OPENSIM_DOXYGEN_USE_MATHJAX "Try to use MathJax to render Doxygen
equations. If OFF, LATEX is used instead if you have it; otherwise we use
MathJax from the internet (we don't download it). If we cannot download MathJax
from the internet, we turn this option OFF." ON)
# Simbody.
# This will be initialized to the environment variable of the same name
# if it is set, otherwise it will be empty.
set(SIMBODY_HOME $ENV{SIMBODY_HOME} CACHE
PATH "The location of the Simbody installation to use; you can change this. Set as empty to let CMake search for Simbody automatically.")
option(OPENSIM_COPY_DEPENDENCIES "Copy Simbody and BTK into the
OpenSim installation. This should be set to ON when making a relocatable
distribution, and should be set to OFF when packaging for Homebrew, Debian,
etc. On Linux and macOS: we use relative RPATHs when ON, and absolute RPATHs
when OFF." ON)
option(OPENSIM_PYTHON_STANDALONE "Make the Python package standalone, meaning
the OpenSim (and Simbody and BTK) shared libraries it depends on are copied
into the package. If you are building OpenSim on the same machine on which you
plan to use it, you can leave this OFF. If you are distributing OpenSim to
other computers, you should turn this ON. If macOS, this option affects how
RPATH is set for the SWIG-generated shared libraries. This variable has no
effect if BUILD_PYTHON_WRAPPING is OFF." OFF)
mark_as_advanced(OPENSIM_PYTHON_STANDALONE) # Mainly for packagers; not users.
# There are many potential ways to distribute the python bindings; here's how
# you might want to set the above option for different ways of distributing:
# simtk.org GUI distribution, macOS: ON (since no env. vars are set)
# simtk.org GUI distrubution, Windows: OFF (PATH is set)
# pypi: ON (there is no way to install the C++ libraries otherwise)
# debian, homebrew, conda: OFF (can have a separate C++ library package)
option(BUILD_API_ONLY "Build/install only headers, libraries,
wrapping, tests; not applications (opensim, ik, rra, etc.)." OFF)
set(OPENSIM_BUILD_INDIVIDUAL_APPS_DEFAULT OFF)
if(WIN32)
# For backwards compatibility in the Windows binary distribution.
set(OPENSIM_BUILD_INDIVIDUAL_APPS_DEFAULT ON)
endif()
option(OPENSIM_BUILD_INDIVIDUAL_APPS
"Build/install the old command line applications (ik, id, rra, cmc, etc.)."
${OPENSIM_BUILD_INDIVIDUAL_APPS_DEFAULT})
mark_as_advanced(OPENSIM_BUILD_INDIVIDUAL_APPS)
# Configure installation directories across platforms.
# ----------------------------------------------------
## OPENSIM_INSTALL_UNIX_FHS option.
set(OPENSIM_INSTALL_UNIX_FHS_DEFAULT OFF)
if(UNIX)
set(OPENSIM_INSTALL_UNIX_FHS_DEFAULT ON)
endif()
option(OPENSIM_INSTALL_UNIX_FHS
"Organize installation according to UNIX Filesystem Hierarchy Standard."
${OPENSIM_INSTALL_UNIX_FHS_DEFAULT})
if(WIN32)
# Windows users probably aren't interested in this option.
mark_as_advanced(OPENSIM_INSTALL_UNIX_FHS)
endif()
## Set variables describing where everything gets installed.
if(${OPENSIM_INSTALL_UNIX_FHS})
# Sets CMAKE_INSTALL_*DIR variables, some of which are used below.
include(GNUInstallDirs)
# Do *NOT* try to use the CMAKE_INSTALL_FULL_*DIR variables created by
# GNUInstallDirs; they are only defined if OPENSIM_INSTALL_UNIX_FHS is ON.
# Now set variables that depend on those set by GNUInstallDirs.
# There's a difference between the locations of these files we'd want
# when using apt-get, and what a build-from-source user would want. For
# now the focus is making sure that if a build-from-source user installs
# into /usr or /usr/local, they have a FHS-compliant OpenSim installation.
set(OPENSIM_INSTALL_ARCHIVEDIR "${CMAKE_INSTALL_LIBDIR}")
set(OPENSIM_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/OpenSim")
# Location of the opensim python package in the installation.
# On Ubuntu/Debian (apt-get), would want lib/python2.7/dist-packages.
# We replace VERSION with the correct version once we know it (in
# Bindings/Python/CMakeLists.txt).
# The _LIBDIR variable might contain something like x86-64-linux-gnu on
# some systems, but for python, we really just want lib/, no matter what.
set(OPENSIM_INSTALL_PYTHONDIR "lib/pythonVERSION/site-packages")
# share/java, as expected on Ubuntu/Debian (apt-get).
set(OPENSIM_INSTALL_JAVAJARDIR "${CMAKE_INSTALL_DATAROOTDIR}/java")
# Don't want to put source files in share/java.
set(OPENSIM_INSTALL_JAVASRCDIR "${CMAKE_INSTALL_DATAROOTDIR}/OpenSim/java")
set(OPENSIM_INSTALL_CPPEXDIR "${CMAKE_INSTALL_DOCDIR}/APIExamples")
set(OPENSIM_INSTALL_SCRIPTSDIR "${CMAKE_INSTALL_DOCDIR}/Scripts")
set(OPENSIM_INSTALL_SIMBODYDIR ".")
else()
# Use our own installation layout.
# Set the variables that would have otherwise been set by GNUInstallDirs.
set(CMAKE_INSTALL_BINDIR bin)
set(CMAKE_INSTALL_INCLUDEDIR sdk/include)
set(CMAKE_INSTALL_LIBDIR sdk/lib)
set(CMAKE_INSTALL_DOCDIR sdk/doc)
# SYSCONFDIR holds read-only single-machine machine-dependent data.
set(CMAKE_INSTALL_SYSCONFDIR sdk)
set(OPENSIM_INSTALL_ARCHIVEDIR "${CMAKE_INSTALL_LIBDIR}")
set(OPENSIM_INSTALL_CMAKEDIR cmake)
set(OPENSIM_INSTALL_PYTHONDIR sdk/python)
set(OPENSIM_INSTALL_JAVAJARDIR sdk/Java)
set(OPENSIM_INSTALL_JAVASRCDIR sdk/Java)
set(OPENSIM_INSTALL_CPPEXDIR sdk/APIExamples)
set(OPENSIM_INSTALL_SCRIPTSDIR sdk/Scripts)
set(OPENSIM_INSTALL_SIMBODYDIR sdk/Simbody)
endif()
set(OPENSIM_INSTALL_MATLABEXDIR "${OPENSIM_INSTALL_SCRIPTSDIR}/Matlab")
set(OPENSIM_INSTALL_PYTHONEXDIR "${OPENSIM_INSTALL_SCRIPTSDIR}/Python")
# Cross-platform location of shared libraries. Used in configureOpenSim.m.
if(WIN32)
set(OPENSIM_INSTALL_SHAREDLIBDIR "${CMAKE_INSTALL_BINDIR}")
else()
set(OPENSIM_INSTALL_SHAREDLIBDIR "${CMAKE_INSTALL_LIBDIR}")
endif()
# On UNIX, be careful about installing into system directories.
# -------------------------------------------------------------
get_filename_component(ABS_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" REALPATH)
if(UNIX AND ("${ABS_INSTALL_PREFIX}" STREQUAL "/usr" OR
"${ABS_INSTALL_PREFIX}" STREQUAL "/usr/local"))
set(no_name_conflict ${BUILD_API_ONLY} OR NOT ${OPENSIM_BUILD_INDIVIDUAL_APPS})
if(${OPENSIM_INSTALL_UNIX_FHS} AND ${no_name_conflict})
# In this case it's fine to install into /usr or /usr/local.
else()
message(SEND_ERROR "
Cannot install into /usr or /usr/local if the OpenSim installation does
not conform to the UNIX Filesystem Hierarchy Standard or if building
the old command-line applications (there are name conflicts with vital
UNIX executables). Either (a) set OPENSIM_INSTALL_UNIX_FHS to ON, or
(b) change CMAKE_INSTALL_PREFIX.")
endif()
endif()
# Platform.
# ---------
# Create a platform name useful for finding things in the Platform
# directory.
if(WIN32)
set(PLATFORM_NAME Windows)
elseif(APPLE)
set(PLATFORM_NAME Mac)
elseif(UNIX)
set(PLATFORM_NAME Linux)
else()
set(PLATFORM_NAME Unknown)
endif()
# In addition to the platform name we need to know the Application Binary
# Interface (ABI) we're building for. Currently that is either x86, meaning
# 32 bit Intel instruction set, or x64 for 64 bit Intel instruction set.
# Kevin: Since Ubuntu 12 64bit libraries are in lib not lib64 (This in
# response of Sherm's change on Simbody)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PLATFORM_ABI x64)
else()
set(PLATFORM_ABI x86)
endif()
set(BUILD_PLATFORM "${PLATFORM_NAME}:${PLATFORM_ABI}" CACHE STRING
"This is the platform and ABI we're building for. Not changeable here; use a different CMake generator instead."
FORCE)
if(NOT MSVC AND NOT XCODE AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo 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()
## Choose the maximum level of x86 instruction set that the compiler is
## allowed to use. Was using sse2 but changed to let the compilers choose. Most
## will probably use sse2 or later by default.
## On 64 bit MSVC, the default is sse2 and the argument
## isn't recognized so we won't specify it.
if(CMAKE_CL_64)
set(default_build_inst_set)
else()
# Here's where we used to set sse2. Leaving this line in
# case we decide to specify a default value again.
set(default_build_inst_set)
endif()
## This can be set to a different value by the person running CMake.
set(BUILD_INST_SET ""
CACHE STRING
"CPU instruction level compiler is permitted to use (default: let compiler decide).")
mark_as_advanced( BUILD_INST_SET )
if(BUILD_INST_SET)
set(inst_set_to_use ${BUILD_INST_SET})
else()
set(inst_set_to_use ${default_build_inst_set})
endif()
## When building in any of the Release modes, tell gcc to use not-quite most
## aggressive optimization and to generate SSE2 floating point instructions.
## Here we are specifying *all* of the Release flags, overriding CMake's
## defaults. Watch out for optimizer bugs in particular gcc versions!
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU" OR
${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
if(inst_set_to_use)
string(TOLOWER ${inst_set_to_use} GCC_INST_SET)
set(GCC_INST_SET "-m${GCC_INST_SET}")
else()
set(GCC_INST_SET)
endif()
# Get the gcc version number in major.minor.build format
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION)
# Testing with Clang 3.3 on Ubuntu 14.04 shows a 5% decrease
# in the runtime of the tests when we enable loop unrolling.
set(GCC_OPT_ENABLE "-funroll-loops")
# If you know of optimization bugs that affect SimTK in particular
# gcc versions, this is the place to turn off those optimizations.
set(GCC_OPT_DISABLE)
# C++
set(CMAKE_CXX_FLAGS_DEBUG "-g ${GCC_INST_SET}"
CACHE STRING "g++ Debug build compile flags" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE
"-DNDEBUG -O2 ${GCC_OPT_ENABLE} ${GCC_OPT_DISABLE} ${GCC_INST_SET}"
CACHE STRING "g++ Release build compile flags" FORCE)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"-DNDEBUG -O2 -g ${GCC_OPT_ENABLE} ${GCC_OPT_DISABLE} ${GCC_INST_SET}"
CACHE STRING "g++ RelWithDebInfo build compile flags" FORCE)
set(CMAKE_CXX_FLAGS_MINSIZEREL "-DNDEBUG -Os ${GCC_INST_SET}"
CACHE STRING "g++ MinSizeRel build compile flags" FORCE)
# C
set(CMAKE_C_FLAGS_DEBUG "-g ${GCC_INST_SET}"
CACHE STRING "gcc Debug build compile flags" FORCE)
set(CMAKE_C_FLAGS_RELEASE
"-DNDEBUG -O2 ${GCC_OPT_ENABLE} ${GCC_OPT_DISABLE} ${GCC_INST_SET}"
CACHE STRING "gcc Release build compile flags" FORCE)
set(CMAKE_C_FLAGS_RELWITHDEBINFO
"-DNDEBUG -O2 -g ${GCC_OPT_ENABLE} ${GCC_OPT_DISABLE} ${GCC_INST_SET}"
CACHE STRING "gcc RelWithDebInfo build compile flags" FORCE)
set(CMAKE_C_FLAGS_MINSIZEREL "-DNDEBUG -Os ${GCC_INST_SET}"
CACHE STRING "gcc MinSizeRel build compile flags" FORCE)
endif()
## When building in any of the Release modes, tell VC++ cl compiler to use intrinsics
## (i.e. sqrt instruction rather than sqrt subroutine) with flag /Oi.
if(WIN32 AND ${CMAKE_C_COMPILER} MATCHES "cl")
if(inst_set_to_use)
string(TOUPPER ${inst_set_to_use} CL_INST_SET)
set(CL_INST_SET "/arch:${CL_INST_SET}")
else()
set(CL_INST_SET)
endif()
set(BUILD_LIMIT_PARALLEL_COMPILES "" CACHE STRING
"Set a maximum number of simultaneous compilations.")
mark_as_advanced(BUILD_LIMIT_PARALLEL_COMPILES)
set(mxcpu ${BUILD_LIMIT_PARALLEL_COMPILES}) # abbreviation
## C++
# Disable "C4068: unknown pragma" warning.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4068")
set(CMAKE_CXX_FLAGS_DEBUG
"/MP${mxcpu} /D _DEBUG /MDd /Od /Ob0 /RTC1 /Zi /bigobj /GS- ${CL_INST_SET}"
CACHE STRING "VC++ Debug build compile flags" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE
"/MP${mxcpu} /D NDEBUG /MD /O2 /Ob2 /Oi /bigobj /GS- ${CL_INST_SET}"
CACHE STRING "VC++ Release build compile flags" FORCE)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
"/MP${mxcpu} /D NDEBUG /MD /O2 /Ob2 /Oi /Zi /bigobj /GS- ${CL_INST_SET}"
CACHE STRING "VC++ RelWithDebInfo build compile flags" FORCE)
set(CMAKE_CXX_FLAGS_MINSIZEREL
"/MP${mxcpu} /D NDEBUG /MD /O1 /Ob1 /Oi /bigobj /GS- ${CL_INST_SET}"
CACHE STRING "VC++ MinSizeRel build compile flags" FORCE)
## C
set(CMAKE_C_FLAGS_DEBUG
"/MP${mxcpu} /D _DEBUG /MDd /Od /Ob0 /RTC1 /Zi /GS- ${CL_INST_SET}"
CACHE STRING "VC++ Debug build compile flags" FORCE)
set(CMAKE_C_FLAGS_RELEASE
"/MP${mxcpu} /D NDEBUG /MD /O2 /Ob2 /Oi /GS- ${CL_INST_SET}"
CACHE STRING "VC++ Release build compile flags" FORCE)
set(CMAKE_C_FLAGS_RELWITHDEBINFO
"/MP${mxcpu} /D NDEBUG /MD /O2 /Ob2 /Oi /Zi /GS- ${CL_INST_SET}"
CACHE STRING "VC++ RelWithDebInfo build compile flags" FORCE)
set(CMAKE_C_FLAGS_MINSIZEREL
"/MP${mxcpu} /D NDEBUG /MD /O1 /Ob1 /Oi /GS- ${CL_INST_SET}"
CACHE STRING "VC++ MinSizeRel build compile flags" FORCE)
endif()
set(BUILD_JAVA_WRAPPING OFF CACHE BOOL "Build Java wrapping (needed if you're building the GUI or the Matlab wrapping; requires that you have SWIG and Java installed on your machine.)")
set(BUILD_PYTHON_WRAPPING OFF CACHE BOOL "Build Python wrapping (needed if you're building the Python wrapping; requires that you have SWIG and Python installed on your machine.)")
if(${BUILD_JAVA_WRAPPING})
# If we can find a MATLAB installation, we'll try to run some MATLAB tests.
# To print info on where MATLAB is found: set(MATLAB_FIND_DEBUG ON)
# Running tests requires that we can find the matlab executable (component
# MAIN_PROGRAM).
# Also, the mechanism we use to set the java classpath and library path
# for MATLAB requires version 7.0 (R14).
find_package(Matlab 7.0 COMPONENTS MAIN_PROGRAM)
# Issue warning if Matlab and OpenSim build architectures differ.
# That is, one is 64-bit and other is not.
if(Matlab_FOUND)
if(${Matlab_MEX_EXTENSION} MATCHES "64")
# On Unix, assume host architecture to be same as target
# architecture.
if(UNIX AND NOT ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "64")
string(CONCAT MSG
"Matlab found is 64-bit but host is 32-bit. Matlab arch"
" and OpenSim binaries arch have to be same.")
message(WARNING ${MSG})
elseif(MSVC AND NOT ${CMAKE_GENERATOR} MATCHES "64")
string(CONCAT MSG
"Matlab found is 64-bit but C++ compiler chosen is "
"32-bit. Matlab arch and OpenSim binaries arch have"
" to be same.")
message(WARNING ${MSG})
endif()
elseif(${Matlab_MEX_EXTENSION} MATCHES "32")
# On Unix, assume host architecture to be same as target
# architecture.
if(UNIX AND ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "64")
string(CONCAT MSG
"Matlab found is 32-bit but host is 64-bit. Matlab arch"
" and OpenSim binaries arch have to be same.")
message(WARNING ${MSG})
elseif(MSVC AND ${CMAKE_GENERATOR} MATCHES "64")
string(CONCAT MSG
"Matlab found is 32-bit but C++ compiler chosen is "
"64-bit. Matlab arch and OpenSim binaries arch have"
" to be same.")
message(WARNING ${MSG})
endif()
endif()
endif()
endif()
if(${BUILD_PYTHON_WRAPPING})
# PythonInterp is supposed to come before PythonLibs.
find_package(PythonInterp 2.7 REQUIRED)
# We update the python install dir to include the python version,
# now that we know it. We replace the token "VERSION" with the actual python
# version.
set(python_version_majmin "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
string(REPLACE "VERSION" "${python_version_majmin}"
OPENSIM_INSTALL_PYTHONDIR "${OPENSIM_INSTALL_PYTHONDIR}")
# This must be done before adding the OpenSim libraries, since
# OPENSIM_INSTALL_PYTHONDIR is used in OpenSimAddLibrary (in
# OpenSimMacros.cmake).
if(APPLE)
# If you have Homebrew's Python, then by default, PythonInterp finds
# Apple's Python, but PythonLibs finds Homebrew's Python, causing
# runtime crashes. This also occurs if one has Anaconda Python.
# So we use the python-config executable to get the
# correct library and include directory.
# https://github.com/Homebrew/legacy-homebrew/issues/25118
execute_process(COMMAND "${PYTHON_EXECUTABLE}-config" --prefix
OUTPUT_VARIABLE python_prefix
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(CONCAT pyinc_desc
"Location of Python header files, to compile bindings. "
"Must be consistent with PYTHON_EXECUTABLE.")
set(PYTHON_INCLUDE_DIR
"${python_prefix}/include/python${python_version_majmin}/"
CACHE PATH "${pyinc_desc}")
string(CONCAT pylib_desc
"Location of Python library, to compile bindings. "
"Must be consistent with PYTHON_EXECUTABLE.")
set(PYTHON_LIBRARY
"${python_prefix}/lib/libpython${python_version_majmin}.dylib"
CACHE FILEPATH "${pylib_desc}")
endif()
find_package(PythonLibs 2.7 REQUIRED)
endif()
if(WIN32)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
endif()
include(InstallRequiredSystemLibraries)
# C++11
# -----
# In revision 8629, we started using std::unique_ptr, which requires
# C++11 features to be enabled when using GCC or Clang.
if(${CMAKE_C_COMPILER} MATCHES "cc" OR ${CMAKE_C_COMPILER} MATCHES "clang")
# Using C++11 on OSX requires using libc++ instead of libstd++.
# libc++ is an implementation of the C++ standard library for OSX.
if(APPLE)
if(XCODE)
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif()
else() # not APPLE
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif()
## RPATH
# If it is necessary to not put RPATHs in the installed binaries, set
# CMAKE_SKIP_INSTALL_RPATH to OFF.
set(OPENSIM_USE_INSTALL_RPATH FALSE)
if(UNIX) # Linux and macOS
# CMake 2.8.12 introduced the ability to set RPATH for shared libraries
# on OSX. This helps executables find the libraries they depend on
# without having to set the DYLD_LIBRARY_PATH environment variable.
# See http://www.cmake.org/Wiki/CMake_RPATH_handling and `man dydl`.
# We have attempted to make the RPATH work even if the
# installation is relocated (using relative paths), but you may need to
# use DYLD_LIBRARY_PATH (or alter the RPATH using install_name_tool) in
# these cases.
## On Linux, this variable has no effect.
set(CMAKE_MACOSX_RPATH ON)
if(NOT OPENSIM_COPY_DEPENDENCIES)
# Add the automatically determined parts of the RPATH which point
# to directories outside the build tree to the install RPATH.
# If we are copying Simbody into OpenSim's installation, then
# there's no need to link to the libraries in Simbody's or BTK's
# original installations. Furthermore, we may be distributing OpenSim
# to other computers that will not have our original Simbody or BTK
# installations, and so the RPATH would point to a nonexistant
# directory on others' computers.
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
# Set RPATH so that OpenSim can find its own libraries, but only if
# OpenSim is not installed into a system library directory.
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(OPENSIM_USE_INSTALL_RPATH TRUE)
endif()
endif()
set(OPENSIM_DEPENDENCIES_DIR
""
CACHE
PATH
"Directory containing installed binaries of OpenSim dependencies. Set this
only if you used the Superbuild procedure to install dependencies. ")
set(WITH_BTK
OFF
CACHE
BOOL
"Compile OpenSim with BTK ? BTK provides C3D reading.")
# If compiling with BTK, find and use it.
if(WITH_BTK)
find_package(BTK
REQUIRED
HINTS "${OPENSIM_DEPENDENCIES_DIR}/BTK/share/btk-0.4dev")
include(${BTK_USE_FILE})
add_definitions(-DWITH_BTK)
OpenSimCopyDependencyDLLsForWin(BTK ${BTK_INSTALL_PREFIX})
if(BUILD_PYTHON_WRAPPING AND OPENSIM_PYTHON_STANDALONE)
OpenSimInstallDependencyLibraries(BTK "${BTK_INSTALL_PREFIX}"
"${BTK_LIBRARY_DIRS}" "${OPENSIM_INSTALL_PYTHONDIR}/opensim")
endif()
endif()
if(NOT SIMBODY_HOME AND OPENSIM_DEPENDENCIES_DIR)
set(SIMBODY_HOME "${OPENSIM_DEPENDENCIES_DIR}/simbody")
endif()
# Find Simbody.
# -------------
# As of Simbody 3.4, Simbody has a SimbodyConfig.cmake file, which is a
# preferred way to find Simbody over the previous FindSimbody.cmake script.
# NO_MODULE means we will not allow the use of a FindSimbody.cmake script.
set(SIMBODY_VERSION_TO_USE 3.6)
# Find Simbody freshly by unsetting this CMake-generated variable.
unset(Simbody_DIR CACHE)
if("${SIMBODY_HOME}" STREQUAL "")
# We assume the only case in which the user
# wants us to search for Simbody is if they left SIMBODY_HOME empty.
# If the user specifies an invalid SIMBODY_HOME by accident,
# we shouldn't let that fail silently and still search for
# Simbody elsewhere; they may never realize
# we are not using their requested installation of Simbody.
find_package(Simbody ${SIMBODY_VERSION_TO_USE}
NO_MODULE)
else()
# Find the package using the user-specified path.
# NO_DEFAULT_PATH will cause find_package to only
# look in the provided PATHS.
find_package(Simbody ${SIMBODY_VERSION_TO_USE}
PATHS "${SIMBODY_HOME}" NO_MODULE NO_DEFAULT_PATH)
endif()
# This variable appears in the CMake GUI and could confuse users,
# since this variable can't be changed manually.
mark_as_advanced(Simbody_DIR)
# If Simbody is not found, Simbody_FOUND is false.
if(NOT Simbody_FOUND)
message(FATAL_ERROR "
Simbody ${SIMBODY_VERSION_TO_USE} not found. Install Simbody and set
SIMBODY_HOME to the installation directory of Simbody.")
endif()
# Check if Simbody targets were built using same BUILD_TYPE/CONFIGURATION as
# current OpenSim build. If build/configuration types mismatch, stop the build.
# ------------------------------------------------------------------------------
get_property(Simbody_CONFIGURATION
TARGET SimTKcommon
PROPERTY IMPORTED_CONFIGURATIONS)
string(CONCAT MESSAGE
"Checking if Simbody was built with same BUILD_TYPE or CONFIGURATION as "
"the current OpenSim BUILD_TYPE or CONFIGURATION.")
if(${PLATFORM_NAME} STREQUAL Windows)
string(TOLOWER "${Simbody_CONFIGURATION}" Simbody_CONFIGURATION_STR)
add_custom_target(Simbody_CONFIG_check ALL
COMMAND "set" "Simbody_CONFIG=${Simbody_CONFIGURATION_STR}"
COMMAND "if"
"\"%Simbody_CONFIG:$<LOWER_CASE:$<CONFIG>>=%\"==\"%Simbody_CONFIG%\""
"exit" "1"
COMMENT ${MESSAGE})
elseif(${PLATFORM_NAME} STREQUAL Mac OR ${PLATFORM_NAME} STREQUAL Linux)
string(TOLOWER "${Simbody_CONFIGURATION}" Simbody_CONFIGURATION_STR)
string(CONCAT CONTENT "if [[ $1 != *\"$2\"* ]]\; then\n"
"exit 1\n"
"fi\n")
file(WRITE "${CMAKE_BINARY_DIR}/simbody_config_check.sh" ${CONTENT})
add_custom_target(Simbody_CONFIG_check ALL
COMMAND "bash" "simbody_config_check.sh"
"\"${Simbody_CONFIGURATION_STR}\"" "\"$<LOWER_CASE:$<CONFIG>>\""
COMMENT ${MESSAGE})
endif()
# Copy Simbody DLLs to build tree.
# --------------------------------
# On Windows, we must copy Simbody libraries to the OpenSim build directory
# so that the tests and examples can run without modifying the PATH
# (that is, put Simbody's dll's in the same directory as OpenSim's
# executables and libraries).
OpenSimCopyDependencyDLLsForWin(Simbody "${Simbody_BIN_DIR}")
if(WIN32)
add_dependencies(Copy_Simbody_DLLs Simbody_CONFIG_check)
endif()
# Directories for Simbody headers and libraries for building.
# -----------------------------------------------------------
# TODO no longer necessary; Simbody's library targets provide the
# include directories.
include_directories("${Simbody_INCLUDE_DIR}")
# Installing dependencies into OpenSim's installation.
# ----------------------------------------------------
if(${OPENSIM_COPY_DEPENDENCIES})
if(WIN32)
# The issue with install(DIRECTORY) is that it creates directories in
# the installation for *every* directory in DIRECTORY, even if that
# dirctory doesn't contain any files matching the provided
# pattern/regex.
# We can safely assume that Simbody is installed in an isolated
# dirctory; therefore, it should be safe to use install(DIRECTORY).
# This may not be true with conda or chocolatey.
install(DIRECTORY "${Simbody_ROOT_DIR}/"
DESTINATION "${OPENSIM_INSTALL_SIMBODYDIR}"
FILES_MATCHING PATTERN "*SimTK*.dll")
install(DIRECTORY "${Simbody_ROOT_DIR}/"
DESTINATION "${OPENSIM_INSTALL_SIMBODYDIR}"
# There's no need to install Simbody examples or docs.
PATTERN "*examples/*" EXCLUDE
PATTERN "*doc/*" EXCLUDE
# Don't copy lapack, blas, etc. into sdk/Simbody/bin/; they are
# already copied into bin/.
PATTERN "*.dll" EXCLUDE
PATTERN "*.exe" EXCLUDE)
# DLLs are handled by OpenSimCopyDependencyDLLsForWin(), but we still
# need to copy simbody-visualizer.exe.
install(DIRECTORY "${Simbody_BIN_DIR}/"
DESTINATION "${CMAKE_INSTALL_BINDIR}"
FILES_MATCHING PATTERN "*.exe")
# TODO We are copying Simbody DLLs to both the bin and sdk/Simbody/bin
# folders; we would prefer to only copy to the former, but
# SimbodyTargets-*.cmake expect dlls in sdk/Simbody/bin. In the future,
# we can edit the *.cmake files to no longer expect these DLLs.
else()
# We would have liked to use install(DIRECTORY) on UNIX, but the
# dependencies may be installed in system-wide locations and we don't
# want to copy extraneous files/directories; install(DIRECTORY) creates
# a directory in DESTINATION for *every* directory in DIRECTORY, even
# if we do not want to copy any files from some of the directories in
# DIRECTORY.
# include
file(RELATIVE_PATH install_simbodyincludedir
"${Simbody_ROOT_DIR}" "${Simbody_INCLUDE_DIR}")
install(DIRECTORY "${Simbody_INCLUDE_DIR}/"
DESTINATION "${OPENSIM_INSTALL_SIMBODYDIR}/${install_simbodyincludedir}")
# lib (and cmake, pkgconfig)
file(RELATIVE_PATH install_simbodylibdir
"${Simbody_ROOT_DIR}/" "${Simbody_LIB_DIR}/")
file(GLOB_RECURSE simbody_desired_lib_files
RELATIVE "${Simbody_LIB_DIR}"
"${Simbody_LIB_DIR}/*SimTK*" "${Simbody_LIB_DIR}/*Simbody*.cmake"
"${Simbody_LIB_DIR}/*SampleCMakeLists.txt*")
foreach(simbody_lib_file ${simbody_desired_lib_files})
get_filename_component(subdir "${simbody_lib_file}" DIRECTORY)
install(FILES "${Simbody_LIB_DIR}/${simbody_lib_file}"
DESTINATION "${OPENSIM_INSTALL_SIMBODYDIR}/${install_simbodylibdir}/${subdir}")
endforeach()
# simbody-visualizer
file(RELATIVE_PATH install_simbodyvizdir
"${Simbody_ROOT_DIR}" "${Simbody_VIZ_DIR}")
install(DIRECTORY "${Simbody_VIZ_DIR}/"
DESTINATION "${OPENSIM_INSTALL_SIMBODYDIR}/${install_simbodyvizdir}"
USE_SOURCE_PERMISSIONS
FILES_MATCHING PATTERN "*simbody-visualizer*")
endif()
# BTK
# ---
if(WIN32)
file(GLOB btk_desired_dll_files "${BTK_INSTALL_DIR}/*BTK*.dll")
install(FILES ${btk_desired_dll_files}
DESTINATION "${CMAKE_INSTALL_BINDIR}")
# No need to copy *.lib on Windows, as BTK links "privately" to
# osimCommon (clients of osimCommon do not link to BTK).
else()
# LIB: .so files on Linux, .dylib on macOS
file(GLOB btk_desired_lib_files "${BTK_LIBRARY_DIRS}/*BTK*")
install(FILES ${btk_desired_lib_files}
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif()
endif()
if(BUILD_PYTHON_WRAPPING AND OPENSIM_PYTHON_STANDALONE)
OpenSimInstallDependencyLibraries(SimTK "${Simbody_BIN_DIR}"
"${Simbody_LIB_DIR}" "${OPENSIM_INSTALL_PYTHONDIR}/opensim")
endif()
# Other than Windows we can debug without debuggable SimTK libraries
if(WIN32)
set(CMAKE_DEBUG_POSTFIX "_d" CACHE INTERNAL "" FORCE)
else(WIN32)
set(CMAKE_DEBUG_POSTFIX "_d" CACHE STRING "Suffix for debug libraries")
endif(WIN32)
## The following are required to uses Dart and the Cdash dashboard per Jesse
enable_testing()
include(CTest)
# Sets the number of concurrent jobs that testing can use.
if(MSVC OR XCODE)
set(OPENSIM_TEST_BUILD_CONFIG --build-config ${CMAKE_CFG_INTDIR})
endif()
add_custom_target(RUN_TESTS_PARALLEL
COMMAND ${CMAKE_CTEST_COMMAND} --parallel ${PROCESSOR_COUNT}
${OPENSIM_TEST_BUILD_CONFIG}
--output-on-failure
)
# Create buildinfo.txt file and place under sdk to include product version,
# platform and compiler for troubleshooting purposes
set(VERSION_FILE_PATH ${CMAKE_BINARY_DIR}/OpenSim_buildinfo.txt)
# message("version file="${VERSION_FILE_PATH})
file(WRITE ${VERSION_FILE_PATH} "Product Version=${OPENSIM_MAJOR_VERSION}.${OPENSIM_MINOR_VERSION}")
file(APPEND ${VERSION_FILE_PATH} "\n")
file(APPEND ${VERSION_FILE_PATH} "Compiler=${CMAKE_GENERATOR}-${CMAKE_CXX_COMPILER_ID}")
file(APPEND ${VERSION_FILE_PATH} "\n")
file(APPEND ${VERSION_FILE_PATH} "Platform=${PLATFORM_NAME}-${PLATFORM_ABI}")
file(APPEND ${VERSION_FILE_PATH} "\n")
install(FILES ${VERSION_FILE_PATH} DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}")
# Preprocessor definitions.
# -------------------------
# These are used in OpenSim/version.h
set(OPENSIM_SYSTEM_INFO ${CMAKE_SYSTEM})
set(OPENSIM_OS_NAME ${CMAKE_SYSTEM_NAME})
if( WIN32 )
if (${MSVC_VERSION} GREATER 1910)
message(AUTHOR_WARNING "OpenSim::GetCompilerVersion() "
"in OpenSim/version.h does not handle this newer version "
"(v${MSVC_VERSION}) of Microsoft Visual C++. "
"Update OpenSim/version.h and the condition for this warning "
"in the root CMakeLists.txt.")
endif()
set(OPENSIM_COMPILER_INFO ${MSVC_VERSION})
else()
set(OPENSIM_COMPILER_INFO ${CMAKE_CXX_COMPILER} )
endif()
add_definitions(-DOSIM_SYS_INFO=${OPENSIM_SYSTEM_INFO}
-DOSIM_COMPILER_INFO=${OPENSIM_COMPILER_INFO}
-DOSIM_OS_NAME=${OPENSIM_OS_NAME}
-DOSIM_VERSION=${OPENSIM_VERSION})
#-----------------------------------------------------------------------------
# This directory contains files (e.g., .osim) that multiple tests may want to
# use. See the OpenSimCopySharedTestFiles function in
# cmake/OpenSimMacros.cmake.
set(OPENSIM_SHARED_TEST_FILES_DIR "${CMAKE_SOURCE_DIR}/OpenSim/Tests/shared")
add_subdirectory(Vendors)
add_subdirectory(OpenSim)
if(NOT BUILD_API_ONLY)
add_subdirectory(Applications)
endif()
add_subdirectory(Bindings)
add_subdirectory(cmake)
add_subdirectory(doc)