<div dir="ltr"><div><div><div><div><div><div><div><div>Thanks for clarifying that external projects are not aware of the project they are embedded in.<br></div>The CMAKE_COMPILER_IS_GNUCXX variable should be set automatically by CMake as far<br></div>as I understand it (see <a href="https://cmake.org/Wiki/CMake_Useful_Variables">https://cmake.org/Wiki/CMake_Useful_Variables</a>).<br><br></div>I narrowed down the problem by creating a minimal setup which still reproduces the issue.<br></div><div>In this case the super project is simply a wrapper around an external dummy project.<br></div></div><br></div>external/CMakeLists.txt:<br><br>  cmake_minimum_required( VERSION 3.4 )<br>  project( external )<br>  message( "External - CMAKE_COMPILER_IS_GNUCXX: " ${CMAKE_COMPILER_IS_GNUCXX} )<br>  message( "External - CMAKE_CXX_COMPILER_ID: " ${CMAKE_CXX_COMPILER_ID} )<br>  message( "External - CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} )<br><br></div>super/CMakeLists.txt:<br></div><br>  cmake_minimum_required( VERSION 3.4 )<br>  project( super )<br>  message( "Super - CMAKE_COMPILER_IS_GNUCXX: " ${CMAKE_COMPILER_IS_GNUCXX} )<br>  message( "Super - CMAKE_CXX_COMPILER_ID: " ${CMAKE_CXX_COMPILER_ID} )<br>  message( "Super - CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} )<br>  include( ExternalProject )<br>  ExternalProject_Add(<br>    external<br>    DOWNLOAD_COMMAND ""<br>    SOURCE_DIR ${CMAKE_SOURCE_DIR}/../external<br>    CMAKE_ARGS<br>      -DCMAKE_CXX_FLAGS="-march=native"<br>    INSTALL_COMMAND  ""<br>  )<br><br><div><div><div><div><div><div><div><div><div><div><div><div class="gmail_extra">The problem occurs when the CMAKE_CXX_FLAGS variable is set inside the ExternalProject_Add<br>command using quotes (i.e. "-march=native" in this example). The output obtained when configuring<br>the super project with 'cmake ../super' is:<br><br>-- The C compiler identification is GNU 5.2.0<br>-- The CXX compiler identification is GNU 5.2.0<br>-- Check for working C compiler: /usr/bin/cc<br>-- Check for working C compiler: /usr/bin/cc -- works<br>-- Detecting C compiler ABI info<br>-- Detecting C compiler ABI info - done<br>-- Detecting C compile features<br>-- Detecting C compile features - done<br>-- Check for working CXX compiler: /usr/bin/c++<br>-- Check for working CXX compiler: /usr/bin/c++ -- works<br>-- Detecting CXX compiler ABI info<br>-- Detecting CXX compiler ABI info - done<br>-- Detecting CXX compile features<br>-- Detecting CXX compile features - done<br>Super - CMAKE_COMPILER_IS_GNUCXX: 1<br>Super - CMAKE_CXX_COMPILER_ID: GNU<br>Super - CMAKE_CXX_FLAGS: <br>-- Configuring done<br>-- Generating done<br><br>Afterwards building with 'make' results in:<br><br>[ 12%] Creating directories for 'external'<br>[ 25%] No download step for 'external'<br>[ 37%] No patch step for 'external'<br>[ 50%] No update step for 'external'<br>[ 62%] Performing configure step for 'external'<br>-- The C compiler identification is GNU 5.2.0<br>-- The CXX compiler identification is unknown<br>-- Check for working C compiler: /usr/bin/cc<br>-- Check for working C compiler: /usr/bin/cc -- works<br>-- Detecting C compiler ABI info<br>-- Detecting C compiler ABI info - done<br>-- Detecting C compile features<br>-- Detecting C compile features - done<br>-- Check for working CXX compiler: /usr/bin/c++<br>-- Check for working CXX compiler: /usr/bin/c++ -- works<br>-- Detecting CXX compiler ABI info<br>-- Detecting CXX compiler ABI info - done<br>External - CMAKE_COMPILER_IS_GNUCXX: <br>External - CMAKE_CXX_COMPILER_ID: <br>External - CMAKE_CXX_FLAGS: "-march=native"<br>-- Configuring done<br>-- Generating done<br><br></div><div class="gmail_extra">This shows the compiler is not correctly identified for the external project. Directly configuring<br></div><div class="gmail_extra">the external project with 'cmake -DCMAKE_CXX_FLAGS="-march=native" ../external' works though:<br><br>-- The C compiler identification is GNU 5.2.0<br>-- The CXX compiler identification is GNU 5.2.0<br>-- Check for working C compiler: /usr/bin/cc<br>-- Check for working C compiler: /usr/bin/cc -- works<br>-- Detecting C compiler ABI info<br>-- Detecting C compiler ABI info - done<br>-- Detecting C compile features<br>-- Detecting C compile features - done<br>-- Check for working CXX compiler: /usr/bin/c++<br>-- Check for working CXX compiler: /usr/bin/c++ -- works<br>-- Detecting CXX compiler ABI info<br>-- Detecting CXX compiler ABI info - done<br>-- Detecting CXX compile features<br>-- Detecting CXX compile features - done<br>External - CMAKE_COMPILER_IS_GNUCXX: 1<br>External - CMAKE_CXX_COMPILER_ID: GNU<br>External - CMAKE_CXX_FLAGS: -march=native<br>-- Configuring done<br>-- Generating done<br><br><br></div><div class="gmail_extra">It also works if the quotations marks in the super project listfile are removed. I.e. changing <br>  CMAKE_ARGS<br>   -DCMAKE_CXX_FLAGS="-march=native"<br></div><div class="gmail_extra">to<br></div><div class="gmail_extra">  CMAKE_ARGS<br>   -DCMAKE_CXX_FLAGS=-march=native<br><br></div><div class="gmail_extra">The question is now, is it still possible to add mutiple compile flags if one cannot use quotation marks?<br><br><br></div><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 20, 2016 at 6:58 PM, Nicholas Braden <span dir="ltr"><<a href="mailto:nicholas11braden@gmail.com" target="_blank">nicholas11braden@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Where/how is that variable normally set? External projects have no<br>
awareness of the project they are in, they just run CMake as usual the<br>
same way you would. If the variable is normally set by CMake itself,<br>
make sure that your containing project and the external project both<br>
find the same compiler. (They each do their own automatic search for<br>
compilers)<br>
<div><div class="h5"><br>
On Wed, Jan 20, 2016 at 11:41 AM, fkillus via CMake <<a href="mailto:cmake@cmake.org">cmake@cmake.org</a>> wrote:<br>
> I have been trying to compile Ogre [1] as external dependency with<br>
> ExternalProject_Add(). In theory this should be straightforward since Ogre<br>
> itself also uses CMake as buildsystem. However, in the process I encountered<br>
> the following problem:<br>
><br>
> Ogre checks the value of the CMAKE_COMPILER_IS_GNUCXX variable in some<br>
> places (e.g. [2]). I am running Linux and compiling with g++ and everything<br>
> works fine if I manually configure Ogre with cmake or cmake-gui.<br>
> Unfortunately, after wrapping everything inside ExternalProject_Add(), the<br>
> CMAK_COMPILER_IS_GNUCXX variable is no longer being set correctly.<br>
><br>
> A simple workaround is to manually set this variable, i.e.:<br>
><br>
>  ExternalProject_Add(<br>
>     ogre<br>
>     URL <a href="https://bitbucket.org/sinbad/ogre/get/v1-9-0.zip" rel="noreferrer" target="_blank">https://bitbucket.org/sinbad/ogre/get/v1-9-0.zip</a><br>
>     CMAKE_ARGS<br>
>       -DCMAKE_INSTALL_PREFIX=${DEPENDENCIES_OUTPUT_DIR}<br>
>       -DCMAKE_COMPILER_IS_GNUCXX=${CMAKE_COMPILER_IS_GNUCXX}   # workaround<br>
>   )<br>
><br>
> This works, but I'm uncertain if this should be necessary. Is this a bug or<br>
> a feature?<br>
><br>
><br>
> [1] <a href="https://bitbucket.org/sinbad/ogre" rel="noreferrer" target="_blank">https://bitbucket.org/sinbad/ogre</a><br>
> [2]<br>
> <a href="https://bitbucket.org/sinbad/ogre/src/0d580c7216abe27fafe41cb43e31d8ed86ded591/CMake/Utils/OgreConfigTargets.cmake?at=default&fileviewer=file-view-default#OgreConfigTargets.cmake-277" rel="noreferrer" target="_blank">https://bitbucket.org/sinbad/ogre/src/0d580c7216abe27fafe41cb43e31d8ed86ded591/CMake/Utils/OgreConfigTargets.cmake?at=default&fileviewer=file-view-default#OgreConfigTargets.cmake-277</a><br>
><br>
</div></div>> --<br>
><br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Please keep messages on-topic and check the CMake FAQ at:<br>
> <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
><br>
> Kitware offers various services to support the CMake community. For more<br>
> information on each offering, please visit:<br>
><br>
> CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
</blockquote></div><br></div></div></div></div></div></div></div></div></div></div></div></div></div>