Imported Upstream version 1.72.0
[platform/upstream/boost.git] / tools / boost_install / boost-install.jam
index 4a8009e..ad19f7b 100644 (file)
@@ -21,6 +21,7 @@ import ./boost-install-dirs ;
 
 feature.feature library-type : : free ;
 feature.feature boost-install.dependency : : free ;
+feature.feature boost-install.cmakedir : : free ;
 feature.feature boost-install.includedir : : free ;
 feature.feature boost-install.libdir : : free ;
 
@@ -267,6 +268,29 @@ rule generate-cmake-variant- ( target : sources * : properties * )
 
     print.text "# threading=$(threading)" "" : true ;
 
+    if $(threading) = "multi"
+    {
+        print.text
+
+            "if(NOT \"${Boost_USE_MULTITHREADED}\" STREQUAL \"\" AND NOT Boost_USE_MULTITHREADED)"
+            "  _BOOST_SKIPPED(\"$(fname)\" \"multithreaded, Boost_USE_MULTITHREADED=${Boost_USE_MULTITHREADED}\")"
+            "  return()"
+            "endif()"
+            ""
+            : true ;
+    }
+    else
+    {
+        print.text
+
+            "if(Boost_USE_MULTITHREADED)"
+            "  _BOOST_SKIPPED(\"$(fname)\" \"single-threaded, Boost_USE_MULTITHREADED=${Boost_USE_MULTITHREADED}\")"
+            "  return()"
+            "endif()"
+            ""
+            : true ;
+    }
+
     print.text "# variant=$(variant)" "" : true ;
 
     if $(variant) = debug
@@ -480,15 +504,23 @@ rule generate-cmake-variant ( project name : property-set : sources * )
 
 # generate-cmake-config-
 
+local rule path-native-fwd ( path )
+{
+    path = [ path.native $(path) ] ;
+
+    if [ os.name ] = NT
+    {
+        path = $(path:T) ;
+    }
+
+    return $(path) ;
+}
+
 local rule get-dir ( name : dir )
 {
     if [ path.is-rooted $(dir) ]
     {
-        if [ os.name ] = NT
-        {
-            dir = [ path.native $(dir) ] ;
-            dir = [ regex.replace $(dir) \\\\ / ] ;
-        }
+        dir = [ path-native-fwd $(dir) ] ;
 
         print.text
 
@@ -523,6 +555,9 @@ rule generate-cmake-config- ( target : sources * : properties * )
     local library-type = [ $(ps).get <library-type> ] ;
     .info "  library-type=" $(library-type) ;
 
+    local cmakedir = [ $(ps).get <boost-install.cmakedir> ] ;
+    .info "  cmakedir=" $(cmakedir) ;
+
     local includedir = [ $(ps).get <boost-install.includedir> ] ;
     .info "  includedir=" $(includedir) ;
 
@@ -550,9 +585,31 @@ rule generate-cmake-config- ( target : sources * : properties * )
         "endif()"
         ""
         "# Compute the include and library directories relative to this file."
+        ""
         "get_filename_component(_BOOST_CMAKEDIR \"${CMAKE_CURRENT_LIST_DIR}/../\" ABSOLUTE)"
         : true ;
 
+    if [ path.is-rooted $(cmakedir) ]
+    {
+        local cmakedir-native = [ path-native-fwd $(cmakedir) ] ;
+
+        print.text
+
+            ""
+            "# If the computed and the original directories are symlink-equivalent, use original"
+            "if(EXISTS \"$(cmakedir-native)\")"
+            "  get_filename_component(_BOOST_CMAKEDIR_COMPUTED \"${_BOOST_CMAKEDIR}\" REALPATH)"
+            "  get_filename_component(_BOOST_CMAKEDIR_ORIGINAL \"$(cmakedir-native)\" REALPATH)"
+            "  if(_BOOST_CMAKEDIR_COMPUTED STREQUAL _BOOST_CMAKEDIR_ORIGINAL)"
+            "    set(_BOOST_CMAKEDIR \"$(cmakedir-native)\")"
+            "  endif()"
+            "  unset(_BOOST_CMAKEDIR_COMPUTED)"
+            "  unset(_BOOST_CMAKEDIR_ORIGINAL)"
+            "endif()"
+            ""
+            : true ;
+    }
+
     get-dir "_BOOST_INCLUDEDIR" : $(includedir) ;
     get-dir "_BOOST_LIBDIR" : $(libdir) ;
 
@@ -560,6 +617,7 @@ rule generate-cmake-config- ( target : sources * : properties * )
 
         ""
         "# Create imported target $(ltarget)"
+        ""
         "add_library($(ltarget) $(library-type) IMPORTED)"
         ""
         "set_target_properties($(ltarget) PROPERTIES"
@@ -667,6 +725,33 @@ rule generate-cmake-config- ( target : sources * : properties * )
             ""
             : true ;
         }
+
+        if $(name) = boost_mpi
+        {
+            print.text
+
+            "include(CMakeFindDependencyMacro)"
+            "find_dependency(MPI)"
+            ""
+            "if(MPI_CXX_FOUND AND NOT TARGET MPI::MPI_CXX)"
+            "  if(MPI_CXX_COMPILE_FLAGS)"
+            "    set_property(TARGET $(ltarget) APPEND PROPERTY INTERFACE_COMPILE_OPTIONS \"${MPI_CXX_COMPILE_FLAGS}\")"
+            "  endif()"
+            "  if(MPI_CXX_INCLUDE_PATH)"
+            "    set_property(TARGET $(ltarget) APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES \"${MPI_CXX_INCLUDE_PATH}\")"
+            "  endif()"
+            "  if(MPI_CXX_LINK_FLAGS)"
+            "    set_property(TARGET $(ltarget) APPEND PROPERTY INTERFACE_LINK_OPTIONS \"SHELL:${MPI_CXX_LINK_FLAGS}\")"
+            "  endif()"
+            "  if(MPI_CXX_LIBRARIES)"
+            "    set_property(TARGET $(ltarget) APPEND PROPERTY INTERFACE_LINK_LIBRARIES \"${MPI_CXX_LIBRARIES}\")"
+            "  endif()"
+            "else()"
+            "  set_property(TARGET $(ltarget) APPEND PROPERTY INTERFACE_LINK_LIBRARIES MPI::MPI_CXX)"
+            "endif()"
+            ""
+            : true ;
+        }
     }
     else
     {
@@ -700,12 +785,15 @@ rule generate-cmake-config ( project name : property-set : sources * )
     local version = [ $(property-set).get <version> ] ;
     local location = [ $(property-set).get <location> ] ;
     local library-type = [ $(property-set).get <library-type> ] ;
+    local cmakedir = [ $(property-set).get <boost-install.cmakedir> ] ;
     local includedir = [ $(property-set).get <boost-install.includedir> ] ;
     local libdir = [ $(property-set).get <boost-install.libdir> ] ;
 
     local ps = [ property-set.create
         <name>$(pname) <version>$(version) <location>$(location)
-        <library-type>$(library-type) <boost-install.includedir>$(includedir)
+        <library-type>$(library-type)
+        <boost-install.cmakedir>$(cmakedir)
+        <boost-install.includedir>$(includedir)
         <boost-install.libdir>$(libdir) ] ;
 
     local result ;
@@ -777,104 +865,132 @@ rule generate-cmake-config-version ( project name : property-set : sources * )
 
 # install-cmake-config-
 
-local rule install-cmake-config- ( location : includedir : libdir : version : name )
+local rule install-cmake-config- ( install-or-stage : location : includedir : libdir : version : name )
 {
     #.debug install-cmake-config- $(name) ;
 
-    local loc = $(location)/$(name)-$(version) ;
-
-    local library-type = UNKNOWN ;
+    local r ;
 
-    if $(name) = boost_headers || $(name) = boost_math || $(name) = boost_exception
+    if [ MATCH boost_(.*) : $(name) ]
     {
-        library-type = INTERFACE ;
-    }
+        local loc = $(location)/$(name)-$(version) ;
 
-    local reqs = <name>$(name) <version>$(version) <location>$(loc) <library-type>$(library-type) <boost-install.includedir>$(includedir) <boost-install.libdir>$(libdir) ;
+        local library-type = UNKNOWN ;
 
-    local r ;
+        if $(name) = boost_headers || $(name) = boost_math || $(name) = boost_exception
+        {
+            library-type = INTERFACE ;
+        }
 
-    r += [ generate $(name)-config.cmake : $(name) : <generating-rule>@boost-install%generate-cmake-config $(reqs) ] ;
-    r += [ generate $(name)-config-version.cmake : $(name) : <generating-rule>@boost-install%generate-cmake-config-version $(reqs) ] ;
+        local reqs = <name>$(name) <version>$(version) <library-type>$(library-type) <boost-install.cmakedir>$(location) <boost-install.includedir>$(includedir) <boost-install.libdir>$(libdir) ;
 
-    if $(library-type) != INTERFACE
+        r += [ generate $(install-or-stage)/$(name)-config.cmake : $(name) : <generating-rule>@boost-install%generate-cmake-config $(reqs) ] ;
+        r += [ install $(install-or-stage)-$(name)-config.cmake : $(install-or-stage)/$(name)-config.cmake : <location>$(loc) ] ;
+
+        r += [ generate $(install-or-stage)/$(name)-config-version.cmake : $(name) : <generating-rule>@boost-install%generate-cmake-config-version $(reqs) ] ;
+        r += [ install $(install-or-stage)-$(name)-config-version.cmake : $(install-or-stage)/$(name)-config-version.cmake : <location>$(loc) ] ;
+
+        if $(library-type) != INTERFACE
+        {
+            local v = [ generate $(install-or-stage)/$(name)-variant.cmake : $(name) : <generating-rule>@boost-install%generate-cmake-variant $(reqs) ] ;
+            r += $(v) ;
+            r += [ install $(install-or-stage)-$(name)-config-variant.cmake : $(v) : <location>$(loc) ] ;
+        }
+    }
+    else
     {
-        r += [ generate $(name)-variant.cmake : $(name) : <generating-rule>@boost-install%generate-cmake-variant $(reqs) ] ;
+        .info "target '$(name)' not prefixed by 'boost_', omitting CMake config" ;
     }
 
     return $(r) ;
 }
 
-# install-cmake-config
+# install-or-stage-cmake-config
+#
+# includedir, libdir, cmakedir should be in canonical path.make format
 
-rule install-cmake-config ( name * )
+rule install-or-stage-cmake-config ( name * : install-or-stage : includedir : libdir : cmakedir )
 {
-    #.debug install-cmake-config $(name) ;
+    local p = [ project.current ] ;
 
     if "--no-cmake-config" in [ modules.peek : ARGV ]
     {
-        local p = [ project.current ] ;
-
-        alias install-detect-toolset ;
-        $(p).mark-target-as-explicit install-detect-toolset ;
-
-        alias install-cmake-config ;
-        $(p).mark-target-as-explicit install-cmake-config ;
+        alias $(install-or-stage)-cmake-config ;
+        $(p).mark-target-as-explicit $(install-or-stage)-cmake-config ;
     }
     else
     {
-        local BOOST_VERSION = [ modules.peek boostcpp : BOOST_VERSION ] ;
+        includedir = [ path.relative-to $(cmakedir) $(includedir) ] ;
+        libdir = [ path.relative-to $(cmakedir) $(libdir) ] ;
 
-        local includedir = [ boost-install-dirs.includedir ] ;
-        local libdir = [ boost-install-dirs.libdir ] ;
-        local cmakedir = [ boost-install-dirs.cmakedir ] ;
-        local header-subdir = [ boost-install-dirs.header-subdir ] ;
-
-        if $(header-subdir)
-        {
-            includedir = $(includedir)/$(header-subdir) ;
-        }
-
-        includedir = [ path.relative-to [ path.make $(cmakedir) ] [ path.make $(includedir) ] ] ;
-        libdir = [ path.relative-to [ path.make $(cmakedir) ] [ path.make $(libdir) ] ] ;
+        local BOOST_VERSION = [ modules.peek boostcpp : BOOST_VERSION ] ;
 
         local configs ;
 
         for local nm in $(name)
         {
-            configs += [ install-cmake-config- $(cmakedir) : $(includedir) : $(libdir) : $(BOOST_VERSION) : $(nm) ] ;
+            configs += [ install-cmake-config- $(install-or-stage) : $(cmakedir) : $(includedir) : $(libdir) : $(BOOST_VERSION) : $(nm) ] ;
         }
 
-        local p = [ project.current ] ;
-
-        # Target install-detect-toolset
+        # Target install/stage-detect-toolset
 
         local boost-install-dir = [ modules.binding $(__name__) ] ;
         boost-install-dir = $(boost-install-dir:D) ;
 
-        install install-detect-toolset : $(boost-install-dir)/BoostDetectToolset.cmake : <location>$(cmakedir) <name>BoostDetectToolset-$(BOOST_VERSION).cmake ;
-        $(p).mark-target-as-explicit install-detect-toolset ;
+        install $(install-or-stage)-detect-toolset : $(boost-install-dir)/BoostDetectToolset.cmake : <location>$(cmakedir) <name>BoostDetectToolset-$(BOOST_VERSION).cmake ;
+        $(p).mark-target-as-explicit $(install-or-stage)-detect-toolset ;
 
-        # Target install-boost-config
+        # Target install/stage-boost-config
 
-        install install-boost-config : $(boost-install-dir)/BoostConfig.cmake : <location>$(cmakedir)/Boost-$(BOOST_VERSION) ;
-        $(p).mark-target-as-explicit install-boost-config ;
+        install $(install-or-stage)-boost-config : $(boost-install-dir)/BoostConfig.cmake : <location>$(cmakedir)/Boost-$(BOOST_VERSION) ;
+        $(p).mark-target-as-explicit $(install-or-stage)-boost-config ;
 
-        # Target install-boost-config-version
+        # Target install/stage-boost-config-version
 
-        generate BoostConfigVersion.cmake : : <generating-rule>@boost-install%generate-cmake-config-version <name>Boost <version>$(BOOST_VERSION) <location>$(cmakedir)/Boost-$(BOOST_VERSION) ;
-        $(p).mark-target-as-explicit BoostConfigVersion.cmake ;
+        project.load [ path.make $(boost-install-dir) ] ;
 
-        alias install-boost-config-version : BoostConfigVersion.cmake ;
-        $(p).mark-target-as-explicit install-boost-config-version ;
+        install $(install-or-stage)-boost-config-version : /boost/tools/boost_install//BoostConfigVersion.cmake : <location>$(cmakedir)/Boost-$(BOOST_VERSION) ;
+        $(p).mark-target-as-explicit $(install-or-stage)-boost-config-version ;
 
-        # Target install-cmake-config
+        # Target install/stage-cmake-config
 
-        alias install-cmake-config : $(configs) install-detect-toolset install-boost-config install-boost-config-version ;
-        $(p).mark-target-as-explicit install-cmake-config ;
+        alias $(install-or-stage)-cmake-config : $(configs) $(install-or-stage)-detect-toolset $(install-or-stage)-boost-config $(install-or-stage)-boost-config-version ;
+        $(p).mark-target-as-explicit $(install-or-stage)-cmake-config ;
     }
 }
 
+# install-cmake-config
+
+rule install-cmake-config ( name * )
+{
+    #.debug install-cmake-config $(name) ;
+
+    local includedir = [ boost-install-dirs.includedir ] ;
+    local libdir = [ boost-install-dirs.libdir ] ;
+    local cmakedir = [ boost-install-dirs.cmakedir ] ;
+    local header-subdir = [ boost-install-dirs.header-subdir ] ;
+
+    if $(header-subdir)
+    {
+        includedir = $(includedir)/$(header-subdir) ;
+    }
+
+    install-or-stage-cmake-config $(name) : install : $(includedir) : $(libdir) : $(cmakedir) ;
+}
+
+rule stage-cmake-config ( name * )
+{
+    local stage-locate = [ path.make [ modules.peek boostcpp : BOOST_STAGE_LOCATE ] ] ;
+
+    local includedir = [ path.make [ modules.peek boostcpp : BOOST_ROOT ] ] ;
+    local libdir = $(stage-locate)/lib ;
+    local cmakedir = $(stage-locate)/lib/cmake ;
+
+    install-or-stage-cmake-config $(name) : stage : $(includedir) : $(libdir) : $(cmakedir) ;
+}
+
+# stage-cmake-config
+
 # collect-targets: Returns the targets and all their dependencies.
 # Copied from stage.jam
 # TODO: Factor this out as a utility in virtal-target.jam
@@ -978,6 +1094,8 @@ rule boost-install ( libraries * )
 
     local stage-locate = [ modules.peek boostcpp : BOOST_STAGE_LOCATE ] ;
 
+    stage-cmake-config $(libraries) ;
+
     install stage-libraries-static : $(libraries) : <location>$(stage-locate)/lib <install-dependencies>on <install-type>STATIC_LIB ;
     $(p).mark-target-as-explicit stage-libraries-static ;
 
@@ -987,6 +1105,6 @@ rule boost-install ( libraries * )
     generate stage-dependencies : $(libraries) : <generating-rule>@boost-install%generate-dependencies <name>stage ;
     $(p).mark-target-as-explicit stage-dependencies ;
 
-    alias stage : stage-libraries-static stage-libraries-shared stage-dependencies ;
+    alias stage : stage-libraries-static stage-libraries-shared stage-cmake-config stage-dependencies ;
     $(p).mark-target-as-explicit stage ;
 }