@@ -12,8 +12,7 @@ dnl Copyright (c) 2004-2005 The Regents of the University of California.
1212dnl All rights reserved.
1313dnl Copyright (c) 2010-2021 Cisco Systems, Inc. All rights reserved
1414dnl Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
15- dnl Copyright (c) 2018-2021 Amazon.com, Inc. or its affiliates.
16- dnl All Rights reserved.
15+ dnl Copyright (c) 2018-2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
1716dnl Copyright (c) 2021 Triad National Security, LLC. All rights
1817dnl reserved.
1918dnl $COPYRIGHT$
@@ -604,9 +603,7 @@ AC_DEFUN([MCA_CONFIGURE_M4_CONFIG_COMPONENT],[
604603 MCA_COMPONENT_BUILD_CHECK($1 , $2 , $3 , [ should_build=$8 ] , [ should_build=0] )
605604 # Allow the component to override the build mode if it really wants to.
606605 # It is, of course, free to end up calling MCA_COMPONENT_COMPILE_MODE
607- m4_ifdef ( [ MCA_$1 _$2 _$3 _COMPILE_MODE] ,
608- [ MCA_$1 _$2 _$3 _COMPILE_MODE($1 , $2 , $3 , compile_mode)] ,
609- [ MCA_COMPONENT_COMPILE_MODE($1 , $2 , $3 , compile_mode)] )
606+ MCA_COMPONENT_COMPILE_MODE([ $1 ] , [ $2 ] , [ $3 ] , [ compile_mode] )
610607
611608 # try to configure the component
612609 m4_ifdef ( [ MCA_$1 _$2 _$3 _CONFIG] ,
@@ -706,10 +703,52 @@ AC_DEFUN([MCA_CONFIGURE_ALL_CONFIG_COMPONENTS],[
706703# MCA_COMPONENT_COMPILE_MODE(project_name (1), framework_name (2),
707704# component_name (3), compile_mode_variable (4))
708705# -------------------------------------------------------------------------
709- # set compile_mode_variable to the compile mode for the given component
706+ # set compile_mode_variable to the compile mode for the given component.
707+ # this macro will only evaluate the build mode once per configure, returning
708+ # the cached value for subsequent tests. The string is not stored in a cache
709+ # variable (ie .*_cv_.*) because cache variables would not be invalidated
710+ # based on changes to --enable-mca-dso or --enable-mca-static.
710711#
711712# NOTE: component_name may not be determined until runtime....
712713AC_DEFUN ( [ MCA_COMPONENT_COMPILE_MODE] ,[
714+ OAC_ASSERT_LITERAL([ $1 ] , [ 1] )dnl
715+ OAC_ASSERT_LITERAL([ $2 ] , [ 2] )dnl
716+
717+ AS_VAR_PUSHDEF ( [ compile_mode_cv] , [ $1 _$2 _$3 _compile_mode] ) dnl
718+ AS_VAR_SET_IF ( [ compile_mode_cv] ,
719+ [ ] ,
720+ [ AS_LITERAL_IF ( [ $3 ] ,
721+ [ m4_ifdef ( [ MCA_$1 _$2 _$3 _COMPILE_MODE] ,
722+ [ dnl We introduced caching of this check after setting the compile
723+ dnl mode by the substitute macro was common, and there was not a
724+ dnl polymorphic variable assumption in all those macros, so we use
725+ dnl a temporary with a fixed name.
726+ OPAL_VAR_SCOPE_PUSH([ component_compile_mode_tmp] )
727+ MCA_$1 _$2 _$3 _COMPILE_MODE([ $1 ] , [ $2 ] , [ $3 ] , [ component_compile_mode_tmp] )
728+ AS_VAR_COPY ( [ compile_mode_cv] , [ $component_compile_mode_tmp] )
729+ OPAL_VAR_SCOPE_POP] ,
730+ [ MCA_COMPONENT_COMPILE_MODE_INTERNAL([ $1 ] , [ $2 ] , [ $3 ] , [ compile_mode_cv] )] ) ] ,
731+ [ MCA_COMPONENT_COMPILE_MODE_INTERNAL([ $1 ] , [ $2 ] , [ $3 ] , [ compile_mode_cv] )] ) ] )
732+ AS_VAR_COPY ( [ $4 ] , [ compile_mode_cv] )
733+ AS_VAR_POPDEF ( [ compile_mode_cv] ) dnl
734+ ] )
735+
736+ # MCA_COMPONENT_COMPILE_MODE_INTERNAL(project_name (1), framework_name (2),
737+ # component_name (3), compile_mode_variable (4))
738+ # -------------------------------------------------------------------------
739+ # Determine compile mode of the given component. Prefer a static
740+ # build by default. Users can customize build mode by influencing the
741+ # component, framework, or all-up build flags. This function starts
742+ # at the most specific (component) and works its way out, looking for
743+ # a set option.
744+ #
745+ # Components can avoid calling this function by defining a macro
746+ # MCA_<project>_<framework>_<component>_COMPILE_MODE.
747+ #
748+ # NOTE: component_name may not be determined until runtime....
749+ AC_DEFUN ( [ MCA_COMPONENT_COMPILE_MODE_INTERNAL] , [
750+ OPAL_VAR_SCOPE_PUSH([ compile_mode_internal_tmp SHARED_FRAMEWORK SHARED_COMPONENT STATIC_FRAMEWORK STATIC_COMPONENT] )
751+
713752 SHARED_FRAMEWORK="$DSO_$2 "
714753 AS_VAR_COPY ( [ SHARED_COMPONENT] , [ DSO_$2 _$3 ] )
715754
@@ -720,27 +759,31 @@ AC_DEFUN([MCA_COMPONENT_COMPILE_MODE],[
720759 # there is a tie (either neither or both specified), prefer
721760 # static.
722761 if test "$STATIC_COMPONENT" = "1"; then
723- $4 =static
762+ compile_mode_internal_tmp =static
724763 elif test "$SHARED_COMPONENT" = "1"; then
725- $4 =dso
764+ compile_mode_internal_tmp =dso
726765 elif test "$STATIC_FRAMEWORK" = "1"; then
727- $4 =static
766+ compile_mode_internal_tmp =static
728767 elif test "$SHARED_FRAMEWORK" = "1"; then
729- $4 =dso
768+ compile_mode_internal_tmp =dso
730769 elif test "$STATIC_all" = "1"; then
731- $4 =static
770+ compile_mode_internal_tmp =static
732771 elif test "$DSO_all" = "1"; then
733- $4 =dso
772+ compile_mode_internal_tmp =dso
734773 else
735- $4 =static
774+ compile_mode_internal_tmp =static
736775 fi
737776
777+ AS_VAR_SET ( [ $4 ] , [ $compile_mode_internal_tmp] )
778+
738779 AC_MSG_CHECKING ( [ for MCA component $2 :$3 compile mode] )
739780 if test "$DIRECT_$2 " = "$3 " ; then
740- AC_MSG_RESULT ( [ $$4 - direct] )
781+ AC_MSG_RESULT ( [ $compile_mode_internal_tmp - direct] )
741782 else
742- AC_MSG_RESULT ( [ $$4 ] )
783+ AC_MSG_RESULT ( [ $compile_mode_internal_tmp ] )
743784 fi
785+
786+ OPAL_VAR_SCOPE_POP
744787] )
745788
746789# OPAL_MCA_STRIP_LAFILES(output_variable(1),
@@ -990,3 +1033,29 @@ AC_DEFUN([OPAL_MCA_MAKE_DIR_LIST],[
9901033 done
9911034 AC_SUBST ( $1 )
9921035] )
1036+
1037+
1038+ # OPAL_MCA_CHECK_DEPENDENCY(check project, check framework, check component,
1039+ # dependent project, dependent framework, dependent component)
1040+ # --------------------------------------------------------------------------
1041+ # Enforce that the check component does not introduce a dependency from its
1042+ # project library (ie libmpi.so or libopen-pal.so) to another component
1043+ # (ie, a common_*.so). This can happen if the check component is set to
1044+ # build static and the common library is set to build dso. If this situation
1045+ # is detected, print an error and abort configure.
1046+ AC_DEFUN ( [ OPAL_MCA_CHECK_DEPENDENCY] ,
1047+ [
1048+ OPAL_VAR_SCOPE_PUSH([ component_compile_mode dependency_compile_mode] )
1049+
1050+ MCA_COMPONENT_COMPILE_MODE([ $1 ] , [ $2 ] , [ $3 ] , [ component_compile_mode] )
1051+ MCA_COMPONENT_COMPILE_MODE([ $4 ] , [ $5 ] , [ $6 ] , [ dependency_compile_mode] )
1052+
1053+ AS_IF ( [ test "${component_compile_mode}" = "static" -a "${dependency_compile_mode}" = "dso"] ,
1054+ [ AC_MSG_ERROR ( [ Component $2 :$3 is set to build as a
1055+ static component, but its dependency $5 :$6 is set to build as
1056+ a dynamic component. This configuration is not supported. Please
1057+ either build $5 :$6 as a static component or build $2 :$3 as a dynamic
1058+ component.] ) ] )
1059+
1060+ OPAL_VAR_SCOPE_POP
1061+ ] )
0 commit comments