<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 17, 2019 at 2:55 AM junk email <<a href="mailto:mlg420sniperxxx69@gmail.com">mlg420sniperxxx69@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"><div dir="ltr">Hello,<div><br></div><div>I am trying to understand how to build a subdirectory project that has its own CMakeLists.txt file already setup. In this case, I am using the open source library GLFW to help me with some of my OpenGL applications. Here is a sample directory structure I am working with.</div><div><br></div><div><div>Root</div><div>├── CMakeLists.txt</div><div>├── MainProject</div><div>├── build</div><div>└── glfw-3.3</div></div><div><br></div><div>The folder MainProject is where I will be doing all my own development and has a src, include, and lib folder associated with it. The glfw-3.3 directory was downloaded from online and has its own CMakeLists.txt file as mentioned previously. So if I were to build my project from the current build directory shown here, how should I add the glfw library to it and also change its target outputs?</div><div><br></div><div>Answers online suggest using ExternalProject_Add(), while others say to simply add_subdirectory() and then change some of the properties. I want to be able to have a user run the root CMake file and have the targets be correctly placed (since users might be on different operating systems). Either way I have not been able to find an explicit example, perhaps my Googling skills for CMake are lacking, and any help on this would be appreciated. Thank you for your time.</div><div><br></div><div>Best,</div><div>mlg</div><div><br></div></div></div><br></blockquote><div><br></div><div></div><div>If Root/CMakeLists.txt is the root of the source directory it's pretty simple.  Just use add_subdirectory() as usual.</div><div><br></div><div>Again I don't follow why GLFW targets would have to change.  It builds in the Build directory like everything else.  In this case it would be Root/build/glfw-3.3 (assuming Root/build is what was supplied on the command line as something like "cmake -S Root -B Root/build").</div><div><br></div><div>For me I downloaded GLFW and put it outside my source tree.  Then I just used a relative path to it's location.  Because it is outside the source tree I had to specify the build directory to use.</div><div><br></div><div>But GLFW looked to be pretty simple and there wasn't any changes to its CMakeLists.txt file.  I just set some of the options to blank so that they wouldn't be built.<br></div><div><br></div><div>This is from the CMakeLists.txt for my directory structure:<br></div><div>    set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)</div><div>
    set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)</div><div>
    set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)</div><div>
    set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)</div><div>
    add_subdirectory(../glfw-3.2.1 glfw)</div><div>...</div><div>target_link_libraries(application glfw)<br></div></div></div></div></div>