[CMake] ExternalProject_Add with different generators

Andrew Hundt athundt at gmail.com
Mon Jun 3 11:47:52 EDT 2013


I'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's script.  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. Any help would be greatly appreciated. I've
included additional information below.

Cheers!
Andrew Hundt

Here is the relevant script, External_PNG.cmake with the problem:
-------------------------------
set(USE_PROJECT_CMAKE_MODULE_PATH "-DCMAKE_MODULE_PATH=${MAKE_MODULE_PATH}")

if(NOT PNG_ROOT)
  set(PNG_ROOT ${CMAKE_SOURCE_DIR}/external/libpng)
endif()

ExternalProject_Add(PNG
                    DEPENDS ZLIB
                    SOURCE_DIR ${PNG_ROOT}
                    CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${USE_PROJECT_CMAKE_MODULE_PATH}
                    )
ExternalProject_Get_Property(PNG install_dir)


add_library(png STATIC IMPORTED )
set_target_properties(png PROPERTIES IMPORTED_LOCATION
${install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}png16${CMAKE_STATIC_LIBRARY_SUFFIX}
)
add_dependencies(png PNG)
set(PNG_LIBRARIES png ${ZLIB_LIBRARIES}) #png always requires zlib, so just
keep them together
set(PNG_DIR ${install_dir})
set(PNG_INCLUDE_DIRS ${install_dir}/include)


find_package_handle_standard_args(PNG DEFAULT_MSG PNG_LIBRARIES
PNG_INCLUDE_DIRS)

if(PNG_FOUND)
  set(PNG_LIBRARIES_OPTIONAL ${PNG_LIBRARIES})
endif()


-------------------------------


Here is an email I sent to the libpng list:

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.

I take the following steps in an OS X terminal:
cd libpng
mkdir build
cd build
cmake .. -G Xcode
open libpng.xcodeproj

I then hit run in the Xcode window

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'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.

Cheers!
Andrew Hundt



Andrew-Hundts-MacBook-Pro-15-2011:external ahundt$ cd external/libpng
Andrew-Hundts-MacBook-Pro-15-2011:libpng ahundt$ ls
ANNOUNCE autogen.sh example.c libpngpf.3 pngdebug.h pngmem.lo pngrio.lo
pngtest.c pngwtran.c
CHANGES build install-sh libtool pngerror.c pngmem.o pngrio.o pngtest.png
pngwtran.lo
CMakeLists.txt config.guess libpng-config ltmain.sh pngerror.lo pngnow.png
pngrtran.c pngtrans.c pngwtran.o
INSTALL config.h libpng-config.in missing pngerror.o pngpread.c pngrtran.lo
pngtrans.lo pngwutil.c
LICENSE config.h.in libpng-manual.txt png.5 pngget.c pngpread.lo pngrtran.o
pngtrans.o pngwutil.lo
Makefile config.log libpng.3 png.c pngget.lo pngpread.o pngrutil.c
pngusr.dfa pngwutil.o
Makefile.am config.status libpng.pc png.h pngget.o pngprefix.h pngrutil.lo
pngwio.c projects
Makefile.in config.sub libpng.pc.in png.lo pnginfo.h pngpriv.h pngrutil.o
pngwio.lo scripts
README configure libpng.sym png.o pnglibconf.dfn pngread.c pngset.c pngwio.o
stamp-h1
TODO configure.ac libpng16-config pngbar.jpg pnglibconf.h pngread.lo
pngset.lo pngwrite.c test-driver
aclocal.m4 contrib libpng16.la pngbar.png pnglibconf.out pngread.o pngset.o
pngwrite.lo tests
arm depcomp libpng16.pc pngconf.h pngmem.c pngrio.c pngstruct.h pngwrite.o
Andrew-Hundts-MacBook-Pro-15-2011:libpng ahundt$ mkdir xcodebuild
Andrew-Hundts-MacBook-Pro-15-2011:libpng ahundt$ cd xcodebuild/
Andrew-Hundts-MacBook-Pro-15-2011:xcodebuild ahundt$ cmake .. -G Xcode
-- The C compiler identification is Clang 4.2.0
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- works
-- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
-- Found ZLIB: /usr/lib/libz.dylib (found version "1.2.5")
-- Configuring done
-- Generating done
-- Build files have been written to:
/Users/ahundt/Source_Code/external/libpng/xcodebuild
Andrew-Hundts-MacBook-Pro-15-2011:xcodebuild ahundt$ ls
CMakeCache.txt CMakeScripts cmake_install.cmake libpng.a libpng.pc
libpng16-config pnglibconf.h
CMakeFiles CTestTestfile.cmake libpng-config libpng.dylib libpng.xcodeproj
libpng16.pc
Andrew-Hundts-MacBook-Pro-15-2011:xcodebuild ahundt$ open libpng.xcodeproj/
Andrew-Hundts-MacBook-Pro-15-2011:xcodebuild ahundt$ ls -alh
total 136
drwxr-xr-x@  17 ahundt  staff   578B May 30 17:54 .
drwxr-xr-x@ 114 ahundt  staff   3.8K May 30 17:53 ..
-rw-r--r--    1 ahundt  staff    13K May 30 17:53 CMakeCache.txt
drwxr-xr-x    8 ahundt  staff   272B May 30 17:53 CMakeFiles
drwxr-xr-x   40 ahundt  staff   1.3K May 30 17:53 CMakeScripts
-rw-r--r--    1 ahundt  staff   3.2K May 30 17:53 CTestTestfile.cmake
drwxr-xr-x    7 ahundt  staff   238B May 30 17:54 Debug
-rw-r--r--    1 ahundt  staff    15K May 30 17:53 cmake_install.cmake
lrwxr-xr-x    1 ahundt  staff    15B May 30 17:53 libpng-config ->
libpng16-config
lrwxr-xr-x    1 ahundt  staff    10B May 30 17:53 libpng.a -> libpng16.a
drwxr-xr-x@   3 ahundt  staff   102B May 30 17:54 libpng.build
lrwxr-xr-x    1 ahundt  staff    14B May 30 17:53 libpng.dylib ->
libpng16.dylib
lrwxr-xr-x    1 ahundt  staff    11B May 30 17:53 libpng.pc -> libpng16.pc
drwxr-xr-x    5 ahundt  staff   170B May 30 17:54 libpng.xcodeproj
-rw-r--r--    1 ahundt  staff   2.3K May 30 17:53 libpng16-config
-rw-r--r--    1 ahundt  staff   242B May 30 17:53 libpng16.pc
-rw-r--r--    1 ahundt  staff   7.1K May 30 17:53 pnglibconf.h
Andrew-Hundts-MacBook-Pro-15-2011:xcodebuild ahundt$ ls -alh Debug/
total 2976
drwxr-xr-x   7 ahundt  staff   238B May 30 17:54 .
drwxr-xr-x@ 17 ahundt  staff   578B May 30 17:54 ..
-rw-r--r--   1 ahundt  staff   845K May 30 17:54 libpng16d.a
-rwxr-xr-x   1 ahundt  staff   368K May 30 17:54 libpng16d.dylib
-rwxr-xr-x   1 ahundt  staff    65K May 30 17:54 pngstest
-rwxr-xr-x   1 ahundt  staff    33K May 30 17:54 pngtest
-rwxr-xr-x   1 ahundt  staff   165K May 30 17:54 pngvalid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130603/bc8917ca/attachment-0001.htm>


More information about the CMake mailing list