<div dir="ltr"><div>Hi.</div><div><br></div><div>The argument STATIC or SHARED is processed at CMake configure time (that is, when CMake is executing the add_library() command). However, generator expressions are only evaluated at generate time, which comes only after all CMake code is processed.</div><div><br></div><div>Fortunately for you, compiler ID is something that is already known at configure time, meaning you don't need to use a genex to read it. You can just do this:</div><div><br></div><div>if(MSVC)</div><div>  set(LibType STATIC)</div><div>else()</div><div>  set(LibType SHARED)</div><div>endif()</div><div>add_library(</div><div>  ${_star_lib_name}</div><div>  ${LibType}</div><div>  ...</div><div>)</div><div><br></div><div>(Feel free to modify the if(), use CMAKE_<LANG>_COMPILER_ID (<a href="https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html">https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html</a>) etc. as necessary).</div><div><br></div><div>Petr<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 7 Nov 2019 at 12:28, David Aldrich <<a href="mailto:david.aldrich.ntml@gmail.com">david.aldrich.ntml@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><p style="margin-top:0px;font-family:Helvetica,Arial,sans-serif;font-size:15px">I want to build a shared library for Linux and a static library for Windows. So I have tried:</p><pre style="overflow:auto;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:15px"><code style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:1em;overflow:auto;background:rgb(249,249,249) none repeat scroll 0% 0%;display:block;padding:0.5em;max-height:500px"> set (_star_lib_name "StdStars")
 
 add_library(${_star_lib_name} 
             $<$<CXX_COMPILER_ID:GNU>:SHARED>
             $<$<CXX_COMPILER_ID:MSVC>:STATIC> 
             ""
 )
</code></pre><p style="font-family:Helvetica,Arial,sans-serif;font-size:15px">but that gives me error:</p><pre style="overflow:auto;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:15px"><code style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace;font-size:1em;overflow:auto;background:rgb(249,249,249) none repeat scroll 0% 0%;display:block;padding:0.5em;max-height:500px">CMake Error at C:/SVNProj/zodiac/branches/TRY_TML_CMake_3Oct2019/StarLibs/StdStars/CMakeLists.txt:7 (add_library):
Cannot find source file:

    STATIC

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx
</code></pre><p style="font-family:Helvetica,Arial,sans-serif;font-size:15px">What is the correct way of doing this please?</p></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: <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 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 <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="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div>