Fix build on Windows.
[dcpomatic.git] / src / lib / environment_info.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "log.h"
21 #include "compose.hpp"
22 #include "version.h"
23 #include "cross.h"
24 #include <dcp/version.h>
25 #include <libssh/libssh.h>
26 #ifdef DCPOMATIC_IMAGE_MAGICK
27 #include <magick/MagickCore.h>
28 #else
29 #include <magick/common.h>
30 #include <magick/magick_config.h>
31 #endif
32 #include <magick/version.h>
33 extern "C" {
34 #include <libavcodec/avcodec.h>
35 #include <libavformat/avformat.h>
36 #include <libswscale/swscale.h>
37 #include <libavfilter/avfiltergraph.h>
38 #include <libavutil/pixfmt.h>
39 }
40 #include <boost/thread.hpp>
41
42 #include "i18n.h"
43
44 #define LOG_GENERAL(...) log->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
45 #define LOG_GENERAL_NC(...) log->log (__VA_ARGS__, LogEntry::TYPE_GENERAL);
46
47 using std::string;
48 using std::list;
49 using std::pair;
50 using boost::shared_ptr;
51
52 /** @param v Version as used by FFmpeg.
53  *  @return A string representation of v.
54  */
55 static
56 string
57 ffmpeg_version_to_string (int v)
58 {
59         SafeStringStream s;
60         s << ((v & 0xff0000) >> 16) << N_(".") << ((v & 0xff00) >> 8) << N_(".") << (v & 0xff);
61         return s.str ();
62 }
63
64
65 /** Return a user-readable string summarising the versions of our dependencies */
66 static
67 string
68 dependency_version_summary ()
69 {
70         SafeStringStream s;
71         s << N_("libavcodec ") << ffmpeg_version_to_string (avcodec_version()) << N_(", ")
72           << N_("libavfilter ") << ffmpeg_version_to_string (avfilter_version()) << N_(", ")
73           << N_("libavformat ") << ffmpeg_version_to_string (avformat_version()) << N_(", ")
74           << N_("libavutil ") << ffmpeg_version_to_string (avutil_version()) << N_(", ")
75           << N_("libswscale ") << ffmpeg_version_to_string (swscale_version()) << N_(", ")
76           << MagickVersion << N_(", ")
77           << N_("libssh ") << ssh_version (0) << N_(", ")
78           << N_("libdcp ") << dcp::version << N_(" git ") << dcp::git_commit;
79
80         return s.str ();
81 }
82
83 list<string>
84 environment_info ()
85 {
86         list<string> info;
87
88         info.push_back (String::compose ("DCP-o-matic %1 git %2 using %3", dcpomatic_version, dcpomatic_git_commit, dependency_version_summary()));
89
90         {
91                 char buffer[128];
92                 gethostname (buffer, sizeof (buffer));
93                 info.push_back (String::compose ("Host name %1", buffer));
94         }
95
96 #ifdef DCPOMATIC_DEBUG
97         info.push_back ("DCP-o-matic built in debug mode.");
98 #else
99         info.push_back ("DCP-o-matic built in optimised mode.");
100 #endif
101 #ifdef LIBDCP_DEBUG
102         info.push_back ("libdcp built in debug mode.");
103 #else
104         info.push_back ("libdcp built in optimised mode.");
105 #endif
106
107 #ifdef DCPOMATIC_WINDOWS
108         OSVERSIONINFO os_info;
109         os_info.dwOSVersionInfoSize = sizeof (os_info);
110         GetVersionEx (&os_info);
111         info.push_back (
112                 String::compose (
113                         "Windows version %1.%2.%3 SP %4",
114                         os_info.dwMajorVersion, os_info.dwMinorVersion, os_info.dwBuildNumber, os_info.szCSDVersion
115                         )
116                 );
117 #endif
118
119 #if __GNUC__
120 #if __x86_64__
121         info.push_back ("Built for 64-bit");
122 #else
123         info.push_back ("Built for 32-bit");
124 #endif
125 #endif
126
127         info.push_back (String::compose ("CPU: %1, %2 processors", cpu_info(), boost::thread::hardware_concurrency ()));
128         list<pair<string, string> > const m = mount_info ();
129         for (list<pair<string, string> >::const_iterator i = m.begin(); i != m.end(); ++i) {
130                 info.push_back (String::compose ("Mount: %1 %2", i->first, i->second));
131         }
132
133         return info;
134 }