title: How do I use CMake ExternalProject_Add or alternatives in a cross-platform way?
body: <p>I would like to build a third-party project that already has CMake as part of my project's CMake strips. ExternalProject_Add is for this purpose, but I have found it can only be made to work with a specific generator, and I wanted it to work on many platforms easily.</p>
  
  <p>For example, here is my external project with an added script for zlib, which has its own CMakeLists.txt:</p>
  
  <pre><code>set(USE_PROJECT_CMAKE_MODULE_PATH "-DCMAKE_MODULE_PATH=${MAKE_MODULE_PATH}")
  ExternalProject_Add(ZLIB
                      SOURCE_DIR ${CMAKE_SOURCE_DIR}/external/zlib
                      DOWNLOAD_COMMAND ""
                      UPDATE_COMMAND ""
                      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}
                      INSTALL_COMMAND "")
  
  ExternalProject_Add_Step(ZLIB installInternally
                           COMMAND cd &lt;BINARY_DIR&gt; &amp;&amp; make install
                           DEPENDEES install
                           ALWAYS 1)
  ExternalProject_Get_Property(ZLIB install_dir)
  
  if(UNIX)
      set(ZLIB_NAME libz)
  else(UNIX)
      set(ZLIB_NAME zlib)
  endif(UNIX)
  
  add_library(zlib UNKNOWN IMPORTED)
  set_property(TARGET zlib PROPERTY IMPORTED_LOCATION ${install_dir}/lib/${ZLIB_NAME}.a)
  set(ZLIB_LIBRARIES zlib)
  set(ZLIB_LIBRARIES_OPTIONAL ${ZLIB_LIBRARIES})
  set(ZLIB_DIR ${install_dir} CACHE INTERNAL "zlib ROOT dir")
  set(ZLIB_INCLUDE_DIRS ${install_dir}/include CACHE INTERNAL "zlib include dirs")
  set(ZLIB_DEFINES "-msse2 -mfpmath=sse" CACHE INTERNAL "zlib defines")
  </code></pre>
  
  <p>The problem with this is that it works with make, but not with Xcode or Visual Studio. Perhaps there is some way to take the CMake build commands passed to my project and forward them to ExternalProject_Add.</p>
  
  <p>How can I write ExternalProject_Add calls in a cross-platform way with minimal code complexity, or is there a better alternative?</p>