Skip to content

Commit 0bb33e6

Browse files
committed
Merge pull request #3 from torbjoernk/feature/cmake
first draft of cmake build scripts
2 parents d3ff713 + 29a101a commit 0bb33e6

File tree

7 files changed

+228
-1
lines changed

7 files changed

+228
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# other stuff
2-
doc/build
2+
/doc/build
3+
/build*
34

45
# Created by http://www.gitignore.io
56

.travis.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
language:
2+
- cpp
3+
4+
compiler:
5+
- gcc
6+
- clang
7+
8+
env:
9+
- CMAKE_BUILD_TYPE="Release"
10+
- CMAKE_BUILD_TYPE="Debug"
11+
12+
before_install:
13+
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test --yes # libstdc++-4.8
14+
- if [ "${CXX}" == "clang++" ]; then sudo add-apt-repository --yes ppa:h-rayflood/llvm; fi # clang++-3.2
15+
- sudo apt-get update
16+
17+
install:
18+
- if [ "${CXX}" == "clang++" ]; then sudo apt-get -qq install clang-3.2; fi
19+
- sudo apt-get install g++-4.8; # clang need it for libstdc++ update
20+
21+
before_script:
22+
# update compilers
23+
- if [ "${CXX}" == "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi
24+
- if [ "${CXX}" == "clang++" ]; then export CXX="clang++-3.2" CC="clang-3.2"; fi
25+
26+
script:
27+
- mkdir build
28+
- cd build
29+
- cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -Dpfasst_DISABLE_LIBCXX=ON -Dpfasst_BUILD_TESTS=ON ..
30+
- make
31+
- make test
32+

3rdparty/CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Managing 3rd-party libraries and tools
2+
set(3rdparty_INCLUDES ${3rdparty_INCLUDES})
3+
set(3rdparty_DEPENDEND_LIBS ${3rdparty_DEPENDEND_LIBS})
4+
5+
if(pfasst_BUILD_TESTS)
6+
message(STATUS "3rd party: Google Testing Framework (gtest & gmock)")
7+
message(STATUS "--------------------------------------------------------------------------------")
8+
9+
# Add gmock
10+
ExternalProject_Add(
11+
googlemock
12+
SVN_REPOSITORY http://googlemock.googlecode.com/svn/trunk/
13+
SVN_REVISION -r 449 # release 1.7.0
14+
TIMEOUT 10
15+
# Disable SVN update
16+
UPDATE_COMMAND ""
17+
PATCH_COMMAND ""
18+
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
19+
-Dgtest_force_shared_crt=ON
20+
-DCMAKE_VERBOSE_MAKEFILE=ON
21+
-Dgmock_build_tests=${gtest_BUILD_TESTS}
22+
# Disable install step
23+
INSTALL_COMMAND ""
24+
# Wrap download, configure and build steps in a script to log output
25+
LOG_DOWNLOAD ON
26+
LOG_CONFIGURE ON
27+
LOG_BUILD ON
28+
)
29+
30+
# Specify include dir
31+
ExternalProject_Get_Property(googlemock source_dir)
32+
list(APPEND 3rdparty_INCLUDES ${source_dir}/include ${source_dir}/gtest/include)
33+
34+
ExternalProject_Get_Property(googlemock binary_dir)
35+
set(Suffix ".a")
36+
set(Pthread "-pthread")
37+
38+
list(APPEND 3rdparty_DEPENDEND_LIBS ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gmock${Suffix})
39+
list(APPEND 3rdparty_DEPENDEND_LIBS ${Pthread})
40+
41+
message(STATUS "--------------------------------------------------------------------------------")
42+
endif()
43+
44+
# propagate include lists to parent directory
45+
set(3rdparty_DEPENDEND_LIBS ${3rdparty_DEPENDEND_LIBS} PARENT_SCOPE)
46+
set(3rdparty_INCLUDES ${3rdparty_INCLUDES} PARENT_SCOPE)

CMakeLists.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
3+
set(CMAKE_VERBOSE_MAKEFILE ON)
4+
5+
project(pfasst)
6+
7+
include(cmake/utility_functions.cmake)
8+
include(CheckCXXCompilerFlag)
9+
include(ExternalProject)
10+
# Set default ExternalProject root directory
11+
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/3rdparty)
12+
13+
option(pfasst_DISABLE_LIBCXX "Disable use of LLVM's libstdc++ when compiling with Clang." ON)
14+
option(pfasst_BUILD_TESTS "Build test suite for PFASST." ON)
15+
16+
# check for C++11 support
17+
message(STATUS "Testing Compiler for C++11 Support ...")
18+
if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
19+
check_cxx_compiler_flag(-std=c++11 HAVE_STD11)
20+
if(HAVE_STD11)
21+
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-std=c++11")
22+
else()
23+
message(FATAL_ERROR "No advanced standard C++ support of your GCC (-std=c++11 not defined).")
24+
endif()
25+
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
26+
check_cxx_compiler_flag(-std=c++11 HAVE_STD11)
27+
if(HAVE_STD11)
28+
if(pfasst_DISABLE_LIBCXX)
29+
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-std=c++11")
30+
add_to_string_list("${CMAKE_CXX_LINK_FLAGS}" CMAKE_CXX_LINK_FLAGS "-std=c++11")
31+
else()
32+
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-std=c++11" "-stdlib=libc++")
33+
add_to_string_list("${CMAKE_CXX_LINK_FLAGS}" CMAKE_CXX_LINK_FLAGS "-std=c++11" "-stdlib=libc++")
34+
endif()
35+
else()
36+
message(FATAL_ERROR "No C++11 support for Clang version. Please upgrade Clang to a version supporting C++11.")
37+
endif()
38+
else()
39+
message(FATAL_ERROR "Don't know how to check C++11 compatibility with compiler '${CMAKE_CXX_COMPILER_ID}'")
40+
endif()
41+
message(STATUS "Your compiler has C++11 support. Hurray!")
42+
43+
# enable all compiler warnings
44+
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-Wall")
45+
46+
set(3rdparty_INCLUDES)
47+
set(3rdparty_DEPENDEND_LIBS)
48+
set(pfasst_INCLUDES)
49+
set(pfasst_DEPENDEND_LIBS)
50+
51+
if(pfasst_BUILD_TESTS)
52+
enable_testing()
53+
endif(pfasst_BUILD_TESTS)
54+
55+
# adding / including 3rd-party libraries
56+
message(STATUS "********************************************************************************")
57+
message(STATUS "Configuring 3rd party libraries")
58+
add_subdirectory(3rdparty)
59+
60+
message(STATUS "********************************************************************************")
61+
message(STATUS "Configuring sources")
62+
add_subdirectory(src)
63+
64+
if(pfasst_BUILD_TESTS)
65+
message(STATUS "********************************************************************************")
66+
message(STATUS "Configuring tests")
67+
add_subdirectory(tests)
68+
endif()
69+
message(STATUS "********************************************************************************")
70+
71+
message(STATUS "C++ Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
72+
message(STATUS "C++ Flags: ${CMAKE_CXX_FLAGS}")
73+
message(STATUS "C++ link flags: ${CMAKE_CXX_LINK_FLAGS}")
74+
75+
set(CMAKE_VERBOSE_MAKEFILE ON)

cmake/utility_functions.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function(add_to_string_list in_string out_string)
2+
# message(STATUS "Adding '${ARGN}' to '${in_string}'")
3+
foreach(element ${ARGN})
4+
# message(STATUS " processing: '${element}'")
5+
if(NOT "${element}" STREQUAL "")
6+
# escape regex commands in new element
7+
string(REPLACE "\\" "\\\\" elem_escaped "${element}")
8+
string(REGEX REPLACE "([][.?*+|()$^-])" "\\\\\\1" elem_escaped "${elem_escaped}")
9+
10+
# only append if not already in string
11+
if("${in_string}" MATCHES "${elem_escaped}")
12+
# message(STATUS " '${element}' found as '${elem_escaped}'")
13+
else()
14+
set(in_string "${in_string} ${element}")
15+
# message(STATUS " '${element}' appended")
16+
endif()
17+
endif()
18+
endforeach(element)
19+
# message(STATUS "Full string is now: '${in_string}'")
20+
set(${out_string} ${in_string} PARENT_SCOPE)
21+
endfunction(add_to_string_list)

src/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# add this source directory to PFASST's includes so headers are found here
2+
list(APPEND pfasst_INCLUDES
3+
${CMAKE_CURRENT_SOURCE_DIR}
4+
)
5+
6+
# enable debug build if required
7+
if(${CMAKE_BUILD_TYPE} MATCHES Debug OR pfasst_DEBUG)
8+
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-Wall")
9+
add_definitions(-DPFASST_DEBUG)
10+
endif()
11+
12+
## set the sources for PFASST
13+
## (uncomment the following lines if PFASST becomes not a header-only library one day)
14+
# set(pfasst_SOURCES
15+
# )
16+
17+
# include_directories(
18+
# ${3rdparty_INCLUDES}
19+
# ${pfasst_INCLUDES}
20+
# )
21+
# message("3rdparty_INCLUDES: ${3rdparty_INCLUDES}")
22+
#
23+
# add_library(pfasst ${pfasst_SOURCES})
24+
# target_link_libraries(pfasst
25+
# ${3rdparty_DEPENDEND_LIBS}
26+
# ${pfasst_DEPENDED_LIBS}
27+
# )
28+
29+
set(pfasst_INCLUDES ${pfasst_INCLUDES} PARENT_SCOPE)
30+
set(pfasst_DEPENDED_LIBS ${pfasst_DEPENDED_LIBS} PARENT_SCOPE)

tests/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Building and Running Tests
2+
include_directories(
3+
${3rdparty_INCLUDES}
4+
${pfasst_INCLUDES}
5+
)
6+
7+
set(TESTS
8+
test-quadrature
9+
)
10+
11+
foreach(test ${TESTS})
12+
add_executable(${test} ${test}.cpp)
13+
add_dependencies(${test} googlemock)
14+
target_link_libraries(${test}
15+
${3rdparty_DEPENDEND_LIBS}
16+
${pfasst_DEPENDED_LIBS}
17+
)
18+
set_target_properties(${test} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${pfasst_BINARY_DIR}/tests)
19+
add_test(NAME ${test}
20+
COMMAND ${CMAKE_BINARY_DIR}/tests/${test} --gtest_output=xml:${test}_out.xml
21+
)
22+
endforeach(test)

0 commit comments

Comments
 (0)