<div dir="ltr"><div><div><div><div>As others have suggested, moving the add_executable() after the set() calls is the correct solution.<br><br></div>The reason is that variables like CMAKE_CXX_STANDARD are used to pre-initialise a target's properties when the target is created. In other words, at the time add_executable() is called, CMake will inspect variables like CMAKE_CXX_STANDARD and use them to initialise the target's properties like CXX_STANDARD. It's the properties which really control the target's build. See <a href="https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html">https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html</a> and <a href="https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html">https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html</a> for details.<br><br></div>The same applies to add_compile_options(). From its docs ( <a href="https://cmake.org/cmake/help/latest/command/add_compile_options.html">https://cmake.org/cmake/help/latest/command/add_compile_options.html</a> ): "Adds options to the compiler command line for targets in the current
directory and below that are added after this command is invoked"<br><br></div>But Craig is right that you shouldn't add `-std` directly, but use CXX_STANDARD and CXX_EXTENSIONS instead.<br><br></div>Petr<br><div class="gmail_extra"><br><div class="gmail_quote">On 11 July 2017 at 07:21, Craig Scott <span dir="ltr"><<a href="mailto:craig.scott@crascit.com" target="_blank">craig.scott@crascit.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">As well as moving the add_executable() call after you set the various CMAKE_CXX... variables, you should also replace the call to <span style="font-size:12.800000190734863px">add_compile_options(-std=c+<wbr>+</span><span style="font-size:12.800000190734863px">11) with the following:</span><div><span style="font-size:12.800000190734863px"><br></span></div><div><span style="font-size:12.800000190734863px">set(CMAKE_CXX_EXTENSIONS OFF)</span><span style="font-size:12.800000190734863px"><br></span></div><div><span style="font-size:12.800000190734863px"><br></span></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Tue, Jul 11, 2017 at 3:11 PM, Michael Ellery <span dir="ltr"><<a href="mailto:mellery451@gmail.com" target="_blank">mellery451@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><br>
> On Jul 10, 2017, at 10:07 PM, Florian Lindner <<a href="mailto:mailinglists@xgm.de" target="_blank">mailinglists@xgm.de</a>> wrote:<br>
><br>
> Hello,<br>
><br>
> my complete cmake file looks like that:<br>
><br>
> cmake_minimum_required (VERSION 3.1)<br>
> project(Preallocation)<br>
> add_executable(prealloc prealloc_parallel.cpp)<br>
><br>
> set(CMAKE_CXX_STANDARD 11)<br>
> set(CMAKE_CXX_STANDARD_REQUIRE<wbr>D ON)<br>
> add_compile_options(-std=c++11<wbr>)<br>
><br>
> find_library(petsc petsc<br>
>  PATHS $ENV{PETSC_DIR}/$ENV{PETSC_ARC<wbr>H}/lib)<br>
> if(NOT petsc)<br>
>  message(FATAL_ERROR "petsc was not found")<br>
> endif()<br>
> target_link_libraries(prealloc ${petsc})<br>
><br>
> find_package(Boost 1.60.0<br>
>  REQUIRED<br>
>  COMPONENTS program_options)<br>
> target_link_libraries(prealloc ${Boost_LIBRARIES})<br>
><br>
> find_package(MPI<br>
>  REQUIRED)<br>
> target_link_libraries(prealloc ${MPI_LIBRARIES})<br>
><br>
> set(COMPILE_FLAGS  ${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS})<br>
> set(LINK_FLAGS ${LINK_FLAGS} ${MPI_LINK_FLAGS})<br>
><br>
<br>
</span>I would try moving the add_executable() to the end of the CMakeLists file (after the set() and find_library calls…)<br></blockquote></div></div></div></div></blockquote></div><br></div></div>