This is very helpful. Thank you!<div><br></div><div>My other question though is how can I get Cmake to add the correct information into the visual studio solution. Even though I have put in the directory names in the cmake gui, I then have to add the same directories manually to the solution. Did I miss something simple. To me the advantage of cmake is that it automatically sets everything up for you in the Visual Studio solutions, which is great. However, even when I manually put in the directories in the cmake-gui, it doesn't seem to add the information to the solution. With that information in there, I can definitely have it copy the .dll to the correct location.</div>
<div><br></div><div>Thanks again for all your help.</div><div>Clark<br><br><div class="gmail_quote">On Sat, Jul 31, 2010 at 9:44 AM, Michael Jackson <span dir="ltr"><<a href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5">On Fri, Jul 30, 2010 at 7:15 PM, John Drescher <<a href="mailto:drescherjm@gmail.com">drescherjm@gmail.com</a>> wrote:<br>
>> I have created a very simple CMake file (I am a newbie) that works<br>
>> wonderfully in Linux, but am having problems in Windows. The CMakeLists.txt<br>
>> is below<br>
>><br>
>> #I think 2.6 is required for some of things I do below, but I am not sure<br>
>> CMAKE_MINIMUM_REQUIRED(VERSION 2.6)<br>
>><br>
>> # This is the CMake file for my application. This<br>
>> # will be my first CMake file of decent size, so please excuse<br>
>> # any particularly bad syntax :)<br>
>> PROJECT(MyApp)<br>
>> FIND_PACKAGE(wxWidgets REQUIRED)<br>
>> FIND_PACKAGE(OpenCV REQUIRED)<br>
>> FIND_PACKAGE(EXPAT REQUIRED)<br>
>> INCLUDE (${wxWidgets_USE_FILE} ${OpenCV_USE_FILE} ${EXPAT_INCLUDE_DIRS})<br>
>><br>
>> SET(Headers myApp.h myAppGUI.h myAppGUImpl.h Coordinates/Coordinates.h)<br>
>> SET(Src myApp.cpp myAppGUI.cpp myAppGUImpl.cpp Coordinates/Coordinates.cpp)<br>
>> ADD_EXECUTABLE(myApp ${Headers} ${Src})<br>
>> TARGET_LINK_LIBRARIES(myApp ${wxWidgets_LIBRARIES} ${OpenCV_LIBS}<br>
>> ${EXPAT_LIBRARIES})<br>
>><br>
>> #End of code<br>
>><br>
>> Everything works great in Linux, but when I try to use this in Windows, I<br>
>> have series of problems, all inter-related.<br>
>><br>
>> Problem #1. While wxWidgets and OpenCV work seamlessly, Cmake can't find<br>
>> the expat libraries. (They are installed. I installed the expat libraries<br>
>> using the basic windows download and install package).<br>
><br>
> CMake rarely finds libraries on windows. The main reason is there is<br>
> no OS standard path for libraries or header files. For me its even<br>
> less likely to find stuff since I build on X: and not the same drive<br>
> as the OS. To fix this normally you run cmake-gui and it tells me it<br>
> can not find a package set the projectname_dir variable. After setting<br>
> this variable in cmake-gui all is well.<br>
><br>
>><br>
>> Problem #2. While I can overcome problem #1 by hardcoding in where the<br>
>> expat include directory and library files are (setting the values in the<br>
>> CMake GUI), when I then open up the resulting solution in Visual Studio 2008<br>
>> Express and compile my code, the compiler gives the error "can't find<br>
>> expat.h"<br>
>><br>
><br>
> That is normally the correct solution.<br>
><br>
>><br>
>> Problem #3. I can fix that problem as well by directly modifying the<br>
>> solution properties, but then when I run the project, it dies because it<br>
>> can't find libexpat.dll.<br>
>><br>
> In your CMakeLists.txt have it copy the libexpat.dll to your debug,<br>
> release .. folder. Do that as a custom build step or an install step.<br>
><br>
> Here are two ways I do this for Qt libraries (modify this for libexpat):<br>
><br>
> The first uses an install.<br>
><br>
> IF (WIN32)<br>
> IF (GET_RUNTIME)<br>
> INSTALL(FILES<br>
> "${QT_BINARY_DIR}/QtCored${QT_VERSION_MAJOR}.dll"<br>
> "${QT_BINARY_DIR}/QtXmld${QT_VERSION_MAJOR}.dll"<br>
> "${QT_BINARY_DIR}/QtTestd${QT_VERSION_MAJOR}.dll"<br>
> "${QT_BINARY_DIR}/QtGuid${QT_VERSION_MAJOR}.dll"<br>
> "${QT_BINARY_DIR}/QtNetworkd${QT_VERSION_MAJOR}.dll"<br>
> "${QT_BINARY_DIR}/QtScriptd${QT_VERSION_MAJOR}.dll"<br>
> DESTINATION ${EXECUTABLE_OUTPUT_PATH}/Debug<br>
> )<br>
> INSTALL(FILES<br>
> "${QT_BINARY_DIR}/QtCore${QT_VERSION_MAJOR}.dll"<br>
> "${QT_BINARY_DIR}/QtXml${QT_VERSION_MAJOR}.dll"<br>
> "${QT_BINARY_DIR}/QtTest${QT_VERSION_MAJOR}.dll"<br>
> "${QT_BINARY_DIR}/QtGui${QT_VERSION_MAJOR}.dll"<br>
> "${QT_BINARY_DIR}/QtNetwork${QT_VERSION_MAJOR}.dll"<br>
> "${QT_BINARY_DIR}/QtScript${QT_VERSION_MAJOR}.dll"<br>
> DESTINATION ${EXECUTABLE_OUTPUT_PATH}/RelWithDebInfo<br>
> )<br>
> ENDIF(GET_RUNTIME)<br>
> ENDIF(WIN32)<br>
><br>
> The second uses a custom build step:<br>
><br>
> # Copy the needed Qt libraries into the Build directory. Also add installation<br>
> # and CPack code to support installer generation.<br>
> # this is a complete hack for Visual Studio to copy the Qt libraries.<br>
> if ( NOT Q_WS_MAC)<br>
> if (DEFINED QT_QMAKE_EXECUTABLE)<br>
> SET (QTLIBLIST QtCore QtGui)<br>
><br>
> IF (MSVC)<br>
> set(TYPE "d")<br>
> FOREACH(qtlib ${QTLIBLIST})<br>
> IF (WIN32)<br>
> GET_FILENAME_COMPONENT(QT_DLL_PATH_tmp<br>
> ${QT_QMAKE_EXECUTABLE} PATH)<br>
> file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Debug)<br>
> file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Release)<br>
> file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/MinSizeRel)<br>
> file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/RelWithDebInfo)<br>
> INSTALL(FILES ${QT_DLL_PATH_tmp}/${qtlib}${type}d4.dll<br>
> DESTINATION ./<br>
> CONFIGURATIONS Debug<br>
> COMPONENT Applications)<br>
> INSTALL(FILES ${QT_DLL_PATH_tmp}/${qtlib}4.dll<br>
> DESTINATION ./<br>
> CONFIGURATIONS Release<br>
> COMPONENT Applications)<br>
> add_custom_target(ZZ_${qtlib}-Debug-Copy ALL<br>
> COMMAND ${CMAKE_COMMAND} -E<br>
> copy_if_different ${QT_DLL_PATH_tmp}/${qtlib}${TYPE}4.dll<br>
> ${PROJECT_BINARY_DIR}/Debug/<br>
> COMMENT "Copying ${qtlib}${TYPE}4.dll to<br>
> ${PROJECT_BINARY_DIR}/Debug/")<br>
> add_custom_target(ZZ_${qtlib}-Release-Copy ALL<br>
> COMMAND ${CMAKE_COMMAND} -E<br>
> copy_if_different ${QT_DLL_PATH_tmp}/${qtlib}4.dll<br>
> ${PROJECT_BINARY_DIR}/Release/<br>
> COMMENT "Copying ${qtlib}4.dll to<br>
> ${PROJECT_BINARY_DIR}/Release/")<br>
> ENDIF (WIN32)<br>
> ENDFOREACH(qtlib)<br>
><br>
> endif(MSVC)<br>
> endif(DEFINED QT_QMAKE_EXECUTABLE)<br>
> endif(NOT Q_WS_MAC)<br>
><br>
><br>
>><br>
>> So, in summary, I think cmake is completely ignoring libexpat, even when I<br>
>> explicitly tell it (in the gui) where the include and library files are.<br>
>><br>
>> Any ideas?<br>
>><br>
> Follow the advice by Stefan. I too believe that is the reason why the<br>
> include did not work.<br>
><br>
> John<br>
<br>
</div></div>Here is a slightly improved version of the above:<br>
<br>
<br>
# --------------------------------------------------------------------<br>
<div class="im"># Copy the needed Qt libraries into the Build directory. Also add installation<br>
# and CPack code to support installer generation.<br>
</div># --------------------------------------------------------------------<br>
if ( NOT Q_WS_MAC AND MSVC AND DEFINED QT_QMAKE_EXECUTABLE)<br>
<br>
SET (QTLIBLIST QtCore QtGui)<br>
SET (QTPLUGINLIST qgif qjpeg qtiff)<br>
set (BUILD_TYPES "Debug;Release")<br>
<br>
foreach (btype ${BUILD_TYPES})<br>
string(TOUPPER ${btype} BTYPE)<br>
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${btype})<br>
foreach(qtlib ${QTLIBLIST})<br>
<br>
string(TOUPPER ${qtlib} QTLIB)<br>
# message(STATUS "QT_${QTLIB}_LIBRARY_${BTYPE}:<br>
${QT_${QTLIB}_LIBRARY_${BTYPE}}")<br>
GET_FILENAME_COMPONENT(DLL_NAME<br>
${QT_${QTLIB}_LIBRARY_${BTYPE}} NAME_WE)<br>
# message(STATUS "DLL_NAME: ${DLL_NAME}")<br>
GET_FILENAME_COMPONENT(QT_BIN_PATH ${QT_QMAKE_EXECUTABLE} PATH)<br>
# message(STATUS "QT_BIN_PATH: ${QT_BIN_PATH}")<br>
<br>
INSTALL(FILES ${QT_BIN_PATH}/${DLL_NAME}.dll<br>
DESTINATION ./<br>
CONFIGURATIONS ${btype}<br>
COMPONENT Applications)<br>
<br>
add_custom_target(Z_${qtlib}-${BTYPE}-Copy ALL<br>
<div class="im"> COMMAND ${CMAKE_COMMAND} -E copy_if_different<br>
</div>${QT_BIN_PATH}/${DLL_NAME}.dll<br>
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${btype}/<br>
COMMENT "Copying<br>
${QT_BIN_PATH}/${DLL_NAME}.dll to<br>
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${btype}/")<br>
<br>
endforeach()<br>
<br>
# For this project we also need to copy the imageformat Qt plugins<br>
which should have already been defined<br>
# in the cmake variables QTPLUGINS_DEBUG, QTPLUGINS_RELEASE and QTPLUGINS<br>
file(MAKE_DIRECTORY<br>
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${btype}/plugins/imageformats)<br>
foreach(plugin ${QTPLUGINLIST})<br>
string(TOUPPER ${plugin} PLUGIN)<br>
# message(STATUS "QT_${QTLIB}_LIBRARY_${BTYPE}:<br>
${QT_${QTLIB}_LIBRARY_${BTYPE}}")<br>
GET_FILENAME_COMPONENT(DLL_NAME<br>
${QT_${PLUGIN}_PLUGIN_${BTYPE}} NAME_WE)<br>
# message(STATUS "DLL_NAME: ${DLL_NAME}")<br>
# GET_FILENAME_COMPONENT(QT_BIN_PATH ${QT_QMAKE_EXECUTABLE} PATH)<br>
# message(STATUS "QT_BIN_PATH: ${QT_BIN_PATH}")<br>
<br>
INSTALL(FILES ${QT_PLUGINS_DIR}/imageformats/${DLL_NAME}.dll<br>
DESTINATION ./plugins/imageformats<br>
CONFIGURATIONS ${btype}<br>
COMPONENT Applications)<br>
<br>
add_custom_target(Z_${plugin}-${BTYPE}-Copy ALL<br>
<div class="im"> COMMAND ${CMAKE_COMMAND} -E copy_if_different<br>
</div>${QT_PLUGINS_DIR}/imageformats/${DLL_NAME}.dll<br>
<br>
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${btype}/plugins/imageformats/<br>
COMMENT "Copying<br>
${QT_PLUGINS_DIR}/imageformats/${DLL_NAME}.dll to<br>
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${btype}/plugins/imageformats")<br>
<br>
endforeach(plugin ${QTPLUGINS_${BTYPE}})<br>
<br>
#write a qt.conf file into the application directory and install it<br>
file(WRITE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${btype}/qt.conf "")<br>
INSTALL(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${btype}/qt.conf<br>
DESTINATION .<br>
CONFIGURATIONS ${btype}<br>
COMPONENT Applications )<br>
<br>
endforeach()<br>
endif()<br>
<br>
Mike Jackson<br>
</blockquote></div><br><br clear="all"><br>-- <br>Clark <br>
</div>