2

私の MacOSX では、Qt と VTK ライブラリを利用するアプリケーションを開発しました。CMake を使用して makefile を生成します。

今、Windows でエンド ユーザーの自己完結型パッケージをコンパイルしたいと考えています。Qt または VTK ライブラリを事前にインストールする必要なく、エンド ユーザーのマシンで動作するはずです。CMakeLists.txt ファイルを変更することでこれを行うことは可能だと思いますが、Web 検索では正しい方向が示されませんでした。

CMake を使用して Windows 用の配布可能なパッケージを作成するには?

4

1 に答える 1

2

私自身のプロジェクトの 1 つで行ったことは、VTK の cmake-variables および QT_LIBRARIES 変数から .so ファイルまたは .dll ファイルを提供する小さなスクリプトを作成することです。

その後、これらの .dll ファイルまたは .so ファイルをインストール ターゲット (以下のスクリプト例) に追加すると、インストール ターゲットはこれらの .dll ファイルまたは .so ファイルを VTK_DIR または QTDIR から ${CMAKE_INSTALL_PREFIX}\bin にコピーします。これは CPack と互換性があるため、cpack-script を少し書くこともできます。

ただし、エンドユーザー向けの自己完結型パッケージを取得するには、Windows でもう少し必要なことに注意してください。「システム ライブラリ」(msvcrt.dll、msvcrp.dll または mingwm10.dll、libstdc++.dll) も必要になります。 . たとえば、この質問を見てください。

Windows では、次のスクリプトはVTK_DIR からすべての Vtk dll を検索します。

file( GLOB VTK_DLLS ${VTK_RUNTIME_LIBRARY_DIRS}/*.dll )
if( VTK_DLLS )
    foreach( Vtk_library ${VTK_DLLS} )
        # Add it to the list of 'desired' vtk-libraries for later installation
        list( APPEND Vtk_Install_Libraries ${Vtk_library} )
    endforeach( Vtk_library ${VTK_DLLS} )
    list( REMOVE_DUPLICATES Vtk_Install_Libraries )
    install( FILES ${Vtk_Install_Libraries} DESTINATION bin COMPONENT ThirdParty  )
endif( VTK_DLLS )

また、Qt の場合、デバッグ ライブラリとリリース ライブラリの両方を見つける必要があったため、スクリプトは少し長くなります。利点: リクエストしたコンポーネントのみを検索しますfind_package( Qt4 ... )

# If Qt-4 was used, add the 'found' Qt-libraries to the Install-target.
if ( USE_QT )
    foreach( Qt_library ${QT_LIBRARIES} )
        # With QT_USE_IMPORTED_TARGETS, we should extract the dll info 
        # from the target properties
        get_target_property( Qt_lib_name ${Qt_library} IMPORTED_LOCATION )
        get_target_property( Qt_lib_name_debug ${Qt_library} IMPORTED_LOCATION_DEBUG )
        get_target_property( Qt_lib_name_release ${Qt_library} IMPORTED_LOCATION_RELEASE )

        # Initially assume the release dlls should be installed, but 
        # fall back to debug if necessary
        if ( Qt_lib_name_release AND EXISTS ${Qt_lib_name_release} )
            set( Qt_library_location ${Qt_lib_name_release} )
        elseif ( Qt_lib_name_debug AND EXISTS ${Qt_lib_name_debug} AND ENVIRONMENT_DEBUG )
            set( Qt_library_location ${Qt_lib_name_debug} )
        elseif ( Qt_lib_name AND EXISTS ${Qt_lib_name} )
            set( Qt_library_location ${Qt_lib_name} )
        endif ( Qt_lib_name_release AND EXISTS ${Qt_lib_name_release} )

        # Extract the filename part, without the lib-prefix or the .a or ..lib suffix
        get_filename_component( Qt_library_name ${Qt_library_location} NAME_WE )
        string( REGEX REPLACE "^lib(.*)" "\\1" Qt_library_name ${Qt_library_name} )

        set( Qt_shared_library ${QT_BINARY_DIR}/${Qt_library_name}.dll )
        if ( EXISTS ${Qt_shared_library} )
            # Add it to the list of 'desired' qt-libraries for later installation
            list( APPEND Qt_Install_Libraries ${Qt_shared_library} )
        else ( EXISTS ${Qt_shared_library} )
            message( WARNING "    could not find ${Qt_shared_library}" )
        endif ( EXISTS ${Qt_shared_library} )
    endforeach( Qt_library ${QT_LIBRARIES} )
    # When building against a static Qt, the list of Qt_Install_Libraries can be empty
    if ( Qt_Install_Libraries )
        list( REMOVE_DUPLICATES Qt_Install_Libraries )
        install( FILES ${Qt_Install_Libraries} DESTINATION bin COMPONENT ThirdParty )
    endif ( Qt_Install_Libraries )
endif ( USE_QT )    
于 2012-04-05T08:21:37.533 に答える