From 732d3674c6998b43639be40ffea699cbfde1ff83 Mon Sep 17 00:00:00 2001 From: zaikunzhang Date: Sat, 17 Feb 2024 03:15:38 +0800 Subject: [PATCH] 240217.031538.HKT revise `linker_options` in compile.m --- CMakeLists.txt | 6 +++--- matlab/setup_tools/compile.m | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4fcc9dfcf..35c43fd822 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,8 +37,8 @@ if (PRIMA_HEAP_ARRAYS) endif () # Set additional linker flags -# Zaikun 20230217: Fix https://github.com/libprima/prima/issues/158, which is due to the new linker -# implemented in Xcode 15 on macOS. It happens only if the Fortran compiler is ifort. +# Zaikun 20240217: Fix https://github.com/libprima/prima/issues/158, which is due to the new linker +# implemented in Xcode 15 on macOS. It happens only if the Fortran compiler is ifort. # An alternative is `add_link_options("-ld_classic")`, which forces Xcode to use the old linker. # Will CMake adapt itself to the new linker later? Will a newer version of CMake make the fix unnecessary? # See @@ -95,7 +95,7 @@ else() message(WARNING "No git detected and .git-archival.txt does not contain a version number") set(PRIMA_VERSION "unknown") endif() - + endif() # Remove the leading v from PRIMA_VERSION, if it contains one. string(REGEX REPLACE "^v" "" PRIMA_VERSION ${PRIMA_VERSION}) diff --git a/matlab/setup_tools/compile.m b/matlab/setup_tools/compile.m index ebc6cdd3ce..a1c785f471 100644 --- a/matlab/setup_tools/compile.m +++ b/matlab/setup_tools/compile.m @@ -73,15 +73,16 @@ function compile(solvers, mexdir, fortd, gateways, options) % https://fortran-lang.discourse.group/t/frecursive-assume-recursion-and-recursion-thread-safety compiler_configurations = mex.getCompilerConfigurations('fortran', 'selected'); extra_compiler_options = ''; -if contains(compiler_configurations.Manufacturer, 'gnu', 'IgnoreCase', true) % gfortran +compiler_manufacturer = lower(compiler_configurations.Manufacturer); +if contains(compiler_manufacturer, 'gnu') % gfortran extra_compiler_options = '-fno-stack-arrays -frecursive'; -elseif contains(compiler_configurations.Manufacturer, 'intel', 'IgnoreCase', true) % Intel compiler +elseif contains(compiler_manufacturer, 'intel') % Intel compiler if ispc extra_compiler_options = '/heap-arrays /assume:recursion'; else extra_compiler_options = '-heap-arrays -assume recursion'; end -elseif ~contains(compiler_configurations.Manufacturer, 'nag', 'IgnoreCase', true) % NAG compiler +elseif ~contains(compiler_manufacturer, 'nag') % NAG compiler warning('prima:UnrecognizedCompiler', 'Unrecognized compiler %s. The package may not work.', ... compiler_configurations.Name); end @@ -98,8 +99,11 @@ function compile(solvers, mexdir, fortd, gateways, options) % Note that we have to modify `LDFLAGSVER`. Setting `LDFLAGS` or `LINKFLAGS` does not work, although % the latter is suggested at https://www.mathworks.com/help/matlab/ref/mex.html. linker_options = ''; -if ismac && contains(compiler_configurations.Manufacturer, 'intel', 'IgnoreCase', true) % macOS with Intel compiler - linker_options = 'LDFLAGSVER=$(echo $LDFLAGSVER | sed "s/-undefined error//g") -undefined dynamic_lookup'; +if ismac && contains(compiler_manufacturer, 'intel') % macOS with Intel compiler + [status, ~] = system('type echo && type sed'); % Check if `echo` and `sed` are available. + if status == 0 + linker_options = 'LDFLAGSVER="$(echo $LDFLAGSVER | sed "s/-undefined error//g") -undefined dynamic_lookup"'; + end end % MEX options shared by all compiling processes below.