diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2015-03-30 08:12:41 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2015-03-30 08:12:41 +0200 |
commit | 954e0d148d2e6cc0d0e8d57cb8d4d1e8fc197103 (patch) | |
tree | 8a9e2c55c6daf99b6c5a69c4d6b1f9de6259c42a | |
parent | bcd836eb265cb5e44aeac6a343342f7b372056c6 (diff) | |
download | usdx-954e0d148d2e6cc0d0e8d57cb8d4d1e8fc197103.tar.gz usdx-954e0d148d2e6cc0d0e8d57cb8d4d1e8fc197103.tar.xz usdx-954e0d148d2e6cc0d0e8d57cb8d4d1e8fc197103.zip |
Remove plain makefiles. Use cmake.
-rw-r--r-- | CMakeLists.txt | 99 | ||||
-rw-r--r-- | Makefile | 33 | ||||
-rw-r--r-- | Makefile.inc | 30 | ||||
-rw-r--r-- | cmake/FindCppUnit.cmake | 18 | ||||
-rw-r--r-- | cmake/FindFTGL.cmake | 16 | ||||
-rw-r--r-- | cmake/FindSDL_gfx.cmake | 88 | ||||
-rw-r--r-- | cmake/Findlog4cpp.cmake | 7 | ||||
-rw-r--r-- | cmake/Require.cmake | 24 | ||||
-rw-r--r-- | test/Makefile | 78 |
9 files changed, 252 insertions, 141 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..2f0e768a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,99 @@ +cmake_minimum_required (VERSION 2.6) +project (usdx-cpp) + +set(cflags "-Wall -Werror -pedantic") +set(cxxflags "${cflags} -std=c++1y") +set(debug "-g -O0") + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${cflags}") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${debug}") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${cxxflags}") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${debug}") + +# +# dependency handling +# +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") +set(Boost_USE_MULTITHREADED "ON") + +include("Require") +require(FTGL) +require(Freetype) +require(SDL) +require(SDL_image) +require(SDL_gfx) +require(log4cpp) +require(Boost COMPONENTS filesystem locale program_options system thread) +require(OpenGL) + +# +# get main sources +# +include_directories(src/) +file(GLOB_RECURSE sources src/*.cpp) +list(REMOVE_ITEM sources "${CMAKE_SOURCE_DIR}/src/main.cpp") +add_library(objects OBJECT ${sources}) + +# +# main usdx binary +# +add_executable(usdx "src/main.cpp" $<TARGET_OBJECTS:objects>) +target_link_libraries(usdx ${LIBS}) + +# +# make run +# +add_custom_target(run + COMMAND usdx + DEPENDS usdx + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} +) + +# +# tests +# +include(CTest) + +if(BUILD_TESTING) + require_test(CppUnit) + + file(GLOB_RECURSE testing_sources test/*.cpp) + add_executable(test/usdx-test ${testing_sources} $<TARGET_OBJECTS:objects>) + target_link_libraries(test/usdx-test ${LIBS} ${TEST_LIBS}) + add_test(NAME test + COMMAND test/test + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/test/" + ) +endif() + +# +# tests with coverage +# +set(coverage-dir "${PROJECT_SOURCE_DIR}/test/coverage") + +add_executable(test/usdx-test-coverage EXCLUDE_FROM_ALL + ${testing_sources} ${sources}) +target_link_libraries(test/usdx-test-coverage ${LIBS} ${TEST_LIBS} "-coverage") +set_target_properties(test/usdx-test-coverage + PROPERTIES COMPILE_FLAGS "${debug} -fprofile-arcs -ftest-coverage") + +get_property(coverage-binary TARGET test/usdx-test-coverage PROPERTY LOCATION) +add_custom_target(test-coverage WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/test/" + # prepare coverage checks + COMMAND rm -f .error + COMMAND mkdir -p "${coverage-dir}" + COMMAND lcov --directory "${PROJECT_SOURCE_DIR}" --zerocounters + + # running checks and save result for later use + COMMAND sh -c \"${coverage-binary} || touch .error\" + + # building coverage pages + COMMAND lcov --directory "${PROJECT_SOURCE_DIR}" --capture --output-file "${coverage-dir}/coverage.info.tmp" + COMMAND lcov --extract "${coverage-dir}/coverage.info.tmp" "'${PROJECT_SOURCE_DIR}/src/*'" -o "${coverage-dir}/coverage.info" + COMMAND genhtml "${coverage-dir}/coverage.info" -o "${coverage-dir}/html/" -p "${PROJECT_SOURCE_DIR}/src" + + # returing check status + COMMAND test ! -e .error +) +add_dependencies(test-coverage test/usdx-test-coverage) diff --git a/Makefile b/Makefile deleted file mode 100644 index ee5c1138..00000000 --- a/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -TARGET:=usdx -include Makefile.inc - -headers+=$(wildcard src/*.hpp) -sources+=$(wildcard src/*.cpp) - -############################################################################## - -.PHONY: all clean run - -all: $(TARGET) - -clean: - -$(RM) -r $(TARGET) $(objects) $(deps) - -run: $(TARGET) - ./$(TARGET) - -ifneq ($(MAKECMDGOALS),clean) --include $(deps) -endif - -############################################################################## -# normal build - -$(TARGET): $(objects) $(deps) - $(CXX) $(LDFLAGS) -o $(TARGET) $(objects) - -%.o: %.cpp - $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ - -%.d: %.cpp - $(CXX) $(CXXFLAGS) -MM -c $< -MF $@ diff --git a/Makefile.inc b/Makefile.inc deleted file mode 100644 index 6d4fb05a..00000000 --- a/Makefile.inc +++ /dev/null @@ -1,30 +0,0 @@ -# -*- mode: makefile -*- -TOP:=$(dir $(lastword $(MAKEFILE_LIST))) - -headers+=$(wildcard $(TOP)src/*/*.hpp) $(wildcard $(TOP)src/*/*/*.hpp) -sources+=$(wildcard $(TOP)src/*/*.cpp) $(wildcard $(TOP)src/*/*/*.cpp) - -deps=$(sources:.cpp=.d) -objects=$(sources:.cpp=.o) - -# APPS -PKG_CONFIG:=pkg-config -LOG4CPP_CONFIG:=log4cpp-config - -# CFLAGS -PEDENTIC:=-Wall -Werror -DEBUG:=-g -INC_PATH:=-I$(TOP)src/ -FTGL_CFLAGS:=$(shell $(PKG_CONFIG) ftgl --cflags) - -# LDFLAGS -SQLITE_LDFLAGS:=-lsqlite3 -LOG4CPP_LDFLAGS:=$(shell $(LOG4CPP_CONFIG) --libs) -BOOST_LDFLAGS:=-lboost_program_options-mt -lboost_filesystem-mt -lboost_thread-mt -lboost_system-mt -SDL_LDFLAGS:=-lSDL -lSDL_image -lSDL_gfx -GL_LDFLAGS:=-lGL -FTGL_LDFLAGS:=$(shell $(PKG_CONFIG) ftgl --libs) - - -CXXFLAGS:=$(PEDENTIC) $(INC_PATH) $(DEBUG) $(FTGL_CFLAGS) -LDFLAGS:=$(SQLITE_LDFLAGS) $(LOG4CPP_LDFLAGS) $(BOOST_LDFLAGS) $(SDL_LDFLAGS) $(GL_LDFLAGS) $(FTGL_LDFLAGS) diff --git a/cmake/FindCppUnit.cmake b/cmake/FindCppUnit.cmake new file mode 100644 index 00000000..71d50356 --- /dev/null +++ b/cmake/FindCppUnit.cmake @@ -0,0 +1,18 @@ +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(CPPUNIT "cppunit") + +IF(CPPUNIT_FOUND) + + SET(CPPUNIT_LIBRARY "${CPPUNIT_LIBRARIES}") + +ELSE() + + FIND_PATH(CPPUNIT_INCLUDE_DIRS cppunit/TestCase.h) + FIND_LIBRARY(CPPUNIT_LIBRARY NAMES cppunit libcppunit) + + INCLUDE(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(CPPUNIT DEFAULT_MSG CPPUNIT_LIBRARY CPPUNIT_INCLUDE_DIRS) + + MARK_AS_ADVANCED(CPPUNIT_INCLUDE_DIRS CPPUNIT_LIBRARY) + +ENDIF() diff --git a/cmake/FindFTGL.cmake b/cmake/FindFTGL.cmake new file mode 100644 index 00000000..a5d44fb1 --- /dev/null +++ b/cmake/FindFTGL.cmake @@ -0,0 +1,16 @@ +# - Locate FTGL library +# This module defines +# FTGL_LIBRARIES, the library to link against +# FTGL_FOUND, if false, do not try to link to FTGL +# FTGL_INCLUDE_DIRS, where to find headers. +# +# $FTGL_DIR is an environment variable that points to the main ftgl directory. + +FIND_PATH(FTGL_INCLUDE_DIRS FTGL/ftgl.h HINTS $ENV{FTGL_DIR}) +FIND_LIBRARY(FTGL_LIBRARY NAMES ftgl libftgl ftgl_static HINTS $ENV{FTGL_DIR}) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(FTGL DEFAULT_MSG FTGL_LIBRARY FTGL_INCLUDE_DIRS) + +MARK_AS_ADVANCED(FTGL_LIBRARY FTGL_INCLUDE_DIRS) + diff --git a/cmake/FindSDL_gfx.cmake b/cmake/FindSDL_gfx.cmake new file mode 100644 index 00000000..314363c2 --- /dev/null +++ b/cmake/FindSDL_gfx.cmake @@ -0,0 +1,88 @@ +# - Locate SDL_gfx library +# This module defines: +# SDL_GFX_LIBRARIES, the name of the library to link against +# SDL_GFX_INCLUDE_DIRS, where to find the headers +# SDL_GFX_FOUND, if false, do not try to link against +# SDL_GFX_VERSION_STRING - human-readable string containing the version of SDL_gfx +# +# For backward compatiblity the following variables are also set: +# SDLGFX_LIBRARY (same value as SDL_GFX_LIBRARIES) +# SDLGFX_INCLUDE_DIR (same value as SDL_GFX_INCLUDE_DIRS) +# SDLGFX_FOUND (same value as SDL_GFX_FOUND) +# +# $SDLDIR is an environment variable that would +# correspond to the ./configure --prefix=$SDLDIR +# used in building SDL. +# +# Created by Eric Wing. This was influenced by the FindSDL.cmake +# module, but with modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). + +#============================================================================= +# Copyright 2005-2009 Kitware, Inc. +# Copyright 2012 Benjamin Eikel +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if(NOT SDL_GFX_INCLUDE_DIR AND SDLGFX_INCLUDE_DIR) + set(SDL_GFX_INCLUDE_DIR ${SDLGFX_INCLUDE_DIR} CACHE PATH "directory cache +entry initialized from old variable name") +endif() +find_path(SDL_GFX_INCLUDE_DIR SDL_gfxPrimitives.h + HINTS + ENV SDLGFXDIR + ENV SDLDIR + PATH_SUFFIXES include/SDL include/SDL12 include/SDL11 include +) + +if(NOT SDL_GFX_LIBRARY AND SDLGFX_LIBRARY) + set(SDL_GFX_LIBRARY ${SDLGFX_LIBRARY} CACHE FILEPATH "file cache entry +initialized from old variable name") +endif() +find_library(SDL_GFX_LIBRARY + NAMES SDL_gfx + HINTS + ENV SDLGFXDIR + ENV SDLDIR + PATH_SUFFIXES lib +) + +if(SDL_GFX_INCLUDE_DIR AND EXISTS "${SDL_GFX_INCLUDE_DIR}/SDL_gfxPrimitives.h") + file(STRINGS "${SDL_GFX_INCLUDE_DIR}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_GFX_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_GFX_INCLUDE_DIR}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_GFX_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL_GFX_INCLUDE_DIR}/SDL_gfxPrimitives.h" SDL_GFX_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_GFX_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_GFX_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MAJOR "${SDL_GFX_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_GFX_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_MINOR "${SDL_GFX_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_GFX_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_GFX_VERSION_PATCH "${SDL_GFX_VERSION_PATCH_LINE}") + set(SDL_GFX_VERSION_STRING ${SDL_GFX_VERSION_MAJOR}.${SDL_GFX_VERSION_MINOR}.${SDL_GFX_VERSION_PATCH}) + unset(SDL_GFX_VERSION_MAJOR_LINE) + unset(SDL_GFX_VERSION_MINOR_LINE) + unset(SDL_GFX_VERSION_PATCH_LINE) + unset(SDL_GFX_VERSION_MAJOR) + unset(SDL_GFX_VERSION_MINOR) + unset(SDL_GFX_VERSION_PATCH) +endif() + +set(SDL_GFX_LIBRARIES ${SDL_GFX_LIBRARY}) +set(SDL_GFX_INCLUDE_DIRS ${SDL_GFX_INCLUDE_DIR}) + +include("FindPackageHandleStandardArgs") + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_gfx + REQUIRED_VARS SDL_GFX_LIBRARIES SDL_GFX_INCLUDE_DIRS + VERSION_VAR SDL_GFX_VERSION_STRING) + +# for backward compatiblity +set(SDLGFX_LIBRARY ${SDL_GFX_LIBRARIES}) +set(SDLGFX_INCLUDE_DIR ${SDL_GFX_INCLUDE_DIRS}) +set(SDLGFX_FOUND ${SDL_GFX_FOUND}) + +mark_as_advanced(SDL_GFX_LIBRARY SDL_GFX_INCLUDE_DIR) diff --git a/cmake/Findlog4cpp.cmake b/cmake/Findlog4cpp.cmake new file mode 100644 index 00000000..c96b1c78 --- /dev/null +++ b/cmake/Findlog4cpp.cmake @@ -0,0 +1,7 @@ +FIND_PATH(LOG4CPP_INCLUDE_DIRS log4cpp/FileAppender.hh) +FIND_LIBRARY(LOG4CPP_LIBRARY NAMES liblog4cpp.so) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LOG4CPP DEFAULT_MSG LOG4CPP_LIBRARY LOG4CPP_INCLUDE_DIRS) + +MARK_AS_ADVANCED(LOG4CPP_INCLUDE_DIRS LOG4CPP_LIBRARY) diff --git a/cmake/Require.cmake b/cmake/Require.cmake new file mode 100644 index 00000000..466d9aaa --- /dev/null +++ b/cmake/Require.cmake @@ -0,0 +1,24 @@ +macro(find lib) + find_package(${lib} REQUIRED ${ARGN}) + string(TOUPPER ${lib} LIB) + + # ignore case (at least Boost uses mixed-case prefix) + if(DEFINED ${lib}_INCLUDE_DIRS) + set(${LIB}_INCLUDE_DIR ${${lib}_INCLUDE_DIRS}) + endif() + if(DEFINED ${lib}_LIBRARIES) + set(${LIB}_LIBRARY ${${lib}_LIBRARIES}) + endif() + + include_directories(${${LIB}_INCLUDE_DIRS}) +endmacro() + +macro(require lib) + find(${ARGV}) + set(LIBS ${LIBS} ${${LIB}_LIBRARY}) +endmacro() + +macro(require_test lib) + find(${ARGV}) + set(TEST_LIBS ${TEST_LIBS} ${${LIB}_LIBRARY}) +endmacro() diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 57b9df50..00000000 --- a/test/Makefile +++ /dev/null @@ -1,78 +0,0 @@ -TARGET:=usdx-tests -include ../Makefile.inc - -headers+=$(wildcard *.hpp) $(wildcard */*.hpp) $(wildcard */*/*.hpp) -sources+=$(wildcard *.cpp) $(wildcard */*.cpp) $(wildcard */*/*.cpp) - -LDFLAGS+=-lcppunit -CXXFLAGS-COVERAGE:=-fprofile-arcs -ftest-coverage -LDFLAGS-COVERAGE:=-coverage -TARGET-COVERAGE:=$(TARGET)-coverage -COVERAGE-DIR:=$(TOP)coverage - -objects-coverage:=$(patsubst %,$(COVERAGE-DIR)/obj/test/%,$(sources:.cpp=.o)) -coverage:=$(COVERAGE-DIR)/coverage.info.tmp $(COVERAGE-DIR)/coverage.info \ - $(objects-coverage:.o=.gcda) $(objects-coverage:.o=.gcno) \ - $(COVERAGE-DIR)/obj/ - -# include the apropriate dir from main src tree -SRC_INC=$(addprefix -I$(TOP)src/,$(filter-out ..%,$(dir $<))) - -############################################################################## - -.PHONY: all clean run - -all: $(TARGET) - -clean: - -$(RM) -r $(TARGET) $(TARGET-COVERAGE) $(objects) $(deps) $(coverage) - -run: $(TARGET) - ./$(TARGET) - -ifneq ($(MAKECMDGOALS),clean) --include $(deps) -endif - -############################################################################## -# normal build - -$(TARGET): $(objects) $(deps) - $(CXX) $(LDFLAGS) -o $(TARGET) $(objects) - -%.o: %.cpp - $(CXX) $(CXXFLAGS) $(SRC_INC) -MMD -c $< -o $@ - -%.d: %.cpp - $(CXX) $(CXXFLAGS) $(SRC_INC) -MM -c $< -MF $@ - -############################################################################## -# build and execute tests with code coverage and build nice html pages - -test-with-coverage: $(COVERAGE-DIR)/html/index.html - @test ! -e .error - -$(COVERAGE-DIR)/html/index.html: $(COVERAGE-DIR)/coverage.info - genhtml $(COVERAGE-DIR)/coverage.info -o $(COVERAGE-DIR)/html/ -p \ - "$(realpath ./$(TOP)/src)" - -$(COVERAGE-DIR)/coverage.info: $(COVERAGE-DIR)/coverage.info.tmp - lcov --extract $(COVERAGE-DIR)/coverage.info.tmp \ - "$(realpath ./$(TOP))/src/*" \ - -o $(COVERAGE-DIR)/coverage.info - -$(COVERAGE-DIR)/coverage.info.tmp: $(TARGET-COVERAGE) - -$(RM) .error - lcov --directory $(TOP) --zerocounters - ./$(TARGET-COVERAGE) || touch .error - lcov --directory $(TOP) --capture \ - --output-file $(COVERAGE-DIR)/coverage.info.tmp -b . - -$(TARGET-COVERAGE): $(objects-coverage) $(deps) - $(CXX) $(LDFLAGS) $(LDFLAGS-COVERAGE) -o $(TARGET-COVERAGE) \ - $(objects-coverage) - -$(COVERAGE-DIR)/obj/test/%.o: %.cpp - @[ -d $(dir $@) ] || mkdir -p $(dir $@) - $(CXX) $(CXXFLAGS) $(CXXFLAGS-COVERAGE) $(SRC_INC) -MMD -c $< -o $@ - |