Skip to content

Commit 508117c

Browse files
committed
first draft of cmake build scripts
available cmake variables: pfasst_BUILD_TESTS={ON,OFF} enable build of tests with automatically pulling in GoogleMock and GoogleTest (both version 1.7.0), building and linking it; no need for them to be preinstalled what it also provides: - auto-detecting C++11 compiler flags for GCC and Clang what it (yet) not provides: - handling of XL/C++ compiler
1 parent d3ff713 commit 508117c

File tree

6 files changed

+199
-1
lines changed

6 files changed

+199
-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

3rdparty/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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=ON
22+
# Disable install step
23+
INSTALL_COMMAND ""
24+
# Run tests
25+
TEST_BEFORE_INSTALL ON
26+
TEST_AFTER_INSTALL ON
27+
TEST_COMMAND make test
28+
# Wrap download, configure and build steps in a script to log output
29+
LOG_DOWNLOAD ON
30+
LOG_CONFIGURE ON
31+
LOG_BUILD ON
32+
)
33+
34+
# Specify include dir
35+
ExternalProject_Get_Property(googlemock source_dir)
36+
list(APPEND 3rdparty_INCLUDES ${source_dir}/include ${source_dir}/gtest/include)
37+
38+
ExternalProject_Get_Property(googlemock binary_dir)
39+
set(Suffix ".a")
40+
set(Pthread "-pthread")
41+
42+
list(APPEND 3rdparty_DEPENDEND_LIBS ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gmock${Suffix})
43+
list(APPEND 3rdparty_DEPENDEND_LIBS ${Pthread})
44+
45+
message(STATUS "--------------------------------------------------------------------------------")
46+
endif()
47+
48+
# propagate include lists to parent directory
49+
set(3rdparty_DEPENDEND_LIBS ${3rdparty_DEPENDEND_LIBS} PARENT_SCOPE)
50+
set(3rdparty_INCLUDES ${3rdparty_INCLUDES} PARENT_SCOPE)

CMakeLists.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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_BUILD_TESTS "Build test suite for PFASST." ON)
14+
15+
# check for C++11 support
16+
message(STATUS "Testing Compiler for C++11 Support ...")
17+
if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
18+
check_cxx_compiler_flag(-std=c++11 HAVE_STD11)
19+
if(HAVE_STD11)
20+
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-std=c++11")
21+
else()
22+
message(FATAL_ERROR "No advanced standard C++ support of your GCC (-std=c++11 not defined).")
23+
endif()
24+
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
25+
check_cxx_compiler_flag(-std=c++11 HAVE_STD11)
26+
if(HAVE_STD11)
27+
if(pfasst_DISABLE_LIBCXX)
28+
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-std=c++11")
29+
add_to_string_list("${CMAKE_CXX_LINK_FLAGS}" CMAKE_CXX_LINK_FLAGS "-std=c++11")
30+
else()
31+
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-std=c++11" "-stdlib=libc++")
32+
add_to_string_list("${CMAKE_CXX_LINK_FLAGS}" CMAKE_CXX_LINK_FLAGS "-std=c++11" "-stdlib=libc++")
33+
endif()
34+
else()
35+
message(FATAL_ERROR "No C++11 support for Clang version. Please upgrade Clang to a version supporting C++11.")
36+
endif()
37+
else()
38+
message(FATAL_ERROR "Don't know how to check C++11 compatibility with compiler '${CMAKE_CXX_COMPILER_ID}'")
39+
endif()
40+
message(STATUS "Your compiler has C++11 support. Hurray!")
41+
42+
# enable all compiler warnings
43+
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-Wall")
44+
45+
set(3rdparty_INCLUDES)
46+
set(3rdparty_DEPENDEND_LIBS)
47+
set(pfasst_INCLUDES)
48+
set(pfasst_DEPENDEND_LIBS)
49+
50+
if(pfasst_BUILD_TESTS)
51+
enable_testing()
52+
endif(pfasst_BUILD_TESTS)
53+
54+
# adding / including 3rd-party libraries
55+
message(STATUS "********************************************************************************")
56+
message(STATUS "Configuring 3rd party libraries")
57+
add_subdirectory(3rdparty)
58+
59+
message(STATUS "********************************************************************************")
60+
message(STATUS "Configuring sources")
61+
add_subdirectory(src)
62+
63+
if(pfasst_BUILD_TESTS)
64+
message(STATUS "********************************************************************************")
65+
message(STATUS "Configuring tests")
66+
add_subdirectory(tests)
67+
endif()
68+
message(STATUS "********************************************************************************")
69+
70+
message(STATUS "C++ Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
71+
message(STATUS "C++ Flags: ${CMAKE_CXX_FLAGS}")
72+
message(STATUS "C++ link flags: ${CMAKE_CXX_LINK_FLAGS}")
73+
74+
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}
21+
)
22+
endforeach(test)

0 commit comments

Comments
 (0)