Add CMake; prepare basic structure

- Added Catch (downloaded automatically by cmake) for unit tests
- Added basic tests/ and src/ directories
- Added basic unit test example. Any changes to files other than main.cc
  in src/ will recompile the relevant tests as needed
- Added CMakeLists that compiles the project using cmake
- Moved the man page to docs/
- Moved old source file to src/
- Since libogg doesn't support cmake based builds, I've added also a
  module in CMakeModules that searches for it, but I haven't tested if
  it works yet...
- Haven't really touched Makefile - I've changed it only to refer to the
  new file locations
This commit is contained in:
rr- 2016-02-19 19:31:51 +01:00 committed by Frédéric Mangano
parent fcd647003b
commit 5cdcb5457f
11 changed files with 112 additions and 3 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/build
tests/catch.h

55
CMakeLists.txt Normal file
View File

@ -0,0 +1,55 @@
cmake_minimum_required (VERSION 2.8.8)
project (opustags)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/modules/")
# ------------
# Dependencies
# ------------
find_package(Ogg REQUIRED)
include_directories(${ogg_INCLUDE_DIR})
link_directories(${ogg_LIBRARY_DIRS})
# --------------------
# Global build options
# --------------------
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") # for MinGW-w64
endif()
# ------------
# Source files
# ------------
set(CMAKE_SOURCE_DIR "${CMAKE_BINARY_DIR}/../")
file(GLOB_RECURSE common_sources "${CMAKE_SOURCE_DIR}/src/*.cc")
file(GLOB_RECURSE common_headers "${CMAKE_SOURCE_DIR}/src/*.h")
file(GLOB_RECURSE test_sources "${CMAKE_SOURCE_DIR}/tests/*.cc")
file(GLOB_RECURSE test_headers "${CMAKE_SOURCE_DIR}/tests/*.h")
list(REMOVE_ITEM common_sources "${CMAKE_SOURCE_DIR}/src/main.cc")
list(REMOVE_ITEM test_sources "${CMAKE_SOURCE_DIR}/tests/main.cc")
# -------------------
# 3rd party libraries
# -------------------
# Catch
set(CATCH_PATH "${CMAKE_SOURCE_DIR}/tests/catch.h")
if (NOT EXISTS "${CATCH_PATH}")
message("Downloading Catch...")
file(DOWNLOAD "http://raw.githubusercontent.com/philsquared/Catch/master/single_include/catch.hpp" "${CATCH_PATH}")
endif()
# -------------------
# Linking definitions
# -------------------
add_library(common OBJECT ${common_sources} ${common_headers})
add_executable(opustags "${CMAKE_SOURCE_DIR}/src/main.cc" $<TARGET_OBJECTS:common>)
add_executable(run_tests "${CMAKE_SOURCE_DIR}/tests/main.cc" $<TARGET_OBJECTS:common> ${test_sources} ${test_headers})
target_include_directories(common BEFORE PUBLIC "${CMAKE_SOURCE_DIR}/src")
target_include_directories(opustags BEFORE PUBLIC "${CMAKE_SOURCE_DIR}/src")
target_include_directories(run_tests BEFORE PUBLIC "${CMAKE_SOURCE_DIR}/src")
target_include_directories(run_tests BEFORE PUBLIC "${CMAKE_SOURCE_DIR}/tests")

View File

@ -5,10 +5,10 @@ LDFLAGS=-logg
all: opustags
opustags: opustags.c
opustags: src/opustags.c
man: opustags.1
gzip <opustags.1 >opustags.1.gz
man: doc/opustags.1
gzip <doc/opustags.1 >opustags.1.gz
install: opustags man
mkdir -p $(DESTDIR)/bin $(DESTDIR)/$(MANDEST)/man1

23
modules/FindOgg.cmake Normal file
View File

@ -0,0 +1,23 @@
# Base Io build system
# Written by Jeremy Tregunna <jeremy.tregunna@me.com>
#
# Find libogg.
FIND_PATH(OGG_INCLUDE_DIR ogg/ogg.h)
SET(OGG_NAMES ${OGG_NAMES} ogg libogg)
FIND_LIBRARY(OGG_LIBRARY NAMES ${OGG_NAMES} PATH)
IF(OGG_INCLUDE_DIR AND OGG_LIBRARY)
SET(OGG_FOUND TRUE)
ENDIF(OGG_INCLUDE_DIR AND OGG_LIBRARY)
IF(OGG_FOUND)
IF(NOT Ogg_FIND_QUIETLY)
MESSAGE(STATUS "Found Ogg: ${OGG_LIBRARY}")
ENDIF (NOT Ogg_FIND_QUIETLY)
ELSE(OGG_FOUND)
IF(Ogg_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find ogg")
ENDIF(Ogg_FIND_REQUIRED)
ENDIF (OGG_FOUND)

6
src/dummy.cc Normal file
View File

@ -0,0 +1,6 @@
#include "dummy.h"
int opustags::return_one()
{
return 1;
}

6
src/dummy.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
namespace opustags
{
int return_one();
}

8
src/main.cc Normal file
View File

@ -0,0 +1,8 @@
#include <iostream>
#include "dummy.h"
int main(int argc, const char **argv)
{
std::cout << opustags::return_one() << std::endl;
return 0;
}

7
tests/dummy_test.cc Normal file
View File

@ -0,0 +1,7 @@
#include "dummy.h"
#include "catch.h"
TEST_CASE("A dummy test")
{
REQUIRE(opustags::return_one() == 1);
}

2
tests/main.cc Normal file
View File

@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.h"