|
30 | 30 | # we need at least cmake 2.8 for the FindLAPACK functions |
31 | 31 | cmake_minimum_required(VERSION 2.8...3.19) |
32 | 32 |
|
| 33 | +# include the CMakeDependentOption module |
| 34 | +include(CMakeDependentOption) |
| 35 | + |
| 36 | + |
33 | 37 | if(POLICY CMP0048) |
34 | 38 | cmake_policy(SET CMP0048 NEW) |
35 | 39 | endif(POLICY CMP0048) |
@@ -273,6 +277,15 @@ endif() |
273 | 277 |
|
274 | 278 | option(ENABLE_JIT "Enable Just In Time compilation for math expressions" ${ENABLE_JIT_DEFAULT}) |
275 | 279 |
|
| 280 | +# Java, C#, and Python bindings are configured before OpenMP so Linux can |
| 281 | +# prefer a shared libomp runtime when those bindings are enabled. |
| 282 | +option(ENABLE_CSHARP "Enable language bindings for the C# language." OFF) |
| 283 | +option(ENABLE_JAVA "Enable language bindings for the Java language." OFF) |
| 284 | +option(ENABLE_PYTHON "Enable language bindings for the Python language." OFF) |
| 285 | +option (ENABLE_PERL "Enable language bindings for the Perl language." OFF) |
| 286 | +option (ENABLE_OCTAVE "Enable language bindings for the Octave language." OFF) |
| 287 | +option (ENABLE_R "Enable language bindings for the R language." OFF) |
| 288 | + |
276 | 289 | option(ENABLE_OMP "Enable the OpenMP support" OFF) |
277 | 290 |
|
278 | 291 | set(EXTRA_DEFS "" CACHE STRING |
@@ -448,8 +461,51 @@ if (ENABLE_OMP) |
448 | 461 | endif() |
449 | 462 | endif() |
450 | 463 |
|
| 464 | + # language bindings cant be linked against static libomp |
| 465 | + if (UNIX AND NOT APPLE AND (ENABLE_JAVA OR ENABLE_CSHARP OR ENABLE_PYTHON)) |
| 466 | + set(_copasi_openmp_library_suffixes "${CMAKE_FIND_LIBRARY_SUFFIXES}") |
| 467 | + set(CMAKE_FIND_LIBRARY_SUFFIXES ".so") |
| 468 | + endif() |
| 469 | + |
451 | 470 | find_package (OpenMP REQUIRED) |
452 | 471 |
|
| 472 | + if (UNIX AND NOT APPLE AND (ENABLE_JAVA OR ENABLE_CSHARP OR ENABLE_PYTHON)) |
| 473 | + # restore the original library suffixes |
| 474 | + if (DEFINED _copasi_openmp_library_suffixes) |
| 475 | + set(CMAKE_FIND_LIBRARY_SUFFIXES "${_copasi_openmp_library_suffixes}") |
| 476 | + unset(_copasi_openmp_library_suffixes) |
| 477 | + endif() |
| 478 | + |
| 479 | + if (OpenMP_omp_LIBRARY AND OpenMP_omp_LIBRARY MATCHES "\\.a$") |
| 480 | + get_filename_component(_copasi_openmp_library_dir "${OpenMP_omp_LIBRARY}" DIRECTORY) |
| 481 | + find_library(_copasi_openmp_shared_library NAMES omp HINTS "${_copasi_openmp_library_dir}" NO_DEFAULT_PATH) |
| 482 | + |
| 483 | + if (NOT _copasi_openmp_shared_library) |
| 484 | + find_library(_copasi_openmp_shared_library NAMES omp) |
| 485 | + endif() |
| 486 | + |
| 487 | + if (_copasi_openmp_shared_library) |
| 488 | + set(OpenMP_omp_LIBRARY "${_copasi_openmp_shared_library}" CACHE FILEPATH "Path to the OpenMP omp library." FORCE) |
| 489 | + |
| 490 | + if (TARGET OpenMP::OpenMP_CXX) |
| 491 | + set_target_properties(OpenMP::OpenMP_CXX PROPERTIES |
| 492 | + IMPORTED_LOCATION "${_copasi_openmp_shared_library}" |
| 493 | + IMPORTED_LOCATION_RELEASE "${_copasi_openmp_shared_library}") |
| 494 | + endif() |
| 495 | + |
| 496 | + if (TARGET OpenMP::OpenMP_C) |
| 497 | + set_target_properties(OpenMP::OpenMP_C PROPERTIES |
| 498 | + IMPORTED_LOCATION "${_copasi_openmp_shared_library}" |
| 499 | + IMPORTED_LOCATION_RELEASE "${_copasi_openmp_shared_library}") |
| 500 | + endif() |
| 501 | + |
| 502 | + message(STATUS "OpenMP omp library for language bindings: ${_copasi_openmp_shared_library}") |
| 503 | + else() |
| 504 | + message(WARNING "COPASI language bindings require a shared OpenMP runtime (libomp.so), but only ${OpenMP_omp_LIBRARY} was found.") |
| 505 | + endif() |
| 506 | + endif() |
| 507 | + endif() |
| 508 | + |
453 | 509 | if (OpenMP_CXX_SPEC_DATE GREATER_EQUAL "201811") |
454 | 510 | # OpenMP 5.0 will always have monotonic scheduling |
455 | 511 | set(OMP_HAVE_MONOTONIC 1 CACHE INTERNAL "" FORCE) |
@@ -655,16 +711,6 @@ endif(BUILD_GUI) |
655 | 711 | # define what shall be build |
656 | 712 | option (BUILD_CXX_EXAMPLES "Build the C++ examples." OFF) |
657 | 713 |
|
658 | | -include(CMakeDependentOption) |
659 | | - |
660 | | -# for the language bindings we need swig |
661 | | -option (ENABLE_CSHARP "Enable language bindings for the C# language." OFF) |
662 | | -option (ENABLE_JAVA "Enable language bindings for the Java language." OFF) |
663 | | -option (ENABLE_PYTHON "Enable language bindings for the Python language." OFF) |
664 | | -option (ENABLE_PERL "Enable language bindings for the Perl language." OFF) |
665 | | -option (ENABLE_OCTAVE "Enable language bindings for the Octave language." OFF) |
666 | | -option (ENABLE_R "Enable language bindings for the R language." OFF) |
667 | | - |
668 | 714 | # we need swig for the language bindings. Only if SWIG was found, the options to |
669 | 715 | # build the different language bindings are enabled |
670 | 716 | # TODO test the SWIG version |
|
0 commit comments