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

Cheng Zhigao ZGCHENG at ntu.edu.sg
Sun Nov 15 08:37:31 EST 2009


Hi,

I have used Cmake to build a VS2005C++ project under windows. And for the project i need to link to some external library. I can manually do it under VS2005, but i wish i could do it using cmake statement.

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 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.

Regards,
zhigao



Below is the cmake file
=============================

PROJECT(TEST)
cmake_minimum_required(VERSION 2.6)

SET(TEST_SRCS
        ${TEST_SOURCE_DIR}/DLLTest.cpp)


ADD_EXECUTABLE(TEST
        ${TEST_SRCS})

INCLUDE_DIRECTORIES(${TEST_SOURCE_DIR}/epanet)
LINK_DIRECTORIES(${TEST_SOURCE_DIR}/epanet)

SET(_LINK_EPANET_LIB ${TEST_SOURCE_DIR}/epanet/epanet2.lib)

TARGET_LINK_LIBRARIES(TEST ${_LINK_EPANET_LIB})


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