Skip to content
Snippets Groups Projects
CMakeLists.txt 47.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • # The entire OTB tree should use the same include path
    
    # Create the list of include directories needed for OTB header files.
    INCLUDE(${OTB_SOURCE_DIR}/otbIncludeDirectories.cmake)
    
    # This should be the only INCLUDE_DIRECTORIES command in the entire
    # tree, except for the Utilities and Wrapping directories.  We need to
    # do this in one place to make sure the order is correct.
    INCLUDE_DIRECTORIES(
      ${OTB_INCLUDE_DIRS_BUILD_TREE}
      ${OTB_INCLUDE_DIRS_BUILD_TREE_CXX}
      ${OTB_INCLUDE_DIRS_SYSTEM}
    )
    
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    #-----------------------------------------------------------------------------
    # Dispatch the build into the proper subdirectories.
    
    #Note: SUBDIRS is deprecated and is replaced by ADD_SUBDIRECTORY
    #SUBDIRS(Utilities Code)
    ADD_SUBDIRECTORY(Utilities)
    ADD_SUBDIRECTORY(Code)
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    
    IF (BUILD_EXAMPLES)
    
      ADD_SUBDIRECTORY(Examples)
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    ENDIF (BUILD_EXAMPLES)
    
    IF (BUILD_TESTING)
    
      ADD_SUBDIRECTORY(Testing)
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    ENDIF (BUILD_TESTING)
    
    #-----------------------------------------------------------------------------
    
    # => Comment for OTB 2.6.0: simplification : copy ITK values
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    # OTB requires special compiler flags on some platforms.
    
    SET(OTB_REQUIRED_C_FLAGS "${ITK_REQUIRED_C_FLAGS}")
    SET(OTB_REQUIRED_CXX_FLAGS "${ITK_REQUIRED_CXX_FLAGS}")
    SET(OTB_REQUIRED_LINK_FLAGS "${ITK_REQUIRED_LINK_FLAGS}")
    
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    IF(MINGW)
      LINK_LIBRARIES(gdi32)
    ENDIF(MINGW)
    
    
    #-----------------------------------------------------------------------------
    # Test for an Objective-C++ compiler.
    SET(OTB_OBJCXX_COMPILER_WORKS 0)
    IF(APPLE)
      TRY_COMPILE(OTB_OBJCXX_COMPILER_WORKS
                  ${OTB_BINARY_DIR}/CMakeTmp
                  ${OTB_SOURCE_DIR}/CMake/otbTestObjCxxCompiler.mm
                  OUTPUT_VARIABLE OTB_OBJCXX_TRY_COMPILE_OUTPUT)
      IF( OTB_OBJCXX_COMPILER_WORKS )
        FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
            "Determining if the Objective-C compiler works passed with "
            "the following output:\n${OTB_OBJCXX_TRY_COMPILE_OUTPUT}\n\n")
      ELSE( OTB_OBJCXX_COMPILER_WORKS )
        FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
          "Determining if the Objective-C compiler works failed with "
          "the following output:\n${OTB_OBJCXX_TRY_COMPILE_OUTPUT}\n\n")
      ENDIF( OTB_OBJCXX_COMPILER_WORKS )
    ENDIF(APPLE)
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    
    
    INCLUDE(CheckTypeSize)
    
    CHECK_TYPE_SIZE("long long" OTB_SIZEOF_LONG_LONG)
    CHECK_TYPE_SIZE("__int64"   OTB_SIZEOF___INT64)
    
    Julien Michel's avatar
    Julien Michel committed
    CHECK_TYPE_SIZE("long int" OTB_SIZEOF_LONG_INT)
    CHECK_TYPE_SIZE("short int" OTB_SIZEOF_SHORT_INT)
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    
    #-----------------------------------------------------------------------------
    # Configure the default OTB_DATA_ROOT for the location of OTB Data.
    
    FIND_PATH(OTB_DATA_ROOT README-OTB-Data PATHS $ENV{OTB_DATA_ROOT} ${OTB_SOURCE_DIR}/../OTB-Data)
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    MARK_AS_ADVANCED(OTB_DATA_ROOT)
    
    
    OPTION(OTB_DATA_USE_LARGEINPUT "Use Large inputs images test." OFF)
    MARK_AS_ADVANCED(OTB_DATA_USE_LARGEINPUT)
    IF(OTB_DATA_USE_LARGEINPUT)
      FIND_PATH(OTB_DATA_LARGEINPUT_ROOT OTBData.readme $ENV{OTB_DATA_LARGEINPUT_ROOT})
      MARK_AS_ADVANCED(OTB_DATA_LARGEINPUT_ROOT)
    ENDIF(OTB_DATA_USE_LARGEINPUT)
    
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    
    #-----------------------------------------------------------------------------
    # Configure files with settings for use by the build.
    
    CONFIGURE_FILE(${OTB_SOURCE_DIR}/otbConfigure.h.in
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
                   ${OTB_BINARY_DIR}/otbConfigure.h)
    
    #-----------------------------------------------------------------------------
    
    # The entire OTB tree should use the same include path
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    
    # Create the list of include directories needed for OTB header files.
    
    #INCLUDE(${OTB_SOURCE_DIR}/otbIncludeDirectories.cmake)
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    
    # This should be the only INCLUDE_DIRECTORIES command in the entire
    # tree, except for the Utilities and Wrapping directories.  We need to
    # do this in one place to make sure the order is correct.
    
    #INCLUDE_DIRECTORIES(
    #  ${OTB_INCLUDE_DIRS_BUILD_TREE}
    #  ${OTB_INCLUDE_DIRS_BUILD_TREE_CXX}
    #  ${OTB_INCLUDE_DIRS_SYSTEM}
    #)
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    
    #-----------------------------------------------------------------------------
    # Uninstall cmake use to uninstall OTB.
    
    #    CONFIGURE_FILE(
    #      "${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in"
    #      "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
    #      IMMEDIATE @ONLY)
    
    #    ADD_CUSTOM_TARGET(uninstall
    #      "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    
    #-----------------------------------------------------------------------------
    # Help other projects use OTB.
    
    # Copy the UseOTB.cmake file to the binary tree for backward compatability.
    CONFIGURE_FILE(${OTB_SOURCE_DIR}/UseOTB.cmake.in
                   ${OTB_BINARY_DIR}/UseOTB.cmake COPYONLY IMMEDIATE)
    
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    # Save the compiler settings so another project can import them.
    INCLUDE(${CMAKE_ROOT}/Modules/CMakeExportBuildSettings.cmake)
    CMAKE_EXPORT_BUILD_SETTINGS(${OTB_BINARY_DIR}/OTBBuildSettings.cmake)
    
    #INSTALL_FILES(/lib/otb .cmake OTBBuildSettings)
    
    IF(NOT OTB_INSTALL_NO_DEVELOPMENT)
      INSTALL(FILES
        ${OTB_BINARY_DIR}/OTBBuildSettings.cmake
        ${OTB_BINARY_DIR}/OTBLibraryDepends.cmake
        ${OTB_BINARY_DIR}/UseOTB.cmake
    
        ${OTB_SOURCE_DIR}/CMake/FindOpenThreads.cmake
    
        DESTINATION ${OTB_INSTALL_PACKAGE_DIR_CM24}
        COMPONENT Development
        )
    ENDIF(NOT OTB_INSTALL_NO_DEVELOPMENT)
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    
    # Save library dependencies.
    EXPORT_LIBRARY_DEPENDENCIES(${OTB_BINARY_DIR}/OTBLibraryDepends.cmake)
    
    # Create the OTBConfig.cmake file containing the OTB configuration.
    INCLUDE (${OTB_SOURCE_DIR}/otbGenerateOTBConfig.cmake)
    
    
    IF(NOT OTB_INSTALL_NO_DEVELOPMENT)
      INSTALL(FILES ${OTB_BINARY_DIR}/otbConfigure.h
        DESTINATION ${OTB_INSTALL_INCLUDE_DIR_CM24}
        COMPONENT Development)
    ENDIF(NOT OTB_INSTALL_NO_DEVELOPMENT)
    
    
    #INSTALL_FILES(/include/otb .h otbConfigure)
    #INSTALL_FILES(/lib/otb .cmake UseOTB OTBLibraryDepends OTBConfig )
    
    Thomas Feuvrier's avatar
    Thomas Feuvrier committed
    
    #-----------------------------------------------------------------------------
    # Add compiler flags OTB needs to work on this platform.  This must be
    # done AFTER the call to CMAKE_EXPORT_BUILD_SETTINGS.
    
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OTB_REQUIRED_C_FLAGS}")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OTB_REQUIRED_CXX_FLAGS}")
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OTB_REQUIRED_LINK_FLAGS}")
    SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OTB_REQUIRED_LINK_FLAGS}")
    SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${OTB_REQUIRED_LINK_FLAGS}")
    
    
    #-----------------------------------------------------------------------------
    
    # Set up CPack support, to be able to distribute OTB binary packages. It will
    # be particulary useful to distributed prebuilt OTB.
    #
    
    
    OPTION(OTB_USE_CPACK "Generate installer using CPack" OFF)
    MARK_AS_ADVANCED(OTB_USE_CPACK)
    
    
        INCLUDE(InstallRequiredSystemLibraries)
        
        SET(CPACK_PACKAGE_NAME "OTB" CACHE STRING "Package name")
        MARK_AS_ADVANCED(CPACK_PACKAGE_NAME)
        
        SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Orfeo Toolbox")
        MARK_AS_ADVANCED(CPACK_PACKAGE_DESCRIPTION_SUMMARY)
        
        SET(CPACK_PACKAGE_VERSION  "${OTB_VERSION_STRING}")
        SET(CPACK_PACKAGE_VERSION_MAJOR "${OTB_VERSION_MAJOR}")
        SET(CPACK_PACKAGE_VERSION_MINOR "${OTB_VERSION_MINOR}")
        SET(CPACK_PACKAGE_VERSION_PATCH "${OTB_VERSION_PATCH}")
        
        SET(CPACK_PACKAGE_CONTACT "contact@orfeo-toolbox.org" CACHE STRING  "Orfeo toolbox contact email")
        
        SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/Description.txt")
        
        #Debian specific
        SET(DEBIAN_PACKAGE_MAINTAINER  "debian@orfeo-toolbox.org" CACHE STRING  "Debian package maintainer email")
        SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libgdal1-1.5.0 (>= 1.5.1-0), libfltk1.1 (>= 1.1.7-3), libcurl3 (>=7.15.5-1etch1), libfftw3-3 (>=3.1.2-3.1)" CACHE STRING "Debian package dependance" )
        SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64" CACHE STRING "arch")
        MARK_AS_ADVANCED(CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
        SET(CPACK_DEBIAN_PACKAGE_NAME "libotb" CACHE STRING "Debian package name")
        
        SET(CPACK_PACKAGE_INSTALL_DIRECTORY "OrfeoToolbox-${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR}")
        
        SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright/OTBCopyright.txt")
        
        FILE(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION)
        FILE(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_DEBIAN_PACKAGE_DESCRIPTION)
        
        IF(WIN32 AND NOT UNIX AND NOT CYGWIN)
        #Find gdal dll files, localized in the GDAL_LIBRARY directory
        GET_FILENAME_COMPONENT(GDAL_LIB_DIR "${GDAL_LIBRARY}" PATH )
        SET(GDAL_LIB_DIR "${GDAL_LIB_DIR}/" )
        INSTALL(DIRECTORY ${GDAL_LIB_DIR}
                DESTINATION                 bin
                FILES_MATCHING  PATTERN     "*.dll" )
        INSTALL(DIRECTORY ${GDAL_LIB_DIR}
                DESTINATION                 lib
                FILES_MATCHING  PATTERN     "*.lib" )
        ENDIF(WIN32 AND NOT UNIX AND NOT CYGWIN)
        
        INCLUDE(CPack)
    
    FILE(GLOB otbconfigfileCreation_SRCS "${OTB_SOURCE_DIR}/CMake/GenerateConfigProperties.cpp")
    SET(otbconfigfile_DEFAULT "${OTB_BINARY_DIR}/otb.conf")
    
    ADD_EXECUTABLE(GenerateConfigProperties ${otbconfigfileCreation_SRCS})
    
    ADD_CUSTOM_COMMAND(
              TARGET GenerateConfigProperties
              POST_BUILD
              COMMAND GenerateConfigProperties
              ARGS "${otbconfigfile_DEFAULT}" "${OTB_STREAM_IMAGE_SIZE_TO_ACTIVATE_STREAMING}" "${OTB_STREAM_MAX_SIZE_BUFFER_FOR_STREAMING}"
    
              COMMENT "Generating ${otbconfigfile_DEFAULT}" )