I don't like my current solution for such problem, but it works for me
well. Note "file(GLOB_RECURSE ..." and custom "copy" step in the end.
Also you can try to google "cmake super build" which probably will
provide you more ideas.
----
include(ExternalProject)

set(WEBSOCKETS_PATCH_DIR "${CMAKE_CURRENT_SOURCE_DIR}/patch")
set(WEBSOCKETS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libwebsockets-1.4")
set(WEBSOCKETS_BUILD_SOURCE_DIR
"${CMAKE_CURRENT_BINARY_DIR}/libwebsockets-1.4.source")
set(WEBSOCKETS_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/libwebsockets-1.4.build")
set(WEBSOCKETS_INSTALL_PREFIX
"${CMAKE_CURRENT_BINARY_DIR}/libwebsockets-1.4.install")

ExternalProject_Add(websockets_ep
    EXCLUDE_FROM_ALL 1
    SOURCE_DIR ${WEBSOCKETS_BUILD_SOURCE_DIR}
    BINARY_DIR ${WEBSOCKETS_BUILD_DIR}
    DOWNLOAD_COMMAND ""
    PATCH_COMMAND find ${WEBSOCKETS_PATCH_DIR} -name "*.patch" -exec
patch -d ${WEBSOCKETS_BUILD_SOURCE_DIR} -p1 -i {} $<SEMICOLON>
    INSTALL_DIR ${WEBSOCKETS_INSTALL_PREFIX}
    CMAKE_ARGS
        -DCMAKE_TOOLCHAIN_FILE:string=${CMAKE_TOOLCHAIN_FILE}
    CMAKE_CACHE_ARGS
        -DCMAKE_BUILD_TYPE:string=${CMAKE_BUILD_TYPE}
        -DCMAKE_INSTALL_PREFIX:string=<INSTALL_DIR>
        -DCMAKE_PREFIX_PATH:string=${CMAKE_PREFIX_PATH})

file(GLOB_RECURSE WEBSOCKETS_SOURCES RELATIVE
"${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/*")
ExternalProject_Add_Step(websockets_ep copy
    COMMAND ${CMAKE_COMMAND} -E copy_directory
${WEBSOCKETS_SOURCE_DIR} ${WEBSOCKETS_BUILD_SOURCE_DIR}
    DEPENDS ${WEBSOCKETS_SOURCES}
    DEPENDEES download
    DEPENDERS patch)

add_library(websockets INTERFACE)
target_include_directories(websockets INTERFACE
${WEBSOCKETS_INSTALL_PREFIX}/include)
target_link_libraries(websockets INTERFACE
${WEBSOCKETS_INSTALL_PREFIX}/lib/libwebsockets.a)
add_dependencies(websockets websockets_ep)

On Thu, Apr 23, 2015 at 4:54 PM, Rob McDonald <rob.a.mcdon...@gmail.com> wrote:
> I've used ExternalProject_Add to trick CMake into supporting two
> compilers to build my project.
>
> Part of my project needs OpenMP, but other parts do not.  So, on
> MacOS, I would prefer to build most of the project with CLang, but the
> OpenMP requiring part with gcc.
>
> I have CMake set up to detect whether the compiler supports OpenMP.
> If it does not, it checks for a user-supplied alternate compiler.
>
> If the user has supplied an alternate compiler, CMake treats the
> current directory as an ExternalProject , but passes the alternate
> OpenMP capable compiler.
>
> In general, this works well.  However, this arrangement does not
> notice when the source files have changed and cause the External
> Project to rebuild.
>
> I'm using ExternalProject_ForceBuild to try to make the EP build every
> time -- that works, but once inside the EP, make doesn't recognize
> that the source files have been updated.
>
> The meat of the situation is something like this....
>
> ExternalProject_Add( MYPROJECT
> URL ${CMAKE_CURRENT_SOURCE_DIR}
> CMAKE_ARGS -DCMAKE_C_COMPILER=${C_ALTERNATE_COMPILER}
>     -DCMAKE_CXX_COMPILER=${CXX_ALTERNATE_COMPILER}
>     -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
>     -DEP_BUILD=TRUE
> INSTALL_COMMAND ""
> )
> EP_ForceBuild( MYPROJECT )
>
> I use the -DEP_BUILD=TRUE as an extra safety to prevent infinite
> recursion -- if the user supplied a non OpenMP capable compiler as the
> ALTERNATE_COMPILER.
>
> So, I think the problem is with my use of 'URL
> ${CMAKE_CURRENT_SOURCE_DIR}'.  Is there a better way to achieve the
> same thing?
>
> Thanks in advance,
>
> Rob
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: 
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more 
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to