[CMake] using cmake to link window lib and dll files

Cheng Zhigao ZGCHENG at ntu.edu.sg
Mon Nov 16 22:50:07 EST 2009


Thanks a lot. It helps.

Regards,
zhigao
________________________________________
From: Michael Jackson [mike.jackson at bluequartz.net]
Sent: Monday, November 16, 2009 11:02 PM
To: Cheng Zhigao
Cc: cmake at cmake.org
Subject: Re: [CMake] using cmake to link window lib and dll files

You will need to create an "install" command that copies the library
into the runtime directory. There are lots of examples in the email
archives. Here is what I do for the Qt libraries:

if (AIM_BUILD_QT_APPS AND NOT Q_WS_MAC)
     if (DEFINED QT_QMAKE_EXECUTABLE)
         SET (QTLIBLIST QtCore QtGui)

         IF (MSVC)
             set(TYPE "d")
             FOREACH(qtlib ${QTLIBLIST})
               IF (WIN32)
                 GET_FILENAME_COMPONENT(QT_DLL_PATH_tmp $
{QT_QMAKE_EXECUTABLE} PATH)
                 file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/
Debug)
                 file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/
Release)
                 file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/
MinSizeRel)
                 file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/
RelWithDebInfo)
                 INSTALL(FILES ${QT_DLL_PATH_tmp}/${qtlib}${type}d4.dll
                     DESTINATION ./
                     CONFIGURATIONS Debug
                     COMPONENT Applications)
                 INSTALL(FILES ${QT_DLL_PATH_tmp}/${qtlib}4.dll
                     DESTINATION ./
                     CONFIGURATIONS Release
                     COMPONENT Applications)
                 add_custom_target(${qtlib}-Debug-Copy ALL
                             COMMAND ${CMAKE_COMMAND} -E
copy_if_different ${QT_DLL_PATH_tmp}/${qtlib}${TYPE}4.dll
                             ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/
                             COMMENT "Copying ${qtlib}${TYPE}4.dll to $
{CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/")
                 add_custom_target(${qtlib}-Release-Copy ALL
                             COMMAND ${CMAKE_COMMAND} -E
copy_if_different ${QT_DLL_PATH_tmp}/${qtlib}4.dll
                             ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/
                             COMMENT "Copying ${qtlib}4.dll to $
{CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release/")
               ENDIF (WIN32)
             ENDFOREACH(qtlib)

         endif()
     endif(DEFINED QT_QMAKE_EXECUTABLE)
endif()

_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio

On Nov 15, 2009, at 10:04 PM, Cheng Zhigao wrote:

> Thanks for your reply. I am pretty sure without giving the full
> path, The link_directories and target_link_library does not work
> under my case. And for the dll thing, is there a way i can use cmake
> to make it available for the application at runtime?
>
> Regards,
> zhigao
> ________________________________________
> From: Tyler Roscoe [tyler at cryptio.net]
> Sent: Monday, November 16, 2009 12:50 AM
> To: Cheng Zhigao
> Cc: cmake at cmake.org
> Subject: Re: [CMake] using cmake to link window lib and dll files
>
> On Sun, Nov 15, 2009 at 09:37:31PM +0800, Cheng Zhigao wrote:
>> The project name is TEST, i put the external library in a folder
>> named
>> ${TEST_SOURCE_DIR}/epanet/ which contains the epanet2.h epanet2.lib
>> and epanet2.dll files. I use the Include_directories and
>> link_directories to point to the /epanet/ folder.     And i use
>> TARGET_LINK_LIBRARIES to link the library. However, i still have to
>> put the full path like ${TEST_SOURCE_DIR}/epanet2/epanet2.lib to link
>> to the library including file extension. And I do not know how to
>> link
>
> link_directories() + target_link_libraries() should work. Maybe the
> problem has to do with your confusion on this issue:
>
>> to the epanet2.dll file. I have to manually copy the dll file in
>> order
>> to make the code to work otherwise it will complain cannot find the
>> .dll file.  How can i do that in cmake so that both the .lib file and
>> .dll file will be linked without manual actions? Thanks.
>
> You don't link against a dll. You link against the import library
> (.lib)
> and then the DLL must be available to your application at runtime.
> There's a page in the CMake wiki with more details about building
> libraries on Windows.
>
> tyler
>
> CONFIDENTIALITY: This email is intended solely for the person(s)
> named. The contents may be confidential and/or privileged. If you
> are not the intended recipient, please delete it, notify us, and do
> not copy or use it, nor disclose its contents. Thank you.
>
> Towards A Sustainable Earth: Print Only When Necessary
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


CONFIDENTIALITY: This email is intended solely for the person(s) named. The contents may be confidential and/or privileged. If you are not the intended recipient, please delete it, notify us, and do not copy or use it, nor disclose its contents. Thank you.

Towards A Sustainable Earth: Print Only When Necessary


More information about the CMake mailing list