<div class="gmail_quote"><font color="#222222" face="arial, sans-serif">I&#39;ve run into a problem where a CMake script that worked with make, xcode, and ninja generators no longer works for XCode after adding ExternalProject_Add to build libpng using their provided CMakeLists.txt as an external. It does not appear to build the correct library files, and I believe this is an issue more closely related to cmake than the fault of libpng&#39;s script. </font><span style="color:rgb(34,34,34);font-family:arial,sans-serif"> </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif">I believe the problem is that libs are not created in the originally expected directories, so instead of lib/libpng.a, xcode creates lib/Debug/libpng.a, and then the main Xcode project wrapped around the libpng Xcode project is unable to find the lib file. I know I could manually write a workaround but I believe this is an issue that can occur in many places and is the typical sort of thing that could or should be handled by the cmake generator.</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif"> Any help would be greatly appreciated. I&#39;ve included additional information below.</span><br>



<div><span style="color:rgb(34,34,34);font-family:arial,sans-serif"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif">Cheers!</span></div>
<div><span style="color:rgb(34,34,34);font-family:arial,sans-serif">Andrew Hundt</span></div><div><br></div><div>
Here is the relevant script, External_PNG.cmake with the problem:</div><div><font color="#222222" face="arial, sans-serif"><div>-------------------------------</div><div>set(USE_PROJECT_CMAKE_MODULE_PATH &quot;-DCMAKE_MODULE_PATH=${MAKE_MODULE_PATH}&quot;)</div>



<div><br></div><div>if(NOT PNG_ROOT)</div><div>  set(PNG_ROOT ${CMAKE_SOURCE_DIR}/external/libpng)</div><div>endif()</div><div><br></div><div>ExternalProject_Add(PNG</div><div>                    DEPENDS ZLIB</div><div>                    SOURCE_DIR ${PNG_ROOT}</div>



<div>                    CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=&lt;INSTALL_DIR&gt; -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${USE_PROJECT_CMAKE_MODULE_PATH}</div>



<div>                    )</div><div>ExternalProject_Get_Property(PNG install_dir)</div><div><br></div><div><br></div><div>add_library(png STATIC IMPORTED )</div><div>set_target_properties(png PROPERTIES IMPORTED_LOCATION ${install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}png16${CMAKE_STATIC_LIBRARY_SUFFIX} )</div>



<div>add_dependencies(png PNG)</div><div>set(PNG_LIBRARIES png ${ZLIB_LIBRARIES}) #png always requires zlib, so just keep them together</div><div>set(PNG_DIR ${install_dir})</div><div>set(PNG_INCLUDE_DIRS ${install_dir}/include)</div>



<div><br></div><div><br></div><div>find_package_handle_standard_args(PNG DEFAULT_MSG PNG_LIBRARIES PNG_INCLUDE_DIRS)</div><div><br></div><div>if(PNG_FOUND)</div><div>  set(PNG_LIBRARIES_OPTIONAL ${PNG_LIBRARIES})</div><div>



endif()</div><div><br></div></font></div><div><br><span style="color:rgb(34,34,34);font-family:arial,sans-serif">-------------------------------</span></div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Here is an email I sent to the libpng list:</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Please pardon me if this is not the right list or way to post this information, but I wanted to provide feedback on an issue I was able to find. I believe I have found a problem with the libpng16 cmakelists.txt file when using the Xcode generator.</div>



<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
I take the following steps in an OS X terminal:</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">cd libpng </div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">



mkdir build</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">cd build</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
cmake .. -G Xcode</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">open libpng.xcodeproj</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">I then hit run in the Xcode window</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">The output does not seem to account for the Debug path in Xcode, and it does not seem to build in Release mode by default. I&#39;ve included the terminal session as well below, so the binaries do not appear in the correct location. I can also supply more information if it would be helpful.<br clear="all">



<div><div><br></div>Cheers!<div>Andrew Hundt</div></div><div><br></div><div><br></div><div><br></div><div><div>Andrew-Hundts-MacBook-Pro-15-2011:external ahundt$ cd external/libpng</div><div>Andrew-Hundts-MacBook-Pro-15-2011:libpng ahundt$ ls</div>



<div>ANNOUNCE<span style="white-space:pre-wrap">                </span>autogen.sh<span style="white-space:pre-wrap">                </span>example.c<span style="white-space:pre-wrap">                </span>libpngpf.3<span style="white-space:pre-wrap">                </span>pngdebug.h<span style="white-space:pre-wrap">                </span>pngmem.lo<span style="white-space:pre-wrap">                </span>pngrio.lo<span style="white-space:pre-wrap">                </span>pngtest.c<span style="white-space:pre-wrap">                </span>pngwtran.c</div>



<div>CHANGES<span style="white-space:pre-wrap">                        </span>build<span style="white-space:pre-wrap">                        </span>install-sh<span style="white-space:pre-wrap">                </span>libtool<span style="white-space:pre-wrap">                        </span>pngerror.c<span style="white-space:pre-wrap">                </span>pngmem.o<span style="white-space:pre-wrap">                </span>pngrio.o<span style="white-space:pre-wrap">                </span>pngtest.<span style="background-color:rgb(255,255,204)">png</span><span style="white-space:pre-wrap">                </span>pngwtran.lo</div>



<div>CMakeLists.txt<span style="white-space:pre-wrap">                </span>config.guess<span style="white-space:pre-wrap">                </span>libpng-config<span style="white-space:pre-wrap">                </span>ltmain.sh<span style="white-space:pre-wrap">                </span>pngerror.lo<span style="white-space:pre-wrap">                </span>pngnow.<span style="background-color:rgb(255,255,204)">png</span><span style="white-space:pre-wrap">                </span>pngrtran.c<span style="white-space:pre-wrap">                </span>pngtrans.c<span style="white-space:pre-wrap">                </span>pngwtran.o</div>



<div>INSTALL<span style="white-space:pre-wrap">                        </span>config.h<span style="white-space:pre-wrap">                </span><a href="http://libpng-config.in/" style="color:rgb(17,85,204)" target="_blank">libpng-config.in</a><span style="white-space:pre-wrap">        </span>missing<span style="white-space:pre-wrap">                        </span>pngerror.o<span style="white-space:pre-wrap">                </span>pngpread.c<span style="white-space:pre-wrap">                </span>pngrtran.lo<span style="white-space:pre-wrap">                </span>pngtrans.lo<span style="white-space:pre-wrap">                </span>pngwutil.c</div>



<div>LICENSE<span style="white-space:pre-wrap">                        </span><a href="http://config.h.in/" style="color:rgb(17,85,204)" target="_blank">config.h.in</a><span style="white-space:pre-wrap">                </span>libpng-manual.txt<span style="white-space:pre-wrap">        </span><span style="background-color:rgb(255,255,204)">png</span>.5<span style="white-space:pre-wrap">                        </span>pngget.c<span style="white-space:pre-wrap">                </span>pngpread.lo<span style="white-space:pre-wrap">                </span>pngrtran.o<span style="white-space:pre-wrap">                </span>pngtrans.o<span style="white-space:pre-wrap">                </span>pngwutil.lo</div>



<div>Makefile<span style="white-space:pre-wrap">                </span>config.log<span style="white-space:pre-wrap">                </span>libpng.3<span style="white-space:pre-wrap">                </span><span style="background-color:rgb(255,255,204)">png</span>.c<span style="white-space:pre-wrap">                        </span>pngget.lo<span style="white-space:pre-wrap">                </span>pngpread.o<span style="white-space:pre-wrap">                </span>pngrutil.c<span style="white-space:pre-wrap">                </span>pngusr.dfa<span style="white-space:pre-wrap">                </span>pngwutil.o</div>



<div>Makefile.am<span style="white-space:pre-wrap">                </span>config.status<span style="white-space:pre-wrap">                </span>libpng.pc<span style="white-space:pre-wrap">                </span><span style="background-color:rgb(255,255,204)">png</span>.h<span style="white-space:pre-wrap">                        </span>pngget.o<span style="white-space:pre-wrap">                </span>pngprefix.h<span style="white-space:pre-wrap">                </span>pngrutil.lo<span style="white-space:pre-wrap">                </span>pngwio.c<span style="white-space:pre-wrap">                </span>projects</div>



<div>Makefile.in<span style="white-space:pre-wrap">                </span>config.sub<span style="white-space:pre-wrap">                </span><a href="http://libpng.pc.in/" style="color:rgb(17,85,204)" target="_blank">libpng.pc.in</a><span style="white-space:pre-wrap">                </span><span style="background-color:rgb(255,255,204)">png</span>.lo<span style="white-space:pre-wrap">                        </span>pnginfo.h<span style="white-space:pre-wrap">                </span>pngpriv.h<span style="white-space:pre-wrap">                </span>pngrutil.o<span style="white-space:pre-wrap">                </span>pngwio.lo<span style="white-space:pre-wrap">                </span>scripts</div>



<div>README<span style="white-space:pre-wrap">                        </span>configure<span style="white-space:pre-wrap">                </span>libpng.sym<span style="white-space:pre-wrap">                </span><span style="background-color:rgb(255,255,204)">png</span>.o<span style="white-space:pre-wrap">                        </span>pnglibconf.dfn<span style="white-space:pre-wrap">                </span>pngread.c<span style="white-space:pre-wrap">                </span>pngset.c<span style="white-space:pre-wrap">                </span>pngwio.o<span style="white-space:pre-wrap">                </span>stamp-h1</div>



<div>TODO<span style="white-space:pre-wrap">                        </span><a href="http://configure.ac/" style="color:rgb(17,85,204)" target="_blank">configure.ac</a><span style="white-space:pre-wrap">                </span>libpng16-config<span style="white-space:pre-wrap">                </span>pngbar.jpg<span style="white-space:pre-wrap">                </span>pnglibconf.h<span style="white-space:pre-wrap">                </span>pngread.lo<span style="white-space:pre-wrap">                </span>pngset.lo<span style="white-space:pre-wrap">                </span>pngwrite.c<span style="white-space:pre-wrap">                </span>test-driver</div>



<div>aclocal.m4<span style="white-space:pre-wrap">                </span>contrib<span style="white-space:pre-wrap">                        </span><a href="http://libpng16.la/" style="color:rgb(17,85,204)" target="_blank">libpng16.la</a><span style="white-space:pre-wrap">                </span>pngbar.<span style="background-color:rgb(255,255,204)">png</span><span style="white-space:pre-wrap">                </span>pnglibconf.out<span style="white-space:pre-wrap">                </span>pngread.o<span style="white-space:pre-wrap">                </span>pngset.o<span style="white-space:pre-wrap">                </span>pngwrite.lo<span style="white-space:pre-wrap">                </span>tests</div>



<div>arm<span style="white-space:pre-wrap">                        </span>depcomp<span style="white-space:pre-wrap">                        </span>libpng16.pc<span style="white-space:pre-wrap">                </span>pngconf.h<span style="white-space:pre-wrap">                </span>pngmem.c<span style="white-space:pre-wrap">                </span>pngrio.c<span style="white-space:pre-wrap">                </span>pngstruct.h<span style="white-space:pre-wrap">                </span>pngwrite.o</div>



<div>Andrew-Hundts-MacBook-Pro-15-2011:libpng ahundt$ mkdir xcodebuild</div><div>Andrew-Hundts-MacBook-Pro-15-2011:libpng ahundt$ cd xcodebuild/</div><div>Andrew-Hundts-MacBook-Pro-15-2011:xcodebuild ahundt$ cmake .. -G Xcode</div>



<div>-- The C compiler identification is Clang 4.2.0</div><div>-- Check for working C compiler using: Xcode</div><div>-- Check for working C compiler using: Xcode -- works</div><div>-- Detecting C compiler ABI info</div>


<div>
-- Detecting C compiler ABI info - done</div><div>-- Found ZLIB: /usr/lib/libz.dylib (found version &quot;1.2.5&quot;) </div><div>-- Configuring done</div><div>-- Generating done</div><div>-- Build files have been written to: /Users/ahundt/Source_Code/external/libpng/xcodebuild</div>



<div>Andrew-Hundts-MacBook-Pro-15-2011:xcodebuild ahundt$ ls</div><div>CMakeCache.txt<span style="white-space:pre-wrap">                </span>CMakeScripts<span style="white-space:pre-wrap">                </span>cmake_install.cmake<span style="white-space:pre-wrap">        </span>libpng.a<span style="white-space:pre-wrap">                </span>libpng.pc<span style="white-space:pre-wrap">                </span>libpng16-config<span style="white-space:pre-wrap">                </span>pnglibconf.h</div>



<div>CMakeFiles<span style="white-space:pre-wrap">                </span>CTestTestfile.cmake<span style="white-space:pre-wrap">        </span>libpng-config<span style="white-space:pre-wrap">                </span>libpng.dylib<span style="white-space:pre-wrap">                </span>libpng.xcodeproj<span style="white-space:pre-wrap">        </span>libpng16.pc</div>



<div>Andrew-Hundts-MacBook-Pro-15-2011:xcodebuild ahundt$ open libpng.xcodeproj/</div><div>Andrew-Hundts-MacBook-Pro-15-2011:xcodebuild ahundt$ ls -alh</div><div>total 136</div><div>drwxr-xr-x@  17 ahundt  staff   578B May 30 17:54 .</div>



<div>drwxr-xr-x@ 114 ahundt  staff   3.8K May 30 17:53 ..</div><div>-rw-r--r--    1 ahundt  staff    13K May 30 17:53 CMakeCache.txt</div><div>drwxr-xr-x    8 ahundt  staff   272B May 30 17:53 CMakeFiles</div><div>drwxr-xr-x   40 ahundt  staff   1.3K May 30 17:53 CMakeScripts</div>



<div>-rw-r--r--    1 ahundt  staff   3.2K May 30 17:53 CTestTestfile.cmake</div><div>drwxr-xr-x    7 ahundt  staff   238B May 30 17:54 Debug</div><div>-rw-r--r--    1 ahundt  staff    15K May 30 17:53 cmake_install.cmake</div>



<div>lrwxr-xr-x    1 ahundt  staff    15B May 30 17:53 libpng-config -&gt; libpng16-config</div><div>lrwxr-xr-x    1 ahundt  staff    10B May 30 17:53 libpng.a -&gt; libpng16.a</div><div>drwxr-xr-x@   3 ahundt  staff   102B May 30 17:54 libpng.build</div>



<div>lrwxr-xr-x    1 ahundt  staff    14B May 30 17:53 libpng.dylib -&gt; libpng16.dylib</div><div>lrwxr-xr-x    1 ahundt  staff    11B May 30 17:53 libpng.pc -&gt; libpng16.pc</div><div>drwxr-xr-x    5 ahundt  staff   170B May 30 17:54 libpng.xcodeproj</div>



<div>-rw-r--r--    1 ahundt  staff   2.3K May 30 17:53 libpng16-config</div><div>-rw-r--r--    1 ahundt  staff   242B May 30 17:53 libpng16.pc</div><div>-rw-r--r--    1 ahundt  staff   7.1K May 30 17:53 pnglibconf.h</div>



<div>Andrew-Hundts-MacBook-Pro-15-2011:xcodebuild ahundt$ ls -alh Debug/</div><div>total 2976</div><div>drwxr-xr-x   7 ahundt  staff   238B May 30 17:54 .</div><div>drwxr-xr-x@ 17 ahundt  staff   578B May 30 17:54 ..</div>



<div>-rw-r--r--   1 ahundt  staff   845K May 30 17:54 libpng16d.a</div><div>-rwxr-xr-x   1 ahundt  staff   368K May 30 17:54 libpng16d.dylib</div><div>-rwxr-xr-x   1 ahundt  staff    65K May 30 17:54 pngstest</div><div>-rwxr-xr-x   1 ahundt  staff    33K May 30 17:54 pngtest</div>



<div>-rwxr-xr-x   1 ahundt  staff   165K May 30 17:54 pngvalid</div></div></div>
</div><br>