Skip to content

Commit

Permalink
modernize cmake files
Browse files Browse the repository at this point in the history
  • Loading branch information
tkonolige committed Mar 23, 2018
1 parent 492ab47 commit 5f5d152
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 27 deletions.
67 changes: 53 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.6)

# project settings
project(mxx)

##### General Compilation Settings

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wuninitialized --std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native -funroll-loops")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -g")
project(mxx LANGUAGES CXX)

# Add these standard paths to the search paths for FIND_LIBRARY
# to find libraries from these locations first
Expand All @@ -25,18 +18,68 @@ if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif()

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>)


#### 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}")
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
target_link_libraries(mxx INTERFACE ${MPI_CXX_LIBRARIES})
target_include_directories(mxx INTERFACE ${MPI_CXX_INCLUDE_DIRS})
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>)

#### Installation
install(DIRECTORY include/mxx/ DESTINATION include/mxx)
install(DIRECTORY ext/ DESTINATION include/mxx FILES_MATCHING PATTERN "*.hpp")

include(CMakePackageConfigHelpers)

install(TARGETS mxx
EXPORT mxxTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

export(EXPORT mxxTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/mxx/mxxTargets.cmake"
NAMESPACE mxx::
)
set(ConfigPackageLocation lib/cmake/mxx)
configure_package_config_file(cmake/mxxConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/mxx/mxxConfig.cmake"
INSTALL_DESTINATION "${ConfigPackageLocation}"
)

install(EXPORT mxxTargets
FILE
mxxTargets.cmake
NAMESPACE
mxx::
DESTINATION
${ConfigPackageLocation}
)
install(
FILES
cmake/mxxConfig.cmake
DESTINATION
${ConfigPackageLocation}
COMPONENT
Devel
)


#### Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
Expand Down Expand Up @@ -82,10 +125,6 @@ endif(FAKE_BIG_MPI)
# Save libs and executables in the same place
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Output directory for applications" )

include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/ext")
include_directories("${PROJECT_SOURCE_DIR}")

# build tests
add_subdirectory(gtest)
add_subdirectory(test)
Expand Down
3 changes: 3 additions & 0 deletions cmake/mxxConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
find_package(MPI REQUIRED QUIET)

include("${CMAKE_CURRENT_LIST_DIR}/mxxTargets.cmake")
7 changes: 3 additions & 4 deletions gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.6)

# project settings
project(mxx-gtest)
Expand All @@ -8,7 +8,6 @@ project(mxx-gtest)
# MPI Google Test: #
######################

include_directories("${PROJECT_SOURCE_DIR}/../")

add_library(mxx-gtest-main mxx_gtest_main.cpp gtest-all.cc)
target_link_libraries(mxx-gtest-main ${MPI_LIBRARIES} pthread)
target_link_libraries(mxx-gtest-main PUBLIC mxx ${MPI_LIBRARIES} pthread)
target_include_directories(mxx-gtest-main PUBLIC "../")
10 changes: 5 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.6)

# project settings
project(mxx-bm)

add_executable(mxx-bm-vote-off vote_off.cpp)
target_link_libraries(mxx-bm-vote-off ${MPI_LIBRARIES})
target_link_libraries(mxx-bm-vote-off mxx ${MPI_LIBRARIES})

# benchmark p2p bandwidth
add_executable(mxx-benchmark-p2p-bw benchmark_p2p_bw.cpp)
target_link_libraries(mxx-benchmark-p2p-bw ${MPI_LIBRARIES})
target_link_libraries(mxx-benchmark-p2p-bw mxx ${MPI_LIBRARIES})

# benchmark all2all
add_executable(mxx-benchmark-a2a benchmark_a2a.cpp)
target_link_libraries(mxx-benchmark-a2a ${MPI_LIBRARIES})
target_link_libraries(mxx-benchmark-a2a mxx ${MPI_LIBRARIES})

# benchmark parallel sorting
add_executable(mxx-sort-benchmark benchmark_sort.cpp)
target_compile_definitions(mxx-sort-benchmark PUBLIC -DMXX_SAMPLESORT_TIMER=1)
target_link_libraries(mxx-sort-benchmark ${MPI_LIBRARIES})
target_link_libraries(mxx-sort-benchmark mxx ${MPI_LIBRARIES})
2 changes: 1 addition & 1 deletion src/benchmark_a2a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <mxx/benchmark.hpp>
#include <mxx/utils.hpp>

#include <ext/cxx-prettyprint/prettyprint.hpp>
#include <cxx-prettyprint/prettyprint.hpp>

std::string exec_name;

Expand Down
2 changes: 1 addition & 1 deletion src/benchmark_p2p_bw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <mxx/benchmark.hpp>
#include <mxx/utils.hpp>

#include <ext/cxx-prettyprint/prettyprint.hpp>
#include <cxx-prettyprint/prettyprint.hpp>

std::string exec_name;

Expand Down
2 changes: 1 addition & 1 deletion src/benchmark_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <mxx/benchmark.hpp>
#include <mxx/utils.hpp>

#include <ext/cxx-prettyprint/prettyprint.hpp>
#include <cxx-prettyprint/prettyprint.hpp>

std::string exec_name;

Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.6)

# project settings
project(mxx-test)
Expand Down

0 comments on commit 5f5d152

Please sign in to comment.