Skip to content

Commit 00de6a9

Browse files
committed
- try and force to find shared libomp for linux, as the static one cant be linked
1 parent e5d9852 commit 00de6a9

1 file changed

Lines changed: 56 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
# we need at least cmake 2.8 for the FindLAPACK functions
3131
cmake_minimum_required(VERSION 2.8...3.19)
3232

33+
# include the CMakeDependentOption module
34+
include(CMakeDependentOption)
35+
36+
3337
if(POLICY CMP0048)
3438
cmake_policy(SET CMP0048 NEW)
3539
endif(POLICY CMP0048)
@@ -273,6 +277,15 @@ endif()
273277

274278
option(ENABLE_JIT "Enable Just In Time compilation for math expressions" ${ENABLE_JIT_DEFAULT})
275279

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+
276289
option(ENABLE_OMP "Enable the OpenMP support" OFF)
277290

278291
set(EXTRA_DEFS "" CACHE STRING
@@ -448,8 +461,51 @@ if (ENABLE_OMP)
448461
endif()
449462
endif()
450463

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+
451470
find_package (OpenMP REQUIRED)
452471

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+
453509
if (OpenMP_CXX_SPEC_DATE GREATER_EQUAL "201811")
454510
# OpenMP 5.0 will always have monotonic scheduling
455511
set(OMP_HAVE_MONOTONIC 1 CACHE INTERNAL "" FORCE)
@@ -655,16 +711,6 @@ endif(BUILD_GUI)
655711
# define what shall be build
656712
option (BUILD_CXX_EXAMPLES "Build the C++ examples." OFF)
657713

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-
668714
# we need swig for the language bindings. Only if SWIG was found, the options to
669715
# build the different language bindings are enabled
670716
# TODO test the SWIG version

0 commit comments

Comments
 (0)