Skip to content

Commit

Permalink
update cmake build settings, adding additional options
Browse files Browse the repository at this point in the history
  • Loading branch information
patflick committed Jan 5, 2019
1 parent f09a41c commit 4f19d42
Showing 1 changed file with 37 additions and 40 deletions.
77 changes: 37 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,34 @@ cmake_minimum_required(VERSION 3.6)
# project settings
project(mxx LANGUAGES CXX)

# Add these standard paths to the search paths for FIND_LIBRARY
# to find libraries from these locations first
if(UNIX)
set(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH} /lib /usr/lib")
endif()

# --------------------------------------------------------------
# Indicate CMake 2.7 and above that we don't want to mix relative
# and absolute paths in linker lib lists.
# Run "cmake --help-policy CMP0003" for more information.
# --------------------------------------------------------------
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif()

#### options
OPTION(MXX_BUILD_TESTS "Build tests" ON)
OPTION(MXX_BUILD_UTILS "Build utilities and benchmarks" OFF)
OPTION(MXX_ENABLE_COVERAGE "Enable code coverage reporting" OFF)
OPTION(MXX_TRAVIS "Travis build (turns on tests and coverage)" OFF)
OPTION(MXX_FAKE_BIG_MPI "Enable a fake, tiny bigMPI threshold (used during CI testing)" OFF)

#### add mxx as header library
add_library(mxx INTERFACE)
target_compile_features(mxx INTERFACE cxx_std_11)
target_include_directories(mxx INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
target_include_directories(mxx INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)


#### MPI
#### load MPI
find_package(MPI REQUIRED)
if (MPI_FOUND)
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MPI_COMPILE_FLAGS}")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_COMPILE_FLAGS}")
#set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} ${MPI_LINK_FLAGS}")
target_link_libraries(mxx INTERFACE ${MPI_CXX_LIBRARIES})
target_include_directories(mxx INTERFACE ${MPI_CXX_INCLUDE_PATH})
else (MPI_FOUND)
message(SEND_ERROR "This application cannot compile without MPI")
endif (MPI_FOUND)

#### cxx-prettyprint
target_include_directories(mxx INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ext> $<INSTALL_INTERFACE:include/mxx/ext>)
target_include_directories(mxx INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ext>
$<INSTALL_INTERFACE:include/mxx/ext>)

#### Installation
install(DIRECTORY include/mxx/ DESTINATION include/mxx)
Expand Down Expand Up @@ -93,41 +87,44 @@ if(DOXYGEN_FOUND)
)
endif(DOXYGEN_FOUND)

### Test Coverage
OPTION(ENABLE_COVERAGE "Enable code coverage reporting" OFF)

# on travis: debug build with coverage
OPTION(TRAVIS "Travis build" OFF)
if(TRAVIS)
#### Travis
if(MXX_TRAVIS)
# enable coverage
SET(ENABLE_COVERAGE ON CACHE BOOL "Enable code coverage reporting" FORCE)
SET(MXX_BUILD_TESTS ON CACHE BOOL "Build tests on travis" FORCE)
SET(MXX_ENABLE_COVERAGE ON CACHE BOOL "Enable code coverage reporting" FORCE)
# set debug build
SET(CMAKE_BUILD_TYPE Debug)
endif(TRAVIS)
endif(MXX_TRAVIS)

if(ENABLE_COVERAGE)
#### Test Coverage
if(MXX_ENABLE_COVERAGE)
# turn off stack protection for gcov coverage, because the stack protector shows
# up as a never taken branch, and thus turns any last statement in a function
# with a stack procetor into a partially covered statement.
#
# additionally: disable inlining for more precise coverage
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fno-stack-protector -fno-inline -fno-inline-small-functions -fno-default-inline")
endif(ENABLE_COVERAGE)
endif(MXX_ENABLE_COVERAGE)

### Fake BIG MPI for testing of BigMPI functions on travis or other small RAM
### build systems
OPTION(FAKE_BIG_MPI "Enable a fake bigMPI threshold of 1" OFF)
if (FAKE_BIG_MPI)
#### Fake BIG MPI
# for testing of BigMPI functions on travis or other small RAM build systems
if (MXX_FAKE_BIG_MPI)
add_definitions(-DMXX_MAX_INT=3)
endif(FAKE_BIG_MPI)
endif(MXX_FAKE_BIG_MPI)

###### Executable and Libraries
# Save libs and executables in the same place
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Output directory for applications" )
#set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Output directory for applications" )

# build tests
# build mxx enabled gtest module
add_subdirectory(gtest)

# build tests
if(MXX_BUILD_TESTS)
add_subdirectory(test)
if (NOT TRAVIS)
endif(MXX_BUILD_TESTS)

# build utils and benchmarks
if (MXX_BUILD_UTILS)
add_subdirectory(src)
endif (NOT TRAVIS)
endif (MXX_BUILD_UTILS)

0 comments on commit 4f19d42

Please sign in to comment.