<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>12760</bug_id>
          
          <creation_ts>2018-05-24 21:34:33 +0000</creation_ts>
          <short_desc>CMake Toolchain File Has Wrong Module Path</short_desc>
          <delta_ts>2026-03-11 15:09:45 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>devtools / tool chain</component>
          <version>2.5.2</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>IN PROGRESS REVIEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>5.99</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>aaron_wright</reporter>
          <assigned_to name="Unassigned">unassigned</assigned_to>
          <cc>aaron_wright</cc>
    
    <cc>kristi</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>tgamblin</cc>
    
    <cc>tim.orling</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Yes (doc changes required)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>80638</commentid>
    <comment_count>0</comment_count>
    <who name="">aaron_wright</who>
    <bug_when>2018-05-24 21:34:33 +0000</bug_when>
    <thetext>The CMake toolchain file, as created by meta/classes/cmake.bbclass, sets CMAKE_MODULE_PATH to ${STAGING_DATADIR}/cmake/Modules/. This doesn&apos;t agree with the comment above that line that says, &quot;Use native cmake modules&quot;, as ${STAGING_DATADIR} isn&apos;t the native recipe sysroot. Rather, ${STAGING_DATADIR_NATIVE} should be used instead.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80670</commentid>
    <comment_count>1</comment_count>
    <who name="">aaron_wright</who>
    <bug_when>2018-05-30 16:56:42 +0000</bug_when>
    <thetext>By using ${STAGING_DATADIR_NATIVE} as the CMAKE_MODULE_PATH, you allow native recipes to add cmake modules to a known directory, which is the desired functionality. 

It might be beneficial to actually document the preferred cmake module directory to install modules to too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80680</commentid>
    <comment_count>2</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2018-05-31 23:21:46 +0000</bug_when>
    <thetext>Hi, 

Here is a sub-section of the &quot;Writing a New Recipe&quot; section from the dev-manual - https://www.yoctoproject.org/docs/2.5/dev-manual/dev-manual.html#new-recipe-configuring-the-recipe.  It mentions Cmake.

Also, this sub-section - https://www.yoctoproject.org/docs/2.5/dev-manual/dev-manual.html#new-recipe-installing

I suspect if we document this we would want to talk about it in the cmake.bbclass section here https://www.yoctoproject.org/docs/2.5/mega-manual/mega-manual.html#ref-classes-cmake.

Would that be a good assumption?  If so, can I get some more explanation for what we need to add?

Thanks,
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80681</commentid>
    <comment_count>3</comment_count>
    <who name="">aaron_wright</who>
    <bug_when>2018-05-31 23:47:40 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; I suspect if we document this we would want to talk about it in the
&gt; cmake.bbclass section here
&gt; https://www.yoctoproject.org/docs/2.5/mega-manual/mega-manual.html#ref-
&gt; classes-cmake.
&gt; 
&gt; Would that be a good assumption?  If so, can I get some more explanation for
&gt; what we need to add?

Yes, documenting it in the cmake.bbclass section would make the most sense.

The situation I was running into was that we were creating a recipe that installs cmake modules and wanting to use those modules in a dependent recipe. So we created a cmake-modules-native.bb recipe:

&gt; SRC_URI = &quot;file://my-module.cmake&quot;
&gt; do_install() {
&gt;     install ${WORKDIR}/my-module.cmake ${D}${datadir}/cmake/Modules
&gt; }
&gt; 
&gt; inherit native

We installed it to that directory because that was the directory listed in the toolchain.cmake file generated by cmake.bbclass:

&gt; # Use native cmake modules
&gt; list(APPEND CMAKE_MODULE_PATH &quot;${STAGING_DATADIR}/cmake/Modules/&quot;)

In the dependent recipe we had:

&gt; DEPENDS += &quot;cmake-modules-native&quot;

And in the dependent CMakeLists.txt file we had:

&gt; include(my-module)

But this didn&apos;t work, because, as has been mentioned, CMAKE_MODULE_PATH is not set to the native sysroot for the recipe.

Once the bug is fixed in cmake.bbclass, it might be helpful to describe this process of creating recipes that install cmake modules.

Perhaps a cmakenative.bbclass should be created instead that could define a variable to use for installing native cmake modules, and which would be assured to correspond to the CMAKE_MODULE_PATH set in the toolchain.cmake file. The documentation for all this could then be added to the cmakenative.bbclass section.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80685</commentid>
    <comment_count>4</comment_count>
    <who name="Stephen K Jolley">sjolley.yp.pm</who>
    <bug_when>2018-06-01 16:18:35 +0000</bug_when>
    <thetext>I believe your question was answered.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82365</commentid>
    <comment_count>5</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2018-11-29 17:00:04 +0000</bug_when>
    <thetext>Aaron - good detail.  I can create the documentation for this.

@Paul - I am looking at the cmake.bbclass in poky/master and the issue for setting CMAKE_MODULE_PATH still exists as described by Aaron in his initial comment.  Once the fix is in place I can do the documentation.  Not sure of the actual implementation ... maybe it creates a new class as suggested... I don&apos;t know.  We probably should also document the CMAKE_MODULE_PATH variable in the glossary as well.

Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84259</commentid>
    <comment_count>6</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2019-06-20 10:19:54 +0000</bug_when>
    <thetext>My apologies for not dealing with this properly until now. Looking at it the comment is definitely incorrect (and Richard will be sending a patch to fix that), however in the native case STAGING_DATADIR will be the same as STAGING_DATADIR_NATIVE hence why we haven&apos;t seen failures as a result, so I don&apos;t think we need to change the value.

I suspect we don&apos;t need to do too much to the documentation relating to this. We could possibly mention somewhere where you should install cmake modules however this is not a particularly common thing to need to do so it wouldn&apos;t need to be mentioned prominently; I&apos;m unsure of the mechanisms off the top of my head but I suspect recipes are getting this right already.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84304</commentid>
    <comment_count>7</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2019-06-21 18:06:01 +0000</bug_when>
    <thetext>Paul, 

Thanks for looking at this.  I am still unsure how to proceed from the documentation end.  I see that the comment in line 122 and 123 of the &quot;cmake.bbclass&quot; file (https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/classes/cmake.bbclass) has been updated to:

   # Use our cmake modules
   list(APPEND CMAKE_MODULE_PATH &quot;${STAGING_DATADIR}/cmake/Modules/&quot;)

This is presumably Richard&apos;s fix?

You stated we might mention where you would install CMake Modules.  I don&apos;t know where or how they would be installed.  I need more information if I am going to apply some sort of documentation fix for this bug.  

Finally, do we want to add the CMAKE_MODULE_PATH variable to the glossary in the YP Reference Manual?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84329</commentid>
    <comment_count>8</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2019-06-27 14:50:32 +0000</bug_when>
    <thetext>Ping Paul...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84387</commentid>
    <comment_count>9</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2019-07-08 21:44:55 +0000</bug_when>
    <thetext>Correct, that was Richard&apos;s fix.

CMAKE_MODULE_PATH is not a bitbake variable, so no we would not want to add it to the glossary.

As for where cmake modules should be installed, they should be installed into
${D}${datadir}/cmake/Modules during do_install.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84395</commentid>
    <comment_count>10</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2019-07-09 23:18:40 +0000</bug_when>
    <thetext>Paul, 

Can you look at https://www.yoctoproject.org/docs/2.8/mega-manual/mega-manual.html#new-recipe-installing section and tell me if what we say about installing CMake here is adequate?  It looks like this is basically saying you don&apos;t have to worry about installing CMake. Sort of like what you said in Comment 6.

Thanks, 
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84730</commentid>
    <comment_count>11</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2019-08-22 14:59:52 +0000</bug_when>
    <thetext>Paul?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85341</commentid>
    <comment_count>12</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2019-10-14 14:43:39 +0000</bug_when>
    <thetext>Paul, 

Can you look at my comment and comment?

Thanks,
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85349</commentid>
    <comment_count>13</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2019-10-16 02:18:22 +0000</bug_when>
    <thetext>Sorry, I sent you (Scott) an email yesterday in reply, I should have included it here. I&apos;ll paste it below:

It&apos;s not really about &quot;installing CMake&quot; it&apos;s about &quot;installing custom CMake 
toolchain files&quot; and it&apos;s a rare situation. If anything, all we would need to 
say is &quot;If you need to install custom CMake toolchain file(s) supplied by the 
application being built, then you would install them to ${D}${datadir}/cmake/
Modules during do_install.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85386</commentid>
    <comment_count>14</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2019-10-17 17:33:23 +0000</bug_when>
    <thetext>I see the email Paul.  Thanks for putting it here in the bug. 

Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85389</commentid>
    <comment_count>15</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2019-10-17 19:07:48 +0000</bug_when>
    <thetext>Paul and Aaron, 

I added a third note to the note block in the &quot;Installing&quot; section of the &quot;Writing a New Recipe&quot; section (https://yoctoproject.org/docs/3.0/dev-manual/dev-manual.html#new-recipe-installing).  It mentions where to install custom CMake toolchain files. 

Also, in the &quot;Configuring the Recipe&quot; section (https://yoctoproject.org/docs/3.0/dev-manual/dev-manual.html#new-recipe-configuring-the-recipe), I added the same note under the &quot;CMake&quot; bullet item.

See https://yoctoproject.org/docs/3.0/ref-manual/ref-manual.html#ref-classes-cmake the &quot;cmake.bbclass&quot; section also for an additional paragraph.

Let me know if there are additional changes.

Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85396</commentid>
    <comment_count>16</comment_count>
    <who name="">aaron_wright</who>
    <bug_when>2019-10-18 19:58:03 +0000</bug_when>
    <thetext>Sorry for not looking into this earlier, but I found some time to take a look, and I don&apos;t think the issue has been addressed.

First off:

&gt; however in the native case STAGING_DATADIR will be the same as STAGING_DATADIR_NATIVE hence why we haven&apos;t seen failures as a result, so I don&apos;t think we need to change the value

Is not true in the use case I&apos;m referring to. I&apos;m trying to write a recipe for the target that uses cmake-native to compile. I also have company-wide CMake scripts that help simplify the build, so I want to use them. Thus, cmake-scripts-native is a dependency of my target recipe.

This gives:

STAGING_DATADIR=&quot;/tmp/yocto-tmp/work/ivybridge-32-sel-linux/my-target-recipe/1.0-r0/recipe-sysroot/usr/share&quot;

and

STAGING_DATADIR_NATIVE=&quot;/tmp/yocto-tmp/work/ivybridge-32-sel-linux/my-target-recipe/1.0-r0/recipe-sysroot-native/usr/share&quot;

Which are different.

Native cmake should not be using scripts from the target (STAGING_DATADIR), but rather, native ones. The comment, &quot;Use native cmake modules,&quot; was correct, but the code is wrong.

Changing cmake.bbclass to the following fixing the issue:

list(APPEND CMAKE_MODULE_PATH &quot;${STAGING_DATADIR_NATIVE}/cmake/Modules/&quot;)

&gt; this is not a particularly common thing to need to do

I would think that any recipe that wanted to use third party CMake scripts would run into this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85397</commentid>
    <comment_count>17</comment_count>
    <who name="">aaron_wright</who>
    <bug_when>2019-10-18 20:10:45 +0000</bug_when>
    <thetext>We currently work around this bug by including the following in our recipes that inherit from cmake.bbclass:

EXTRA_OECMAKE += &quot;-DCMAKE_MODULE_PATH=${STAGING_DATADIR_NATIVE}/cmake/Modules&quot;

Having it fixed in cmake.bbclass itself would be nice.

Another possibility, if there are existing recipes depending on using modules from the target sysroot, is that both can be added. It still seems odd to me to have a native cmake using target modules though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85425</commentid>
    <comment_count>18</comment_count>
    <who name="">aaron_wright</who>
    <bug_when>2019-10-23 18:53:28 +0000</bug_when>
    <thetext>FYI, meta-clang has this correct in their cmake-native.bbclass file:

https://github.com/kraj/meta-clang/blob/master/classes/cmake-native.bbclass#L47</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87032</commentid>
    <comment_count>19</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2020-04-16 07:41:01 +0000</bug_when>
    <thetext>Paul, Can you sort this out?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88670</commentid>
    <comment_count>20</comment_count>
    <who name="Paul Eggleton">bluelightning</who>
    <bug_when>2020-11-23 20:49:44 +0000</bug_when>
    <thetext>I won&apos;t be able to look at this I&apos;m afraid - moving to unassigned.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92196</commentid>
    <comment_count>21</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2021-12-21 00:54:22 +0000</bug_when>
    <thetext>Bumped to M2, added Michael Opdenacker for what seems to be on a quick read, a documentation component to this defect.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96100</commentid>
    <comment_count>22</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2023-07-26 21:22:06 +0000</bug_when>
    <thetext>Bulk move of 64 bugs to 4.3 M3 after a quick review.
If a bug is actually fixed, please add a commit link and resolve it.
-- Randy for YP bug team.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96435</commentid>
    <comment_count>23</comment_count>
    <who name="Trevor Gamblin">tgamblin</who>
    <bug_when>2023-09-14 15:44:29 +0000</bug_when>
    <thetext>Moved to M4.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96502</commentid>
    <comment_count>24</comment_count>
    <who name="Michael Opdenacker">michael.opdenacker</who>
    <bug_when>2023-09-14 19:05:50 +0000</bug_when>
    <thetext>I confirm that I see documentation taking the above comments into account:
https://docs.yoctoproject.org/ref-manual/classes.html#cmake
https://docs.yoctoproject.org/dev-manual/new-recipe.html#installing
https://docs.yoctoproject.org/dev-manual/new-recipe.html#configuring-the-recipe

Removing myself from CC.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97053</commentid>
    <comment_count>25</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2023-10-30 15:29:08 +0000</bug_when>
    <thetext>Bulk move to 5.0 M1. -- Randy</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97681</commentid>
    <comment_count>26</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2023-12-21 23:28:30 +0000</bug_when>
    <thetext>Bulk move of 52 5.0-M1 bugs to M2.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97985</commentid>
    <comment_count>27</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2024-01-25 14:28:43 +0000</bug_when>
    <thetext>Bulk move of bugs owned by &quot;unassigned&quot; from 5.0-M2 to 5.0-M3.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98286</commentid>
    <comment_count>28</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2024-02-22 19:53:19 +0000</bug_when>
    <thetext>Bulk move of bugs from 5.0-M3 to 5.99.
The bugs in this list are all unassigned and are ones that I consider to be nice to do some time but not essential track from milestone to milestone in 5.0 or 5.1. We agreed on this bug handling approach in the YP bug review on Feb 22, 2024.

If you disagree, please move back to a 5.[012...]-M* milestone.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104580</commentid>
    <comment_count>29</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2026-03-11 15:09:45 +0000</bug_when>
    <thetext>Aaron,

I&apos;m doing bug clean-up so not looking carefully myself.

Did this get fixes with:
https://git.openembedded.org/openembedded-core/commit/?id=79dc6a23234a34403157dec10d0cdd839ca76b3e

❯ rg  CMAKE_MODULE_PATH `fd  cmake.bbclass `
meta/classes-recipe/cmake.bbclass
173:list(APPEND CMAKE_MODULE_PATH &quot;${STAGING_DATADIR}/cmake/Modules/&quot;)
206:list(APPEND CMAKE_MODULE_PATH &quot;${STAGING_DATADIR_NATIVE}/cmake/Modules/&quot;)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>