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&#39;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">&lt;<a href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a>&gt;</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 &lt;<a href="mailto:drescherjm@gmail.com">drescherjm@gmail.com</a>&gt; wrote:<br>


&gt;&gt; I have created a very simple CMake file (I am a newbie) that works<br>
&gt;&gt; wonderfully in Linux, but am having problems in Windows.  The CMakeLists.txt<br>
&gt;&gt; is below<br>
&gt;&gt;<br>
&gt;&gt; #I think 2.6 is required for some of things I do below, but I am not sure<br>
&gt;&gt; CMAKE_MINIMUM_REQUIRED(VERSION 2.6)<br>
&gt;&gt;<br>
&gt;&gt; # This is the CMake file for my application.  This<br>
&gt;&gt; # will be my first CMake file of decent size, so please excuse<br>
&gt;&gt; # any particularly bad syntax :)<br>
&gt;&gt; PROJECT(MyApp)<br>
&gt;&gt; FIND_PACKAGE(wxWidgets REQUIRED)<br>
&gt;&gt; FIND_PACKAGE(OpenCV REQUIRED)<br>
&gt;&gt; FIND_PACKAGE(EXPAT REQUIRED)<br>
&gt;&gt; INCLUDE (${wxWidgets_USE_FILE} ${OpenCV_USE_FILE} ${EXPAT_INCLUDE_DIRS})<br>
&gt;&gt;<br>
&gt;&gt; SET(Headers myApp.h myAppGUI.h myAppGUImpl.h Coordinates/Coordinates.h)<br>
&gt;&gt; SET(Src myApp.cpp myAppGUI.cpp myAppGUImpl.cpp Coordinates/Coordinates.cpp)<br>
&gt;&gt; ADD_EXECUTABLE(myApp ${Headers} ${Src})<br>
&gt;&gt; TARGET_LINK_LIBRARIES(myApp ${wxWidgets_LIBRARIES} ${OpenCV_LIBS}<br>
&gt;&gt; ${EXPAT_LIBRARIES})<br>
&gt;&gt;<br>
&gt;&gt; #End of code<br>
&gt;&gt;<br>
&gt;&gt; Everything works great in Linux, but when I try to use this in Windows, I<br>
&gt;&gt; have series of problems, all inter-related.<br>
&gt;&gt;<br>
&gt;&gt; Problem #1.  While wxWidgets and OpenCV work seamlessly, Cmake can&#39;t find<br>
&gt;&gt; the expat libraries.  (They are installed.  I installed the expat libraries<br>
&gt;&gt; using the basic windows download and install package).<br>
&gt;<br>
&gt; CMake rarely finds libraries on windows. The main reason is there is<br>
&gt; no OS standard path for libraries or header files. For me its even<br>
&gt; less likely to find stuff since I build on X: and not the same drive<br>
&gt; as the OS. To fix this normally you run cmake-gui and it tells me it<br>
&gt; can not find a package set the projectname_dir variable. After setting<br>
&gt; this variable in cmake-gui all is well.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; Problem #2.  While I can overcome problem #1 by hardcoding in where the<br>
&gt;&gt; expat include directory and library files are (setting the values in the<br>
&gt;&gt; CMake GUI), when I then open up the resulting solution in Visual Studio 2008<br>
&gt;&gt; Express and compile my code, the compiler gives the error &quot;can&#39;t find<br>
&gt;&gt; expat.h&quot;<br>
&gt;&gt;<br>
&gt;<br>
&gt; That is normally the correct solution.<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; Problem #3.  I can fix that problem as well by directly modifying the<br>
&gt;&gt; solution properties, but then when I run the project, it dies because it<br>
&gt;&gt; can&#39;t find libexpat.dll.<br>
&gt;&gt;<br>
&gt; In your CMakeLists.txt have it copy the libexpat.dll to your debug,<br>
&gt; release .. folder. Do that as a custom build step or an install step.<br>
&gt;<br>
&gt; Here are two ways I do this for Qt libraries (modify this for libexpat):<br>
&gt;<br>
&gt; The first uses an install.<br>
&gt;<br>
&gt; IF (WIN32)<br>
&gt; IF (GET_RUNTIME)<br>
&gt; INSTALL(FILES<br>
&gt;                &quot;${QT_BINARY_DIR}/QtCored${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                &quot;${QT_BINARY_DIR}/QtXmld${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                &quot;${QT_BINARY_DIR}/QtTestd${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                &quot;${QT_BINARY_DIR}/QtGuid${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                &quot;${QT_BINARY_DIR}/QtNetworkd${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                &quot;${QT_BINARY_DIR}/QtScriptd${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                DESTINATION ${EXECUTABLE_OUTPUT_PATH}/Debug<br>
&gt; )<br>
&gt; INSTALL(FILES<br>
&gt;                &quot;${QT_BINARY_DIR}/QtCore${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                &quot;${QT_BINARY_DIR}/QtXml${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                &quot;${QT_BINARY_DIR}/QtTest${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                &quot;${QT_BINARY_DIR}/QtGui${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                &quot;${QT_BINARY_DIR}/QtNetwork${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                &quot;${QT_BINARY_DIR}/QtScript${QT_VERSION_MAJOR}.dll&quot;<br>
&gt;                DESTINATION ${EXECUTABLE_OUTPUT_PATH}/RelWithDebInfo<br>
&gt; )<br>
&gt; ENDIF(GET_RUNTIME)<br>
&gt; ENDIF(WIN32)<br>
&gt;<br>
&gt; The second uses a custom build step:<br>
&gt;<br>
&gt; # Copy the needed Qt libraries into the Build directory. Also add installation<br>
&gt; # and CPack code to support installer generation.<br>
&gt; # this is a complete hack for Visual Studio to copy the Qt libraries.<br>
&gt; if ( NOT Q_WS_MAC)<br>
&gt;   if (DEFINED QT_QMAKE_EXECUTABLE)<br>
&gt;       SET (QTLIBLIST QtCore QtGui)<br>
&gt;<br>
&gt;       IF (MSVC)<br>
&gt;           set(TYPE &quot;d&quot;)<br>
&gt;           FOREACH(qtlib ${QTLIBLIST})<br>
&gt;             IF (WIN32)<br>
&gt;               GET_FILENAME_COMPONENT(QT_DLL_PATH_tmp<br>
&gt; ${QT_QMAKE_EXECUTABLE} PATH)<br>
&gt;               file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Debug)<br>
&gt;               file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Release)<br>
&gt;               file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/MinSizeRel)<br>
&gt;               file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/RelWithDebInfo)<br>
&gt;               INSTALL(FILES ${QT_DLL_PATH_tmp}/${qtlib}${type}d4.dll<br>
&gt;                   DESTINATION ./<br>
&gt;                   CONFIGURATIONS Debug<br>
&gt;                   COMPONENT Applications)<br>
&gt;               INSTALL(FILES ${QT_DLL_PATH_tmp}/${qtlib}4.dll<br>
&gt;                   DESTINATION ./<br>
&gt;                   CONFIGURATIONS Release<br>
&gt;                   COMPONENT Applications)<br>
&gt;               add_custom_target(ZZ_${qtlib}-Debug-Copy ALL<br>
&gt;                           COMMAND ${CMAKE_COMMAND} -E<br>
&gt;                                                        copy_if_different ${QT_DLL_PATH_tmp}/${qtlib}${TYPE}4.dll<br>
&gt;                           ${PROJECT_BINARY_DIR}/Debug/<br>
&gt;                           COMMENT &quot;Copying ${qtlib}${TYPE}4.dll to<br>
&gt; ${PROJECT_BINARY_DIR}/Debug/&quot;)<br>
&gt;               add_custom_target(ZZ_${qtlib}-Release-Copy ALL<br>
&gt;                           COMMAND ${CMAKE_COMMAND} -E<br>
&gt;                                                   copy_if_different ${QT_DLL_PATH_tmp}/${qtlib}4.dll<br>
&gt;                           ${PROJECT_BINARY_DIR}/Release/<br>
&gt;                           COMMENT &quot;Copying ${qtlib}4.dll to<br>
&gt; ${PROJECT_BINARY_DIR}/Release/&quot;)<br>
&gt;             ENDIF (WIN32)<br>
&gt;           ENDFOREACH(qtlib)<br>
&gt;<br>
&gt;       endif(MSVC)<br>
&gt;   endif(DEFINED QT_QMAKE_EXECUTABLE)<br>
&gt; endif(NOT Q_WS_MAC)<br>
&gt;<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; So, in summary, I think cmake is completely ignoring libexpat, even when I<br>
&gt;&gt; explicitly tell it (in the gui) where the include and library files are.<br>
&gt;&gt;<br>
&gt;&gt; Any ideas?<br>
&gt;&gt;<br>
&gt; Follow the advice by Stefan. I too believe that is the reason why the<br>
&gt; include did not work.<br>
&gt;<br>
&gt; 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 &quot;Debug;Release&quot;)<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 &quot;QT_${QTLIB}_LIBRARY_${BTYPE}:<br>
${QT_${QTLIB}_LIBRARY_${BTYPE}}&quot;)<br>
            GET_FILENAME_COMPONENT(DLL_NAME<br>
${QT_${QTLIB}_LIBRARY_${BTYPE}} NAME_WE)<br>
           # message(STATUS &quot;DLL_NAME: ${DLL_NAME}&quot;)<br>
            GET_FILENAME_COMPONENT(QT_BIN_PATH ${QT_QMAKE_EXECUTABLE} PATH)<br>
           # message(STATUS &quot;QT_BIN_PATH: ${QT_BIN_PATH}&quot;)<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 &quot;Copying<br>
${QT_BIN_PATH}/${DLL_NAME}.dll to<br>
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${btype}/&quot;)<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 &quot;QT_${QTLIB}_LIBRARY_${BTYPE}:<br>
${QT_${QTLIB}_LIBRARY_${BTYPE}}&quot;)<br>
            GET_FILENAME_COMPONENT(DLL_NAME<br>
${QT_${PLUGIN}_PLUGIN_${BTYPE}} NAME_WE)<br>
           # message(STATUS &quot;DLL_NAME: ${DLL_NAME}&quot;)<br>
           # GET_FILENAME_COMPONENT(QT_BIN_PATH ${QT_QMAKE_EXECUTABLE} PATH)<br>
           # message(STATUS &quot;QT_BIN_PATH: ${QT_BIN_PATH}&quot;)<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 &quot;Copying<br>
${QT_PLUGINS_DIR}/imageformats/${DLL_NAME}.dll to<br>
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${btype}/plugins/imageformats&quot;)<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 &quot;&quot;)<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>