<div dir="ltr">I normally see it like this:<div><br></div><div><div>if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )</div><div>  project(foo)</div></div><div># ...</div><div>endif()</div><div><br></div><div>hth...</div><div>don</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 3, 2018 at 6:09 PM, Dave Milter <span dir="ltr"><<a href="mailto:davemilter@gmail.com" target="_blank">davemilter@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
If there is some libfoo that I want to use in my project,<br>
and this libfoo has it's own CMakeLists.txt I have 3 options to deal<br>
with such external dependency:<br>
<br>
a) Treat it like every other external dependency and write cmake code<br>
  like FindLibFoo.cmake to find libfoo on file system.<br>
<br>
b)Include this project as git submodule and use ExternalProject to<br>
invoke `cmake` and `cmake --build`<br>
<br>
c)Include this project as git submodule and use add_subdirectory(libfoo)<br>
<br>
<br>
Variant "c" has advantages that potentially in this case it is<br>
possible to have almost the same compiler flags for libfoo and main<br>
project, which may give the most<br>
robust solution in case of usage visual studio (release/debug/multi<br>
thread/single thread CRT problems), plus it is simplify a lot cross<br>
compilation.<br>
<br>
But usually "libfoo" CMakeLists.txt looks like this:<br>
<br>
```<br>
cmake_minimum_required(VERSION 3.10)<br>
<br>
#configure many things that important for standalone<br>
#project, but not requires for project as part of another project<br>
#for example in case of gcc we add some special flags like -Wall<br>
-Wextra -pedantic and so on<br>
<br>
add_library(foo SHARED sources)<br>
```<br>
<br>
and part between `cmake_minimum_required` and `add_library` is useless<br>
and sometime prevent cross compilation and usage of the same compiler flags.<br>
<br>
So question how should I organize CMakeListst.txt of libfoo help deals with "c"?<br>
<br>
Should I move all specific for standalone project code to:<br>
<br>
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)<br>
# i am standalone<br>
endif()<br>
<br>
or may be I should use some other tricks?<br>
--<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/<wbr>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/<wbr>support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>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/<wbr>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/<wbr>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/<wbr>listinfo/cmake</a><br>
</blockquote></div><br></div>