All,

I have a project that is typically compiled with CLang/LLVM.  However,
I'm now adding a component that is preferentially built with OpenMP.
CLang doesn't support OpenMP, so I'd like to build that component with
GCC while still building everything else with CLang.

So far, I'm approaching the problem as shown in the below
CMakeLists.txt.  The program understands -DUSE_OPENMP, so if OpenMP
isn't found, it will build a uni-processor version.  The user can
optionally pass -DC_OMP_COMPILER and -DCXX_OMP_COMPILER when CMake is
run.  Those will specify alternate OpenMP capable compilers.  The
EP_BUILD variable prevents infinite recursion.

So, in the case where the primary compiler does not support OpenMP,
and the user specifies an alternate compiler, this will use
ExternalProject_Add to establish a new build environment with the
alternate compiler, and build that.  So far, so good.

The problem I have is that I would like the executable built by
ExternalProject to be added to the top-level project's package.  So,
instead of the recursion protected INSTALL at the bottom, I want a
roughly equivalent INSTALL command that specifically works in the
ExternalProject case.

Best,

Rob

#####################################
FIND_PACKAGE( OpenMP )

if(OPENMP_FOUND)
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} -DUSE_OPENMP")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -DUSE_OPENMP")
  set(BUILD_IT true)
else()

if( CXX_OMP_COMPILER AND NOT EP_BUILD )

  INCLUDE( ExternalProject )

  set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
  INCLUDE( ExternalProject_ForceBuild )

  ExternalProject_Add( ALTBUILD
    URL ${CMAKE_CURRENT_SOURCE_DIR}
    CMAKE_ARGS -DCMAKE_C_COMPILER=${C_OMP_COMPILER}
        -DCMAKE_CXX_COMPILER=${CXX_OMP_COMPILER}
        -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
        -DEP_BUILD=TRUE
    INSTALL_COMMAND ""
    )
    EP_ForceBuild( ALTBUILD )

  else()
    set(BUILD_IT true)
  endif()
endif()

if(BUILD_IT)

  ADD_EXECUTABLE( myprogram
  main.cpp
  )

  TARGET_LINK_LIBRARIES( myprogram
  )

  if ( NOT EP_BUILD )
    INSTALL( TARGETS myprogram RUNTIME DESTINATION . )
  endif()

endif()
-- 

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