Commit d2b7b724 authored by Bart van der Velden's avatar Bart van der Velden

Merge branch 'master' of gitorious.org:musiccollection/musiccollection

Conflicts:
	INSTALL
parents f7683c3e af1fc0aa
......@@ -22,5 +22,8 @@
#-----------------------------------------------------------------------------
# Add the Google C++ Testing Framework
# gtest_force_shared_crt must be set to true, at least in Windows but it doesn't seem to
# hurt on Linux
set(gtest_force_shared_crt on CACHE BOOL "Use a shared runtime library for Google Test" FORCE)
add_subdirectory(gmock-1.7.0)
......@@ -48,7 +48,7 @@ enable_testing()
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR
"CMake generation for is not allowed within the source directory!"
"\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
"\n Remove the CMakeCache.txt file and try again from another directory, e.g.:"
"\n "
"\n rm CMakeCache.txt"
"\n cd .."
......@@ -72,10 +72,8 @@ set(TEST_DATA_PATH ${CMAKE_CURRENT_SOURCE_DIR}/data/testdata)
#-----------------------------------------------------------------------------
# Enable modules
#-----------------------------------------------------------------------------
# Global compiler flags
include(PedanticCompilerWarnings)
include(EnableCoverageReport) # Enable settings for coverage calculation
include(PedanticCompilerWarnings) # Global compiler flags
#-----------------------------------------------------------------------------
# Fix for compiling Google Mock and Test with Visual Studio 2012, see:
......@@ -102,4 +100,4 @@ add_subdirectory(src)
if(CMAKE_DEBUG)
include(CMakeVariableLogging)
endif(CMAKE_DEBUG)
\ No newline at end of file
endif(CMAKE_DEBUG)
------------------------------------------
How to build MusicCollection
============================
This file contains the steps that are needed to build MusicCollection from source.
These steps will certainly not cover every system that exists, so additional steps
may be necessary.
Prerequisites:
==============
- Have boost installed >= 1.55
- Have cmake >= 2.8.12 installed
- Have taglib installed >= 1.9.1
- Have Qt installed >= 5.0
Building on Linux:
=================
The following steps were obtained from getting MusicCollection to work on Kubuntu
13.10 (my home system, as well as one running within VirtualBox) and Linux Mint 16
Cinnamon. All these systems are Debian/Ubuntu based, so you need to adjust for other
systems.
Install CMake
-------------
- Install: sudo apt-get install cmake
Install Boost
-------------
- Install: sudo apt-get install libbz2-dev
- Install: sudo apt-get install python-dev
- wget http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.bz2/download
- mv download boost.tar.bz2
- tar xvfj boost_1_xx_x.tar.bz2
- check for patches and install these
- cd boost_1_xx
- ./bootstrap
- ./b2 -j4 link=shared threading=multi runtime-link=shared stage
- sudo ./b2 install
Install taglib
--------------
- wget http://taglib.github.io/releases/taglib-1.9.1.tar.gz
- tar xfvz taglib-1.9.1.tar.gz
- cd taglib-1.9.1/
- cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Debug .
- make
- sudo make install
Install Qt Creator
------------------
- Download the "Qt Online Installer for Linux 64-bit" from qt-project.org
- chmod +x the run file
- sudo ./qt...run to start installation but do not "Launch Qt Creator" at the end of
the installation process, otherwise we get permission problems as a normal user
- When running from VirtualBox Disable 3D acceleration in VirtualBox because the Qml
welcome screen misbehaves
- make the correct Qt libraries available, in my case I added the following line to
~/.profile
export CMAKE_PREFIX_PATH=/opt/Qt/5.2.1/gcc_64/lib/cmake/Qt5Widgets/
On my Jenkins server, without X, I needed to install qt5-default. This gives Qt 5.02
versions, which suffices for now.
Install git
-----------
- sudo apt-get install git
Clone the MusicCollection source
--------------------------------
To clone my MusicCollection repository go to:
https://gitorious.org/musiccollection/musiccollection
and find out what to use.
For example:
git clone https://git.gitorious.org/musiccollection/musiccollection.git
This will create a directory called musiccollection in the current directory.
However, you cannot push changes back to the repository, so you may want to fork my
repository, clone that and change it to your hearts content. If you then want to
inflict your changes on me, just create a pull request, and I will have a look.
Build MusicCollection and run unit tests
----------------------------------------
The software must be built in a different directory than where the source is
(assuming you are in the directory musiccollection):
- cd ..
- mkdir buildmusiccollection
- cd buildmusiccollection
- cmake -DCMAKE_BUILD_TYPE=Debug ../musiccollection
- make
- make test
For a release build use -DCMAKE_BUILD_TYPE=Release
If all went well, the software is now built and the unit tests were performed without
error.
As a more convenient alternative, you can also build from Qt Creator:
- Start Qt Creator
- Click Open Project and select the file MusicCollection/CMakeLists.txt
- Accept the suggested Build Location
- Enter -DCMAKE_BUILD_TYPE=Debug at Arguments and check that a Desktop Generator is
selected
- Click Run CMake
- Click Finish
- The project is now opened
- Ctrl-Shift-B to build all
Of course, you can also use KDevelop and any other IDE that supports CMake.
Linux trivia
------------
To enable debugging (when you get the error "ptrace: operation not permitted")
- sudo nano /etc/sysctl.d/10-ptrace.conf
- change the line to read: kernel.yama.ptrace_scope = 0
- Have boost installed >= 1.55
- Have cmake >= 2.8.11 installed
- Have taglib installed >= 1.9
- Have Qt installed >= 5.0
For Qt: set CMAKE_PREFIX_PATH to the path where Qt is installed, i.e. C:\Qt\5.1.1\msvc2010 on my
Windows machine.
On Linux:
Install TagLib:
- wget http://taglib.github.io/releases/taglib-1.9.1.tar.gz
- tar xvf taglib-1.9.1.tar.gz
- cd taglib-1.9.1/
- cmake .
- make
- sudo make install
On openSUSE:
- sudo zypper install taglib-devel
- Create a build directory on the same level as MusicCollection: mkdir build
- cd build
- Configure cmake: cmake ../MusicCollection
- Build the software: make
- Run the software: ./musiccollection
Building on Windows
===================
<<<<<<< HEAD
- Sometimes the Qt5 cmake files cannot be found. In that case run something similar to: cmake -DCMAKE_PREFIX_PATH=/opt/Qt/5.2.0/gcc_64 ../musiccollection
- To build a debug version: cmake -DCMAKE_BUILD_TYPE:STRING=Debug ../MusicCollection
- After that: gdb musiccollection
=======
These steps were obtained from getting MusicCollection to work on two systems, one a
64 bit Windows 7 Enterprise and one 64 bit Windows 7 Home Premium.
>>>>>>> af1fc0aa18231ea4432be3cff91133ef23539bf6
Install CMake
-------------
- Download a Windows installer from http://cmake.org/cmake/resources/software.html
- Run the installer
Install Boost
-------------
Install taglib
--------------
Install Qt Creator
------------------
For Qt: set CMAKE_PREFIX_PATH to the path where Qt is installed, i.e.
C:\Qt\5.2.1\msvc2010 on my
Windows machine.
On Windows:
......
# - Creates a special coverage build type and target on GCC.
#
# Defines a function ENABLE_COVERAGE_REPORT which generates the coverage target
# for selected targets. Optional arguments to this function are used to filter
# unwanted results using globbing expressions. Moreover targets with tests for
# the source code can be specified to trigger regenerating the report if the
# test has changed
#
# ENABLE_COVERAGE_REPORT(TARGETS target... [FILTER filter...] [TESTS test targets...])
#
# To generate a coverage report first build the project with
# CMAKE_BUILD_TYPE=coverage, then call make test and afterwards make coverage.
#
# The coverage report is based on gcov. Depending on the availability of lcov
# a HTML report will be generated and/or an XML report of gcovr is found.
# The generated coverage target executes all found solutions. Special targets
# exist to create e.g. only the xml report: coverage-xml.
#
# Copyright (C) 2010 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
#
# This file may be licensed under the terms of the
# GNU Lesser General Public License Version 3 (the ``LGPL''),
# or (at your option) any later version.
#
# Software distributed under the License is distributed
# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
# express or implied. See the LGPL for the specific language
# governing rights and limitations.
#
# You should have received a copy of the LGPL along with this
# program. If not, go to http://www.gnu.org/licenses/lgpl.html
# or write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The development of this software was supported by:
# CoR-Lab, Research Institute for Cognition and Robotics
# Bielefeld University
#
# Adapted by Bart van der Velden (bart@muckingabout.eu)
find_package(Lcov QUIET)
find_package(gcovr QUIET)
......@@ -19,25 +19,33 @@
<!-- Create the logs directory -->
<mkdir dir="${logdir}" />
<!--
unittest is the target to run unit tests
-->
<target name="unittest">
<echo message="Running unit tests" />
<!-- Run the actual unit tests -->
<exec
executable="${bindir}/runUtilsTest"
output="${logdir}/runUtilsTest.log"
append="false">
<arg value="--gtest_output=xml:${logdir}/test_UtilsTest.xml" />
</exec>
<exec
executable="${bindir}/runCollectionTest"
output="${logdir}/runCollectionTest.log"
append="false">
<arg value="--gtest_output=xml:${logdir}/test_CollectionTest.xml" />
</exec>
<!-- Macro to factor out the common code for each unit test -->
<macrodef name="run_unit_test">
<attribute name="executable" />
<sequential>
<echo message="executable = ${bindir}/@{executable}" />
<echo message="output = ${logdir}/@{executable}.log" />
<echo message="arg = --gtest_output=xml:${logdir}/test_@{executable}.xml" />
<exec
executable="${bindir}/@{executable}"
output="${logdir}/@{executable}.log"
append="false">
<arg value="--gtest_output=xml:${logdir}/test_@{executable}.xml" />
</exec>
</sequential>
</macrodef>
<!-- Run the actual unit tests -->
<run_unit_test executable="runUtilsTest" />
<run_unit_test executable="runCollectionTest" />
<run_unit_test executable="runMusicCollectionTest" />
</target>
<!--
......
......@@ -22,6 +22,9 @@
set (MUSICCOLLECTION_VERSION_MAJOR 0)
set (MUSICCOLLECTION_VERSION_MINOR 1)
# The copyright string
set (MUSICCOLLECTION_COPYRIGHT "Copyright 2012-2014 Bart van der Velden <bart@muckingabout.eu>")
# Configure a header file to pass some of the CMake settings
# to the source code
configure_file (
......@@ -81,14 +84,16 @@ if (test)
# gtest_force_shared_crt must be set to true, at least in Windows but it doesn't seem to
# hurt on Linux
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(gtest_force_shared_crt ON)
include_directories(
${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR})
${gtest_SOURCE_DIR}
${gmock_SOURCE_DIR}/include
${gmock_SOURCE_DIR})
# Where Google Test's libraries can be found.
link_directories(${gtest_BINARY_DIR})
link_directories(${gtest_BINARY_DIR} ${gmock_BINARY_DIR})
endif()
#--------------------------------------------------------------------
......@@ -170,26 +175,40 @@ endif()
#--------------------------------------------------------------------
# Add libraries
include_directories(.)
include_directories(${PROJECT_BINARY_DIR}/src)
include_directories(utils)
add_subdirectory(utils)
include_directories(collection)
add_subdirectory(collection)
add_subdirectory(test)
set(EXTRA_LIBS ${EXTRA_LIBS} utils collection)
set(EXTRA_LIBS ${EXTRA_LIBS} ${TAGLIB_LIBRARIES})
set(EXTRA_LIBS ${EXTRA_LIBS} ${Boost_LIBRARIES})
set(COMMON_SOURCES
HandleCommandLine.cpp
CommandLine.cpp
${PROJECT_BINARY_DIR}/src/version.cpp
)
set(COMMON_INCLUDES
version.h
CommandLine.h
HandleCommandLine.h
)
#--------------------------------------------------------------------
# Add the console application
set(CMD_SOURCES
${COMMON_SOURCES}
main.cpp
${PROJECT_BINARY_DIR}/src/version.cpp
)
set(CMD_INCLUDES
version.h
${COMMON_INCLUDES}
)
add_executable(musiccollection
......@@ -203,8 +222,8 @@ target_link_libraries(musiccollection ${EXTRA_LIBS})
# Add the test GUI application
set(GUI_SOURCES
${COMMON_SOURCES}
mainui.cpp
${PROJECT_BINARY_DIR}/src/version.cpp
ui/mainwindow.cpp
ui/about.cpp
)
......@@ -212,7 +231,7 @@ set(GUI_SOURCES
set(GUI_INCLUDES
ui/mainwindow.h
ui/about.h
version.h
${COMMON_INCLUDES}
)
set(UI
......
/*****************************************************************************
* Copyright 2014 Bart van der Velden <bart@muckingabout.eu> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#include "CommandLine.h"
#include <fstream>
#include <boost/program_options.hpp>
#include <boost/exception/all.hpp>
#include <boost/exception/get_error_info.hpp>
#include "version.h"
CommandLine::CommandLine()
{
}
CommandLine::~CommandLine()
{
}
bool CommandLine::ParseCommandLine()
{
return false;
}
std::vector<boost::filesystem::path> CommandLine::GetDirectories() const
{
std::vector<boost::filesystem::path> directories;
return directories;
}
boost::filesystem::path CommandLine::GetLogFile() const
{
boost::filesystem::path logFile;
return logFile;
}
std::string CommandLine::GetErrorMessage() const
{
std::string retVal;
return retVal;
}
std::string CommandLine::GetLogMessage() const
{
std::string retVal;
return retVal;
}
/*****************************************************************************
* Copyright 2014 Bart van der Velden <bart@muckingabout.eu> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#ifndef MUSICCOLLECTION_COMMANDLINE_H_INCLUDED
#define MUSICCOLLECTION_COMMANDLINE_H_INCLUDED
#include <vector>
#include <boost/filesystem.hpp>
class CommandLine
{
public:
explicit CommandLine();
virtual ~CommandLine();
virtual bool ParseCommandLine();
virtual std::vector<boost::filesystem::path> GetDirectories() const;
virtual boost::filesystem::path GetLogFile() const;
virtual std::string GetErrorMessage() const;
virtual std::string GetLogMessage() const;
private:
};
#endif // MUSICCOLLECTION_COMMANDLINE_H_INCLUDED
/*****************************************************************************
* Copyright 2014 Bart van der Velden <bart@muckingabout.eu> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#include "HandleCommandLine.h"
#include <fstream>
#include <boost/program_options.hpp>
#include <boost/exception/all.hpp>
#include <boost/exception/get_error_info.hpp>
#include "version.h"
using namespace std;
namespace fs = boost::filesystem;
namespace po = boost::program_options;
static const char* DefaultLogFile = "mc";
static const char* DefaultConfigFile = "musiccollection.cfg";
void AddErrorMessage(string& orgMessage, const string& newMessage)
{
if (orgMessage.length() == 0)
{
orgMessage = newMessage;
}
else
{
orgMessage += "\n";
orgMessage += newMessage;
}
}
//! Parse the command line
/*! The options for this program can come from two sources: the command line and a (default)
configuration file.
--help, --h or -h : show the help. This option can only be combined with the version command
Any other command or configuration will be ignored. This option is only available from the
command line.
--version, --v pr -v: show the version. This option can only be combined with the help command.
Any other command or configuration will be ignored. This option is only available from the
command line.
--configfile: read options from the supplied configuration file. If this option is not given,
an attempt is made to read from the file musiccollection.cfg in the current directory.
Options
found in the configuration file are merged with options given on the command line.
*/
bool HandleCommandLine(
int argc,
char **argv,
vector<fs::path>& directories ,
fs::path& logFile,
string& message)
{
auto retVal = true;
try
{
po::positional_options_description pod;
pod.add("directory", -1);
po::variables_map vm;
fs::path configFile(DefaultConfigFile);
// Generic options: help and version. These can only be used from the command line
po::options_description genericOptions("Generic options");
genericOptions.add_options()
("help,h", "show this help")
("version,v", "show version information")
("configfile",
po::value<fs::path>(&configFile)->default_value(DefaultConfigFile),
"the configuration file to read for other options. musiccollection.cfg is used "
"if no configuration file name is supplied");
// Configuration options: logfile and directories. These can be used both from
// the command line and a configuration file. Only one logfile is used. If a logfile is
// specified on the command line and in the configuration file, the command line option
// takes precedence. Multiple directory values from the command line and the configuration
// file are merged.
po::options_description configOptions("Configuration");
configOptions.add_options()
("logfile",
po::value<fs::path>(),
"the file to log to")
("directory",
po::value<vector<fs::path> >()->composing(),
"directory to scan. A directory can also be given without the --directory.");
po::options_description cmdLineOptions;
cmdLineOptions.add(genericOptions).add(configOptions);
try
{
po::store(po::command_line_parser(argc, argv).options(cmdLineOptions).positional(pod).run(), vm);
ifstream ifs(configFile.native());
po::store(po::parse_config_file(ifs, configOptions), vm);
po::notify(vm);
}
catch (boost::program_options::invalid_syntax& e)
{
stringstream ss;
ss << "Caught an invalid_syntax exception: " << e.what();
AddErrorMessage(message, ss.str());
retVal = false;
}
if (vm.count("help"))
{
// Help is the only action required.
stringstream ss;
ss << cmdLineOptions;
AddErrorMessage(message, ss.str());
retVal = false;
}
if (vm.count("version"))
{
// version may be asked at the same time as help, but it doesn't have to be
// The program will not continue after asking it for its version information
Version version;
stringstream ss;
ss << "MusicCollection, version: " << version.GetMajor() << "." <<
version.GetMinor() << ", git revision: " << version.GetGitSha1() << "\n";
ss << version.Copyright() << "\n";
AddErrorMessage(message, ss.str());
retVal = false;
}
if (retVal == true)
{
if (vm.count("directory") == 0)
{
stringstream ss;
ss << "Need to supply at least one directory\n";
ss << cmdLineOptions << "\n";
AddErrorMessage(message, ss.str());
retVal = false;
}
else
{
cout << "Directories are: \n";
directories = vm["directory"].as< vector<fs::path> >();
for (vector<fs::path>::iterator it = directories .begin(); it != directories .end(); ++it)
{
//cout << "\t" << *it << "\n";
}
}
if (vm.count("logfile") == 1)
{
logFile = vm["logfile"].as<fs::path> ();
}
else
{
logFile = DefaultLogFile;
}
}
}
catch(po::unknown_option& option)
{
stringstream ss;
ss << "Unknown option: " << option.get_option_name() << "\n";
AddErrorMessage(message, ss.str());
retVal = false;
}
catch(boost::exception&)
{
stringstream ss;
ss << "Unhandled exception: " << "\n";
ss << boost::current_exception_diagnostic_information() << "\n";
AddErrorMessage(message, ss.str());
retVal = false;
}
return retVal;
}
/*****************************************************************************
* Copyright 2014 Bart van der Velden <bart@muckingabout.eu> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#ifndef MUSICCOLLECTION_HANDLECOMMANDLINE_H_INCLUDED
#define MUSICCOLLECTION_HANDLECOMMANDLINE_H_INCLUDED
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
//! Parse the command line
/*! The options for this program can come from two sources: the command line and a (default)
configuration file.
--help, --h or -h : show the help. This option can only be combined with the version command
Any other command or configuration will be ignored. This option is only available from the
command line.
--version, --v pr -v: show the version. This option can only be combined with the help command.
Any other command or configuration will be ignored. This option is only available from the
command line.
--configfile: read options from the supplied configuration file. If this option is not given,
an attempt is made to read from the file musiccollection.cfg in the current directory.
Options
found in the configuration file are merged with options given on the command line.
\param argc the original argc as received through main()
\param argv the original argv as received through main()
\param directories the directories that were given as argument or read from the configuration
file
\param logFile the path to the logfile either as argument or read from the configuration file
\param message an error message when the function returns false
\return True if no errors occurred, otherwise false
*/
bool HandleCommandLine(int argc,
char** argv,
std::vector<boost::filesystem::path>& directories,
boost::filesystem::path& logFile,
std::string& message);