[CMake] Visual C++ and cpack

Mathias Bavay bavay at slf.ch
Wed Jun 1 06:12:49 EDT 2011


Hi!

I've been using cmake and cpak on Linux for my project (a library) 
without any problems. I'm now trying to get it to work with Visual C++ 
Express 10. It compiles fine, and puts files (from the project 
directory) into meteoio/Release (both a .dll and a .lib). When running 
cpack, it only packs the .lib file, and I can not find any way to also 
properly get the dll.

Here is a sample of my code for compiling the library:
SET(LIBPREFIX "lib") #make sure ALL plugins are libXXX for ALL plateforms
SET(CMAKE_IMPORT_LIBRARY_PREFIX "lib") #for Visual C++ import libraries
     SET(SHAREDNAME ${PROJECT_NAME})
     ADD_LIBRARY(${SHAREDNAME} ${meteoio_sources})
     TARGET_LINK_LIBRARIES(${SHAREDNAME} ${LIBPROJ})
     SET_TARGET_PROPERTIES(${SHAREDNAME} PROPERTIES
         PREFIX "${LIBPREFIX}"
         LIBRARY_OUTPUT_DIRECTORY lib
         ARCHIVE_OUTPUT_DIRECTORY lib
         CLEAN_DIRECT_OUTPUT 1
         VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
         SOVERSION "${VERSION_MAJOR}"
     )
     INSTALL(TARGETS ${SHAREDNAME}
         RUNTIME DESTINATION bin
         LIBRARY DESTINATION lib
         ARCHIVE DESTINATION lib
         COMPONENT libraries
     )

First issue, despite specifying that I want the library to be under lib, 
it goes into a Release directory under the source file's directory. But 
when cpack should find and pack it, it only gets the .lib and always 
misses the dll:
IF(WIN32) #handle the special case of WIN32 needing import libraries
     FILE(GLOB importlibs "lib/libmeteoio*.lib*")
     SET(DLL_EXT "dll")
ENDIF(WIN32)
FILE(GLOB solibs "lib/libmeteoio*.${DLL_EXT}*")
FILE(GLOB alibs "lib/*.${STAT_EXT}*")
INSTALL(FILES ${solibs} ${importlibs} ${alibs} DESTINATION lib COMPONENT 
libraries)

What am I doing wrong? It works perfectly fine under Linux (obviously, 
only packing a .so), but not with Visual C++... The whole code can be 
seen at https://slfsmm.indefero.net/p/meteoio/source/tree/HEAD/

Thank you very much,
Mathias Bavay


More information about the CMake mailing list