setup: added basic cmake project structure

Added cmake build instructions for app, lib and test.
Included Qt via environment variable QT_DIR.
Included CxxTest via environment variable CXX_TEST_DIR.
Added scripts for setup, syncing master and publishing features.
Added dlls for QT on Windows.
This commit is contained in:
Eberhard Graether
2014-03-24 15:40:50 +01:00
parent e763532523
commit 4fa1e22035
34 changed files with 493 additions and 14 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/bin/sh
ABORT="\033[31mAbort:\033[00m"
SUCCESS="\033[32mSuccess:\033[00m"
INFO="\033[33mInfo:\033[00m"
BRANCH_NAME=$(git symbolic-ref -q --short HEAD)
if [ -z $BRANCH_NAME ]
then
echo $ABORT "You are not on any branch."
exit 1
fi
if [ $BRANCH_NAME == "master" ]
then
echo $ABORT "Commiting to master is prohibited."
exit 1
fi
exit 0
+4
View File
@@ -0,0 +1,4 @@
build/
lib/
bin/Debug/
bin/Release/
+115
View File
@@ -0,0 +1,115 @@
cmake_minimum_required(VERSION 2.8.9)
include(cmake/add_files.cmake)
# Variables --------------------------------------------------------------------
set(PROJECT_NAME masterproject)
set(APP_PROJECT_NAME "${PROJECT_NAME}_app")
set(LIB_PROJECT_NAME "${PROJECT_NAME}_lib")
set(TEST_PROJECT_NAME "${PROJECT_NAME}_test")
# Settings ---------------------------------------------------------------------
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
if (UNIX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE})
else ()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
endif ()
# Project ----------------------------------------------------------------------
project(${PROJECT_NAME})
# Qt ---------------------------------------------------------------------------
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the QtWidgets library
set(CMAKE_PREFIX_PATH "$ENV{QT_DIR}/")
find_package(Qt5Widgets)
# Lib --------------------------------------------------------------------------
add_subdirectory(src/lib)
add_library(${LIB_PROJECT_NAME} ${LIB_FILES})
set_target_properties( ${LIB_PROJECT_NAME}
PROPERTIES DEBUG_OUTPUT_NAME ${PROJECT_NAME}_d
RELEASE_OUTPUT_NAME ${PROJECT_NAME})
# App --------------------------------------------------------------------------
add_subdirectory(src/app)
include_directories(src/lib)
add_executable(${APP_PROJECT_NAME} ${APP_FILES})
target_link_libraries(${APP_PROJECT_NAME} ${LIB_PROJECT_NAME})
# Use the Widgets module from Qt 5.
qt5_use_modules(${APP_PROJECT_NAME} Widgets)
# CxxTest ----------------------------------------------------------------------
add_subdirectory(src/test)
set(CXXTEST_INCLUDE_DIR $ENV{CXX_TEST_DIR})
set(CXXTEST_PYTHON_TESTGEN_EXECUTABLE ${CXXTEST_INCLUDE_DIR}/bin/cxxtestgen)
set(TESTGEN_FILE ${CMAKE_CURRENT_BINARY_DIR}/temptests.cpp)
find_package(CxxTest)
if (CXXTEST_FOUND)
include_directories(${CXXTEST_INCLUDE_DIR})
endif (CXXTEST_FOUND)
find_package(PythonInterp REQUIRED)
add_executable (${TEST_PROJECT_NAME} ${TESTGEN_FILE})
target_link_libraries(${TEST_PROJECT_NAME} ${LIB_PROJECT_NAME})
if (WIN32)
add_custom_command(TARGET ${TEST_PROJECT_NAME}
PRE_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE} --runner=ParenPrinter -o ${TESTGEN_FILE} ${PROJECT_SOURCE_DIR}/src/test/*.h
COMMENT "Generating unittest code with cxxtestgen")
add_custom_command(TARGET ${TEST_PROJECT_NAME}
POST_BUILD
COMMAND $(OutDir)$(TargetName)$(TargetExt)
COMMENT "Running unittest code")
elseif (UNIX)
add_custom_command(OUTPUT ${TESTGEN_FILE}
PRE_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE} --runner=ParenPrinter -o ${TESTGEN_FILE} ${PROJECT_SOURCE_DIR}/src/test/*.h
COMMENT "Generating unittest code with cxxtestgen")
add_custom_target(gen DEPENDS ${TESTGEN_FILE})
add_dependencies(${TEST_PROJECT_NAME} gen)
endif ()
+14 -10
View File
@@ -1,14 +1,18 @@
### Masterproject ###
### Masterproject
#### Setup ####
#### Setup
##### External Software
* QT 5.2.1
* CxxTest 4.3
##### Environment Variables
* QT_DIR - ...\Qt\Qt5.2.1\5.2.1\<IDE>\
* CXX_TEST_DIR - .../cxxtest-4.3/
##### Settings
Run setup script:
$ ./script/setup.sh
Or
Define commit message template:
$ git config commit.template .git_commit_template.txt
Enable git commandline colors:
$ git config color.ui true
+29
View File
@@ -0,0 +1,29 @@
#
# Defines a list of files with a given name, prepends the relative path to the
# source dir to each file if available and passes the list to PARENT_SCOPE.
#
# Usage:
# add_files(
# NAME_OF_FILES
# file1.cpp
# file2.cpp
# ...
# )
#
macro(add_files var_name)
file (RELATIVE_PATH _relPath "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
foreach (_src ${ARGN})
if (_relPath)
list (APPEND ${var_name} "${CMAKE_SOURCE_DIR}/${_relPath}/${_src}")
else()
list (APPEND ${var_name} "${CMAKE_SOURCE_DIR}/${_src}")
endif()
endforeach()
if (_relPath)
set(${var_name} ${${var_name}} PARENT_SCOPE)
else()
set(${var_name} ${${var_name}})
endif()
endmacro()
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
SUCCESS="\033[32mSuccess:\033[00m"
# Enter masterproject directory
MY_PATH=`dirname "$0"`
cd $MY_PATH/..
# Remove folders and contents
rm -rf build
rm -rf lib
rm -rf bin/Debug
rm -rf bin/Release
echo $SUCCESS "clean complete"
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
# Determine path to script
MY_PATH=`dirname "$0"`
cd $MY_PATH/..
# Build and run target
make -C build/Debug "$1" && bin/Debug/"$1"
+100
View File
@@ -0,0 +1,100 @@
#!/bin/sh
ABORT="\033[31mAbort:\033[00m"
SUCCESS="\033[32mSuccess:\033[00m"
INFO="\033[33mInfo:\033[00m"
echo $INFO "Checking index"
# check clean index
if [[ -n $(git diff HEAD) ]]
then
echo $ABORT "You have uncommited changes."
exit 1
fi
BRANCH_NAME=$(git symbolic-ref -q --short HEAD)
PUBLISH_BRANCH_NAME=_publish_"$BRANCH_NAME"_
echo $INFO "Checking branch $BRANCH_NAME"
# check if on branch
if [ -z $BRANCH_NAME ]
then
echo $ABORT "You are not on any branch."
exit 1
fi
# check if on master
if [ $BRANCH_NAME == "master" ]
then
echo $ABORT "You are on master. Use this script only from a feature branch."
exit 1
fi
git checkout -q master
git remote update &>/dev/null
echo $INFO "Checking master"
# check if master is up to date
if [[ -n $(git diff origin/master) ]]
then
echo $ABORT "Your master is not up-to-date. Run 'sync.sh' to update your master, then run 'git rebase master' to update branch $BRANCH_NAME."
git checkout -q $BRANCH_NAME
exit 1
fi
MASTER_HEAD_COMMIT=$(git rev-parse HEAD)
BASE_COMMIT=$(git merge-base $BRANCH_NAME master)
git checkout -q $BRANCH_NAME
BRANCH_HEAD_COMMIT=$(git rev-parse HEAD)
# check if feature has commits
if [ $BRANCH_HEAD_COMMIT == $MASTER_HEAD_COMMIT ]
then
echo $ABORT "Your feature branch has no commits."
exit 1
fi
# check if feature is not behind master
if [ $BASE_COMMIT != $MASTER_HEAD_COMMIT ]
then
echo $ABORT "Your feature branch is behind master. Use 'git rebase master' to update your feature branch."
exit 1
fi
# switch to temporary branch for squashing
git checkout -q -b $PUBLISH_BRANCH_NAME
echo $INFO "Squashing commits"
git reset --soft $BASE_COMMIT
git commit
if [ $? != 0 ]
then
git checkout -q $BRANCH_NAME
git branch -q -D $PUBLISH_BRANCH_NAME
exit 1
fi
echo $INFO "Rebasing on master"
git checkout -q master
git rebase -q $PUBLISH_BRANCH_NAME
git branch -q -d $PUBLISH_BRANCH_NAME
echo $INFO "Uploading to origin master"
git push origin master
if [ $? != 0 ]
then
git reset --hard -q HEAD^
git checkout -q $BRANCH_NAME
echo $ABORT "Pushing to origin master has failed, there are new remote changes. Run 'sync.sh' to update your master, then run 'git rebase master' to update branch $BRANCH_NAME."
exit 1
fi
echo $SUCCESS "Published branch $BRANCH_NAME successfully"
exit 0
+69
View File
@@ -0,0 +1,69 @@
#!/bin/sh
ABORT="\033[31mAbort:\033[00m"
ALERT="\033[31mAlert:\033[00m"
SUCCESS="\033[32mSuccess:\033[00m"
INFO="\033[33mInfo:\033[00m"
BRANCH_NAME=$(git symbolic-ref -q --short HEAD)
# check if on branch
if [ -z $BRANCH_NAME ]
then
echo $ABORT "You are not on any branch."
exit 1
fi
# switch to master
echo $INFO "Switching to master"
git checkout -q master
if [ $? != 0 ]
then
echo $ABORT "Switching to master failed."
exit 1
fi
# check clean index
echo $INFO "Checking index"
if [[ -n $(git diff HEAD) ]]
then
echo $ABORT "You have uncommited changes on master."
git checkout -q "$BRANCH_NAME"
exit 1
fi
# fetch remote changes
echo $INFO "Fetching changes"
git fetch -q origin master
if [ $? != 0 ]
then
echo $ABORT "Fetching from origin master failed."
git checkout -q "$BRANCH_NAME"
exit 1
fi
if [[ -z $(git diff origin/master) ]]
then
echo $SUCCESS "Your master is already up-to-date."
git checkout -q "$BRANCH_NAME"
exit 0
fi
# rebase master to origin/master
git rebase -q origin/master
if [ $? != 0 ]
then
echo $ALERT "Rebasing on master caused conflicts. This should never happen. Follow the instructions above to resolve them then use 'git push origin master' to update the remote."
exit 1
fi
git checkout -q "$BRANCH_NAME"
echo $SUCCESS "Updated master"
exit 0
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
# Determine path to script
MY_PATH=`dirname "$0"`
cd $MY_PATH/..
# Build and run target
make -C build/Release "$1" && bin/Release/"$1"
+51 -4
View File
@@ -1,9 +1,56 @@
#!/bin/sh
# Define commit message template:
ABORT="\033[31mAbort:\033[00m"
SUCCESS="\033[32mSuccess:\033[00m"
INFO="\033[33mInfo:\033[00m"
# Determine current platform
PLATFORM='unknown'
if [ "$(uname)" == "Darwin" ]; then
PLATFORM='MacOS'
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
PLATFORM='Linux'
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
PLATFORM='Windows'
fi
# Enter masterproject directory
MY_PATH=`dirname "$0"`
cd $MY_PATH/..
# git settings
echo $INFO "install git settings"
git config commit.template .git_commit_template.txt
# Enable git commandline colors:
git config color.ui true
cp .git_pre_commit_hook.sh .git/hooks/pre-commit
echo "setup complete"
# Create Debug and Release folders
echo $INFO "create build folders"
mkdir -p build
mkdir -p lib
mkdir -p bin/Debug
mkdir -p bin/Release
# Copy necessary dynamic libraries to bin folder
if [ $PLATFORM == "Windows" ]; then
echo $INFO "copy dynamic libraries"
cp -u setup/dynamic_libraries/windows/Debug/* bin/Debug
cp -u setup/dynamic_libraries/windows/Release/* bin/Release
fi
# Setup both Debug and Release configuration
if [ $PLATFORM == "Linux" ] || [ $PLATFORM == "MacOS" ]; then
mkdir -p build/Debug
mkdir -p build/Release
echo $INFO "run cmake with Debug configuration"
cd build/Debug && cmake -DCMAKE_BUILD_TYPE="Debug" ../..
echo $INFO "run cmake with Release configuration"
cd ../Release && cmake -DCMAKE_BUILD_TYPE="Release" ../..
fi
echo $SUCCESS "setup complete"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4
View File
@@ -0,0 +1,4 @@
add_files(
APP_FILES
main.cpp
)
+16
View File
@@ -0,0 +1,16 @@
#include <QApplication>
#include <QTextEdit>
#include "utility.h"
int main(int argv, char **args)
{
hello();
QApplication app(argv, args);
QTextEdit textEdit;
textEdit.show();
return app.exec();
}
+5
View File
@@ -0,0 +1,5 @@
add_files(
LIB_FILES
utility.h
utility.cpp
)
+13
View File
@@ -0,0 +1,13 @@
#include "utility.h"
#include <iostream>
void hello()
{
std::cout << "hello world!" << std::endl;
}
int one()
{
return 1;
}
+3
View File
@@ -0,0 +1,3 @@
void hello();
int one();
+4
View File
@@ -0,0 +1,4 @@
add_files(
TEST_FILES
UtilityTestSuite.h
)
+12
View File
@@ -0,0 +1,12 @@
#include <cxxtest/TestSuite.h>
#include "utility.h"
class UtilityTestSuite: public CxxTest::TestSuite
{
public:
void test_one_returns_the_number_one(void)
{
TS_ASSERT_EQUALS(one(), 1);
}
};