MonteverdiApplicationMacros.cmake 2.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
macro(create_monteverdi_application)
  cmake_parse_arguments(APPLICATION  "" "NAME;OUTPUT_NAME;COMPONENT_NAME;NEEDS_OTB_APPS" "SOURCES;LINK_LIBRARIES" ${ARGN} )

  if(NOT DEFINED APPLICATION_NEEDS_OTB_APPS OR APPLICATION_NEEDS_OTB_APPS)
    set(APPLICATION_NEEDS_OTB_APPS TRUE)
  else()
    set(APPLICATION_NEEDS_OTB_APPS FALSE)
  endif()

  if(WIN32)
    add_executable(${APPLICATION_NAME}
      WIN32
      ${APPLICATION_SOURCES})
  elseif(APPLE)
    add_executable(${APPLICATION_NAME}
      MACOSX_BUNDLE
      ${APPLICATION_SOURCES})

  else() #Linux
    add_executable(${APPLICATION_NAME}
      ${APPLICATION_SOURCES})
  endif()

  set(EXECUTABLE_NAME ${APPLICATION_NAME})
  if(APPLE)

    string(SUBSTRING ${APPLICATION_NAME} 0 1 FIRST_LETTER)
    string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
    string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" APPLICATION_OUTPUT_NAME "${APPLICATION_NAME}")
  endif()

  if (APPLICATION_OUTPUT_NAME)
    set_target_properties(${APPLICATION_NAME} PROPERTIES OUTPUT_NAME ${APPLICATION_OUTPUT_NAME})
    set(EXECUTABLE_NAME ${APPLICATION_OUTPUT_NAME})
  endif()

  if(APPLE)
    if(Monteverdi_USE_CPACK)
      set(MACOS_FILES_DIR "${CMAKE_SOURCE_DIR}/Packaging/MacOS")

      configure_file(${MACOS_FILES_DIR}/Info.plist.in
        ${CMAKE_BINARY_DIR}/Code/Application/${APPLICATION_NAME}/Info.plist
	      @ONLY)

      configure_file(${MACOS_FILES_DIR}/StartupCommand.in
        ${CMAKE_BINARY_DIR}/Code/Application/${APPLICATION_NAME}/${EXECUTABLE_NAME}_start
	      @ONLY)

      set_target_properties(${APPLICATION_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_BINARY_DIR}/Code/Application/${APPLICATION_NAME}/Info.plist")
    endif(Monteverdi_USE_CPACK)

  endif(APPLE)

  target_link_libraries(${APPLICATION_NAME} ${APPLICATION_LINK_LIBRARIES})

#############################################################################
install(TARGETS ${APPLICATION_NAME}
  BUNDLE DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT ${APPLICATION_COMPONENT_NAME}
  RUNTIME DESTINATION ${Monteverdi_INSTALL_BIN_DIR} COMPONENT ${APPLICATION_COMPONENT_NAME}
  LIBRARY DESTINATION ${Monteverdi_INSTALL_LIB_DIR} COMPONENT ${APPLICATION_COMPONENT_NAME}
  ARCHIVE DESTINATION ${Monteverdi_INSTALL_LIB_DIR} COMPONENT ${APPLICATION_COMPONENT_NAME}
  )

#############################################################################

endmacro(create_monteverdi_application)