Sunday, July 1, 2012

build and install dbus with cmake, msvc and nmake

Here are the directions for building dbus using the cmake folder and Microsoft Visual Studio C++ (MSVC).
  1. Install MSVC of your choice, e.g.: 2008 Express (MSVC90) or  2010 Express (MSVC100), then get all updates and service packs.
  2. Download and install CMake (2.8.8). I'll list the software versions I used in parentheses.
  3. Download and install Expat (2.1.0)
  4. Download and install doxygen (1.8.1.1)
  5. Download and install NullSoft (2.46)
  6. Download and extract dbus (1.6.2) to folder with no spaces, e.g.: c:\dbus-1.6.2-msvc90
  7. Start CMake gui from start menu
  8. Enter the path to your source, e.g.: "C:\dbus-1.6.2-msvc90\cmake"
  9. Make a folder called, "build" in the same folder and enter it as the build directory, e.g.:  "C:\dbus-1.6.2-msvc90\cmake\build"
  10. add the following variables using the "Add Entry" button. The format I use here is NAME:TYPE=value, which is the how cmake expects it at the command line, but in the gui you just fill in the boxes.
    • LIBEXPAT_LIBRARIES:FILEPATH="C:\Program Files\Expat 2.1.0\Bin\libexpat.lib"
    • LIBEXPAT_INCLUDE_DIR:PATH="C:\Program Files\Expat 2.1.0\Source\lib"
  11. (UPDATED - 2012-07-17)  Optional: Edit CMakeLists.txt so that the default session address is autolaunch: instead of the nonce-tcp:, see the "D-Bus Windows help" thread in the mailing list.
    • DBUS_SYSTEM_BUS_DEFAULT_ADDRESS="autolaunch:"
  12. Click Configure, select either MSVC90 (Visual Studio 2008) or MSVC100 (Visual Studio 2010), then generate.
  13. close CMake and start MSVC from the start menu.
  14. Load the dbus.sln from the build folder you created in step 8.
  15. Select configuration manager from build pull down in menu bar, and select doc, INSTALL and PACKAGE.
  16. Build the solution.
  17. Make sure that all projects built successfully.
  18. If there are any errors clean the the solution, quit and go back to step 1.
  19. Use the configuration manager to change from Debug to Release, and build the solution again.
  20. (UPDATED - 2012-07-03) Copy the libexpat.dll to the dbus bin folder ("C:\Program Files\dbus\bin") and the libexpat.lib file to the dbus lib folder, otherwise you will get an error saying that dbus-daemon can't find expat application and that re-installing expat might fix the problem. Setting the PATH to include expat does not fix this issue, sorry. Not sure if dbus also needs library but it can't hurt.
  21. (UPDATED - 2012-07-03) Test the daemon using a windows command shell, navigate to the dbus bin folder and try dbus-daemon --session --print-address > dbus_address.txt (or whatever), and then open dbus_address select and copy the address. Note for added excitement, set DBUS_VERBOSE=1 first, and the dbus-daemon will display everything that it's thinking in the terminal, which gives you the sense that it's actually working!
  22. $ cd "C:\Program Files\dbus\bin"
    $ set DBUS_VERBOSE=1
    $ dbus-daemon --session --print-address > dbus_address.txt

  23. (UPDATED - 2012-07-03) Open another windows shell, navigate to the dbus bin folder again and set DBUS_SESSION_BUS_ADDRESS="<paste the address from the dbus_address.txt file here>". Don't forget the quotes, or you;'ll get a string of errors. (Note: if you edited the CMakeLists.txt file in the optional step 11, then you can just use dbus-monitor, and it should work out of the box.) Now type dbus-monitor --address %DBUS_SESSION_BUS_ADDRESS% and you should see the following text in the monitor shell (and a ton of stuff if you enabled verbose in the daemon shell):
  24. $ cd "C:\Program Files\dbus\bin"
    $ set DBUS_SESSION_BUS_ADDRESS="<paste from dbus_address.text, don't forget quotes>
    $ dbus-monitor --address %DBUS_SESSION_BUS_ADDRESS%
    signal sender=org.freedesktop.DBus -> dest=:1.0 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired   string ":1.0"
    method call sender=:1.0 -> dest=org.freedesktop.DBus serial=3 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch   string "eavesdrop=true,type='method_call'"
    method call sender=:1.0 -> dest=org.freedesktop.DBus serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch   string "eavesdrop=true,type='method_return'"
    method call sender=:1.0 -> dest=org.freedesktop.DBus serial=5 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch   string "eavesdrop=true,type='error'"

Done!

Now try using nmake.

from the start menu start msvc command prompt
add cmake to the path by typing the following:
    $ set PATH="C:\Program Files\Cmake-2.8.0\bin";%PATH%
change the folder where you extracted dbus, e.g. C:\dbus-1.6.0 and make a new folder called build
    $ cd C:\dbus-1.6.0
    $ mkdir build
    $ cd build
Run cmake with the following options
    $ cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=Release -D LIBEXPAT_LIBRARIES:FILEPATH="C:\Program Files\Expat 2.1.0\Bin\libexpat.lib" -D LIBEXPAT_INCLUDE_DIR:PATH="C:\Program Files\Expat 2.1.0\Source\lib" "C:\dbus-1.6.0\cmake"
Now build the solution
    $ nmake /A
then finally ...
    $ nmake install
I think you can build the package this way too ...
    $ nmake package

No comments:

Post a Comment

Fork me on GitHub