Skip to content
Snippets Groups Projects
Dependences.cmake 10.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • # Search for installed software required by BornAgain
    
    if(WIN32)
        set(CMAKE_FIND_LIBRARY_SUFFIXES .dll.a .lib)
    endif()
    
    
    find_package(LibHeinz REQUIRED CONFIG)
    
    message(STATUS "LibHeinz: found=${LibHeinz_FOUND}, include_dirs=${LibHeinz_INCLUDE_DIR}, "
    
        "version=${LibHeinz_VERSION}")
    
    
    #find_package(formfactor REQUIRED CONFIG)
    
    #message(STATUS "formfactor: found=${formfactor_FOUND}, version=${formfactor_VERSION}")
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    
    
    find_package(Threads REQUIRED)
    
    find_package(FFTW3 REQUIRED)
    
    find_package(GSL REQUIRED)
    
    Matthias's avatar
    Matthias committed
    message(STATUS "GSL found=${GSL_FOUND} libs=${GSL_LIBRARIES} inc=${GSL_INCLUDE_DIR} version=${GSL_VERSION}")
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    if(WIN32)
    
        set(EIGEN3_INCLUDE_DIR ${CMAKE_INCLUDE_PATH})
    
        message(STATUS "Eigen3 include_dir=${EIGEN3_INCLUDE_DIR}(hard-coded)")
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    else()
    
        find_package(Eigen3 3.3 REQUIRED)
    
        message(STATUS "Eigen3 include_dir=${EIGEN3_INCLUDE_DIR} version=${EIGEN3_VERSION_STRING}")
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    endif()
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
    find_package(Cerf REQUIRED)
    
    t.knopff's avatar
    t.knopff committed
        message(STATUS "Compiling test program to determine additional libcerf flags")
    
    t.knopff's avatar
    t.knopff committed
            "${CMAKE_BINARY_DIR}/temp"
            "${CMAKE_SOURCE_DIR}/cmake/tests/test_libcerf.cpp"
            CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${Cerf_INCLUDE_DIR};${CMAKE_SOURCE_DIR}"
    
            LINK_LIBRARIES ${Cerf_LIBRARIES}
            OUTPUT_VARIABLE COMPILE_OUT)
    
    t.knopff's avatar
    t.knopff committed
        if(NOT COMPILE_OK)
            try_compile(COMPILE_OK
                "${CMAKE_BINARY_DIR}/temp"
                "${CMAKE_SOURCE_DIR}/cmake/tests/test_libcerf.cpp"
                COMPILE_DEFINITIONS "-DLIBCERF_WITHOUT_TYPEDEF"
                CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${Cerf_INCLUDE_DIR};${CMAKE_SOURCE_DIR}"
    
                LINK_LIBRARIES ${Cerf_LIBRARIES})
    
    t.knopff's avatar
    t.knopff committed
            if(COMPILE_OK)
                add_definitions("-DLIBCERF_WITHOUT_TYPEDEF")
            else()
                message(FATAL_ERROR "Compilation of libcerf test program failed with "
                    "the following output:\n" "${COMPILE_OUT}\n")
            endif()
    
    if(Cerf_IS_CPP)
        add_compile_definitions(CERF_AS_CPP=ON)
    endif()
    
    set(Boost_NO_BOOST_CMAKE ON) # prevent shortcut
    
    set(Boost_USE_STATIC_LIBS OFF)
    
    set(Boost_USE_STATIC_RUNTIME OFF)
    
    add_definitions(-DBOOST_ALL_DYN_LINK) # line is needed for MSVC
    
    add_definitions(-DBOOST_UUID_FORCE_AUTO_LINK) # line is needed to link bcrypt for MSVC
    
    # amends problems with bimap and MSVC, serialization of bimap is currently not needed
    add_definitions(-DBOOST_BIMAP_DISABLE_SERIALIZATION)
    
    
    # Boost component libraries (do not list headers here)
    
    set(boost_libraries_required iostreams program_options)
    
    # NOTE: `FindBoost` CMake module internally adds Boost::regex as an extra dependency for Boost::iostream
    
    
    pospelov's avatar
    pospelov committed
    if(WIN32)
    
        # On Windows, additional libaries are required for Boost::iostream
        list(APPEND boost_libraries_required zlib bzip2)
    
    pospelov's avatar
    pospelov committed
    endif()
    
    
    message(STATUS "Boost required libraries: ${boost_libraries_required}")
    
    find_package(Boost 1.65.1 COMPONENTS ${boost_libraries_required})
    message(STATUS "Boost: includes at ${Boost_INCLUDE_DIRS}, libraries at ${Boost_LIBRARY_DIRS}")
    
    message(STATUS "Boost libraries: ${Boost_LIBRARIES}; ${Boost_Additional_Libraries}")
    
    
        message(FATAL_ERROR "Not all required Boost component libraries were found")
    
    # === optional packages ===
    
    if(BORNAGAIN_MPI)
        message(STATUS "Configuring with MPI support")
    
        find_package(MPI REQUIRED)
    
        message(STATUS "MPI_CXX_INCLUDE_PATH: ${MPI_CXX_INCLUDE_PATH}")
        message(STATUS "MPI_CXX_LIBRARIES: ${MPI_CXX_LIBRARIES}")
    
        message(STATUS "Looking for libtiff (use -DBORNAGAIN_TIFF_SUPPORT=OFF to disable)")
    
        find_package(TIFF 4.0.2 REQUIRED COMPONENTS CXX)
    
    if(BORNAGAIN_PYTHON)
    
        find_package(Python3 COMPONENTS Interpreter Development)
    
        if(NOT Python3_FOUND)
            message(FATAL_ERROR "Python3 not found.")
        endif()
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
        message(STATUS "  Python3_VERSION              : ${Python3_VERSION}")
        message(STATUS "  Python3_INTERPRETER_ID       : ${Python3_INTERPRETER_ID}")
        message(STATUS "  Python3_EXECUTABLE           : ${Python3_EXECUTABLE}")
        message(STATUS "  Python3_STDLIB               : ${Python3_STDLIB} Python3_STDARCH: ${Python3_STDARCH}")
        message(STATUS "  Python3_SITELIB              : ${Python3_SITELIB} Python3_SITEARCH: ${Python3_SITEARCH}")
        message(STATUS "  Python3_INCLUDE_DIRS         : ${Python3_INCLUDE_DIRS}")
        message(STATUS "  Python3_LIBRARIES            : ${Python3_LIBRARIES}")
        message(STATUS "  Python3_LIBRARY_DIRS         : ${Python3_LIBRARY_DIRS}")
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
        if(NOT Python3_FOUND)
    
            message(FATAL_ERROR "Python3 interpreter not found.")
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
        endif()
    
        find_package(Python3 COMPONENTS Interpreter Development)
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
        if(NOT Python3_Development_FOUND)
    
            message(FATAL_ERROR
                "Python.h not found. Probably you need to install package libpython3-dev (or similar).")
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
        endif()
    
        find_package(Python3 COMPONENTS Interpreter Development NumPy)
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
        if(NOT Python3_NumPy_FOUND)
    
            message(FATAL_ERROR "Python3-NumPy not found.")
    
    Wuttke, Joachim's avatar
    Wuttke, Joachim committed
        endif()
    
        message(STATUS "  Python3_NumPy_VERSION        : ${Python3_NumPy_VERSION}")
        message(STATUS "  Python3_NumPy_INCLUDE_DIRS   : ${Python3_NumPy_INCLUDE_DIRS}")
    
        if(CONFIGURE_BINDINGS)
            find_package(SWIG 4.0 REQUIRED)
            include(${SWIG_USE_FILE})
            message(STATUS "Found SWIG version ${SWIG_VERSION} at ${SWIG_EXECUTABLE} with flags '${SWIG_FLAGS}'; CMake definitions in ${SWIG_USE_FILE}")
    
            if(CONFIGURE_PYTHON_DOCS)
                find_package(Doxygen REQUIRED)
            endif()
        endif()
    
    endif()
    
    # --- man page generation ---
    
        find_program(POD2MAN pod2man)
    
            message(FATAL_ERROR "FATAL: cannot satisfy CONFIGURE_MANPAGE: pod2man not found")
    
        message(STATUS "Found pod2man: ${POD2MAN}")
    
    
    
    # === install Windows DLLs ===
    
    if(WIN32)
    
        ## Boost libraries
    
        # The list ${Boost_LIBRARIES} can contain either only dll names (if e.g. debug dlls are
    
        # not found), or keyword/dll pairs (if debug and release dlls have been found). This has
        # to be taken care of in the iteration over the list.
        # debug DLLs are ignored for installation
        message(STATUS "Installation of Boost libraries:")
        set(entryShallBeSkipped false)
    
        foreach(Boost_lib ${Boost_LIBRARIES})
    
                set(entryShallBeSkipped false)
                continue()
            endif()
    
    
            if(${Boost_lib} STREQUAL "debug")
    
                set(entryShallBeSkipped true)
                continue()
            endif()
    
    
            if(${Boost_lib} STREQUAL "optimized")
    
                set(entryShallBeSkipped false)
                continue()
            endif()
    
    
            get_filename_component(UTF_BASE_NAME ${Boost_lib} NAME_WE)
            get_filename_component(UTF_PATH ${Boost_lib} PATH)
            install(FILES ${UTF_PATH}/${UTF_BASE_NAME}.dll
    
                DESTINATION ${destination_lib} COMPONENT Libraries
                CONFIGURATIONS [Release|MinSizeRel|RelWithDebInfo])
            message("    ${UTF_PATH}/${UTF_BASE_NAME}.dll - will be installed in ${destination_lib}")
        endforeach()
    
        ## Libraries needed in addition (for boost)
        message(STATUS "Installation of libraries needed in addition to Boost:")
        foreach(lib ${Boost_Additional_Libraries})
            get_filename_component(UTF_BASE_NAME ${lib} NAME_WE)
            get_filename_component(UTF_PATH ${lib} PATH)
            install(FILES ${UTF_PATH}/${UTF_BASE_NAME}.dll
                DESTINATION ${destination_lib} COMPONENT Libraries
                CONFIGURATIONS [Release|MinSizeRel|RelWithDebInfo])
            message("    ${UTF_PATH}/${UTF_BASE_NAME}.dll - will be installed in ${destination_lib}")
    
        ## Python library
    
        set(win_python_lib
            "${Python3_LIBRARY_DIRS}/python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}.lib")
        get_filename_component(UTF_BASE_NAME ${win_python_lib} NAME_WE)
        get_filename_component(UTF_PATH ${Python3_EXECUTABLE} PATH)
    
        message(STATUS "Python dll: ${UTF_PATH}/${UTF_BASE_NAME}.dll"
    
            " - will be installed in ${destination_lib}")
    
        install(FILES ${UTF_PATH}/${UTF_BASE_NAME}.dll
    
            DESTINATION ${destination_lib} COMPONENT Libraries
            CONFIGURATIONS [Release|MinSizeRel|RelWithDebInfo])
    
        ## CERF library
    
        set(Cerf_LIB ${Cerf_LIBRARIES}) # we take for granted that there is only one cerf.lib
        get_filename_component(DIR ${Cerf_LIB} DIRECTORY)
        get_filename_component(cerf ${Cerf_LIB} NAME_WE)
    
    
        set(Cerf_DLL "${DIR}/cerfcpp.dll")
    
            message(FATAL_ERROR "Dynamic link library ${Cerf_DLL} (needed for cerf) does not exist")
    
        install(FILES ${Cerf_DLL} DESTINATION ${destination_lib} COMPONENT Libraries)
        message(STATUS "Cerf dll: ${Cerf_DLL} - will be installed in ${destination_lib}")
    
    
        ## FFTW3
        message(STATUS "Installation of FFTW3:")
        foreach(lib ${FFTW3_LIBRARIES})
            get_filename_component(UTF_BASE_NAME ${lib} NAME_WE)
            get_filename_component(UTF_PATH ${lib} PATH)
            install(FILES ${UTF_PATH}/${UTF_BASE_NAME}.dll
                DESTINATION ${destination_lib} COMPONENT Libraries
                CONFIGURATIONS [Release|MinSizeRel|RelWithDebInfo])
            message("    ${UTF_PATH}/${UTF_BASE_NAME}.dll - will be installed in ${destination_lib}")
    
        endforeach()
    
            ## Same as for Boost above: list can contain
            # mixture of debug/optimized libs
            message(STATUS "Installation of TIFF:")
            set(entryShallBeSkipped false)
            foreach(LIB ${TIFF_LIBRARIES})
    
                    set(entryShallBeSkipped false)
                    continue()
                endif()
    
                    set(entryShallBeSkipped true)
                    continue()
                endif()
    
                if(${LIB} STREQUAL "optimized")
    
                    set(entryShallBeSkipped false)
                    continue()
                endif()
    
                get_filename_component(UTF_NAME ${LIB} NAME)
    
                if(${UTF_NAME} STREQUAL "tiff.lib")
    
                    message("    No installation for ${UTF_NAME}: This is the static TIFF library")
                    continue()
                endif()
                string(REPLACE ".lib" ".dll" DLL "${LIB}")
    
                if(NOT EXISTS ${DLL})
                    message(FATAL_ERROR
                        "Dynamic link library ${DLL} (derived from ${LIB}) does not exist")
    
                endif()
                install(FILES ${DLL} COMPONENT Libraries
                    DESTINATION ${destination_lib}
                    CONFIGURATIONS [Release|MinSizeRel|RelWithDebInfo])
                message("    ${DLL} - will be installed in ${destination_lib}")
            endforeach()
        endif()