I have two projects: A and B. A depends on B but should set some settings for the proper compilation of B when included in A.<div><br></div><div>==== CMakeLists.txt ==== (project A)</div><div><br></div><div>set(PROJB_OPENCV_LINK NO)</div>
<div><br></div><div>add_subdirectory(vendor/projb)</div><div><br></div><div>==== vendor/projb/CMakeLists.txt === (project B)</div><div><div><br></div><div>option (PROJB_OPENCV_LINK &quot;Set this to NO to link opencv alloc later.&quot; YES)</div>
</div><div><br></div><div>========</div><div><br></div><div>The local value &quot;PROJB_OPENCV_LINK&quot; is overwritten by the option on the first run. If you run cmake a second time, the cached value is seen and takes over so the option does not overwrite.</div>
<div><br></div><div>I do not see any reason why an &quot;option&quot; setting should overwrite a defined variable.</div><div><br></div><div>build &gt; cmake .. ==&gt; fail</div><div><br></div><div>build &gt; cmake .. || cmake .. ==&gt; works. This is absurd.</div>
<div><br></div><div>Gaspard</div><div><br></div><div><br></div><div>PS: I know there is a workaround by using IF(DEFINED...).</div>