Commit c0b790e5 authored by chuck cranor's avatar chuck cranor

add cmake build files for margo. example usage:

 [assuming you are in src dir and want an out of tree build]
 mkdir ../build-margo
 cd ../build
 cmake -DBUILD_SHARED_LIBS=ON \
    -DCMAKE_PREFIX_PATH=/proj/testbed/data/chuck \
    -DCMAKE_INSTALL_PREFIX=/tmp/test-install \
    ../margo

BUILD_SHARED_LIBS turns on shared libs (off by default)
CMAKE_PREFIX_PATH is where to look for required packages (abt-snoozer, libev)
CMAKE_INSTALL_PREFIX is where to install abt-snoozer

 make
 ctest                  # optional: run tests
 make install
parent 32ef4531
#
# cmake for margo. requires argobots, abt-snoozer, mercury.
#
#
# to build:
# - make a build directory and "cd" to it
# - run: cmake [flags] <abt-snoozer-directory>
# - make && make test && make install
#
#
# flags:
# -DCMAKE_INSTALL_PREFIX=/usr/local -- the prefix for installing
# -DCMAKE_BUILD_TYPE=type -- type can be DEBUG, RELEASE, ...
# -DCMAKE_PREFIX_PATH=/dir -- external packages
# -DBUILD_SHARED_LIBS=OFF -- turn ON for shared libs
#
# note that CMAKE_PREFIX_PATH can be a list of directories:
# -DCMAKE_PREFIX_PATH='/dir1;/dir2;/dir3'
#
# we will look for dependencies in CMAKE_PREFIX_PATH
#
cmake_minimum_required (VERSION 3.0)
project (margo C)
# link shared lib with rpath
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release
CACHE STRING "Choose the type of build." FORCE)
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif ()
set (CMAKE_PREFIX_PATH "" CACHE
STRING "Path used to find external dependencies")
set (BUILD_SHARED_LIBS "OFF" CACHE
BOOL "Build a shared library")
find_package (mercury CONFIG)
find_package (abt-snoozer CONFIG) # will pull argobots and libev for us
# for the tests
find_program (TIMEOUT timeout HINTS ${TIMEOUT_DIR}
DOC "Timeout program for tests")
if (NOT TIMEOUT)
message (FATAL_ERROR "Cannot find GNU 'timeout' program for tests")
endif ()
find_program (MKTEMP mktemp HINTS ${MKTEMP_DIR}
DOC "Mktemp program for tests")
if (NOT MKTEMP)
message (FATAL_ERROR "Cannot find GNU 'mktemp' program for tests")
endif ()
enable_testing ()
add_subdirectory (src)
add_subdirectory (examples)
add_subdirectory (tests)
#
# CMakeLists.txt cmake file for margo examples subdirectory
#
# included from ../CMakeLists.txt
set (margo-egs client-timeout.c client.c server-hang.c server.c sleep.c)
add_library (my-rpc STATIC my-rpc.c)
target_link_libraries (my-rpc margo)
foreach (lcv ${margo-egs})
# need a exec name... use regex to extract the file basename into ${id}
string (REGEX REPLACE ".*/" "" id ${lcv})
string (REGEX REPLACE "([A-Za-z0-9_]+)\\.c+$" "\\1" id ${id})
add_executable (${id} ${lcv})
target_link_libraries (${id} my-rpc)
endforeach ()
#
# CMakeLists.txt cmake file for margo src subdirectory
#
# included from ../CMakeLists.txt
set (margo-srcs margo-timer.c margo.c)
include (CMakePackageConfigHelpers)
set (margo-pkg-loc "share/cmake/margo") # install cmake pkg files here
#
# set up library version info
#
set (MARGO_VERSION_MAJOR 0)
set (MARGO_VERSION_MINOR 1)
set (MARGO_VERSION_PATCH 0)
set (margo-vers "${MARGO_VERSION_MAJOR}.${MARGO_VERSION_MINOR}")
set (MARGO_VERSION "${margo-vers}.${MARGO_VERSION_PATCH}")
#
# create library target
#
add_library (margo ${margo-srcs})
target_include_directories (margo PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../include>
$<INSTALL_INTERFACE:include>)
target_link_libraries (margo mercury abt-snoozer)
# patch in version info
set_target_properties(margo
PROPERTIES VERSION ${MARGO_VERSION}
SOVERSION ${MARGO_VERSION_MAJOR})
#
# generate packaging
#
write_basic_package_version_file(
"margo-config-version.cmake"
VERSION ${MARGO_VERSION}
COMPATIBILITY AnyNewerVersion)
# push this off into a function so the sub vars are in a private scope
function (makepcfile)
set (prefix ${CMAKE_INSTALL_PREFIX})
set (exec_prefix "\${prefix}")
set (libdir "\${exec_prefix}/lib")
set (includedir "\${prefix}/include")
configure_file ("../maint/margo.pc.in" "margo.pc" @ONLY)
endfunction ()
makepcfile ()
#
# "make install" rules
#
install (TARGETS margo EXPORT margo-targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install (DIRECTORY ../include
DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.h")
# packaging
install (EXPORT margo-targets
DESTINATION ${margo-pkg-loc}
FILE "margo-targets.cmake")
install (FILES "margo-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/margo-config-version.cmake"
DESTINATION ${margo-pkg-loc} )
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/margo.pc"
DESTINATION "lib/pkgconfig")
#
# margo-config.cmake
#
include (CMakeFindDependencyMacro)
find_dependency (mercury)
find_dependency (abt-snoozer)
include ("${CMAKE_CURRENT_LIST_DIR}/margo-targets.cmake")
#
# CMakeLists.txt cmake file for margo tests subdirectory
#
# included from ../CMakeLists.txt
set (abts-tests basic.sh sleep.sh timeout.sh)
foreach (lcv ${abts-tests})
# need a test name... use regex to extract the file basename into ${id}
string (REGEX REPLACE ".*/" "" id ${lcv})
string (REGEX REPLACE "([A-Za-z0-9_]+)\\.c+$" "\\1" id ${id})
add_test (NAME ${id}
COMMAND env srcdir=${CMAKE_SOURCE_DIR}
TIMEOUT=${TIMEOUT}
MKTEMP=${MKTEMP}
${CMAKE_CURRENT_SOURCE_DIR}/${lcv}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
endforeach ()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment