Skip to content

Commit

Permalink
Merge branch 'cmake-modernize'
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeekman committed Mar 21, 2019
2 parents 9f21ff1 + 5ee4cad commit 0152690
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ os: osx

env:
global:
# - ZERO_AR_DATE=1
- TZ=UTC
- CACHE="${HOME}/.local"
- MPICH_VER="3.2.1"
- MPICH_URL_HEAD="https://www.mpich.org/static/downloads/${MPICH_VER}"
Expand Down Expand Up @@ -102,6 +104,8 @@ install:

script:
- pwd
- export SOURCE_DATE_EPOCH=$(git show -s --format=%ct $TRAVIS_COMMIT)
- echo "SOURCE_DATE_EPOCH = ${SOURCE_DATE_EPOCH}"
- ./developer-scripts/travis/test-script.${BUILD_TYPE:-cmake}.sh

after_script:
Expand Down
39 changes: 28 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
cmake_minimum_required(VERSION 3.10)

cmake_policy(VERSION 3.10...3.12)

cmake_policy(VERSION 3.10...3.14)

set(CMAKE_SKIP_RPATH ON
CACHE BOOL "Don't add a build-dir rpath")
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON
CACHE BOOL "Build using the install rpath")
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON
CACHE BOOL "Use relative rpaths")
# Set the type/configuration of build to perform
set ( CMAKE_CONFIGURATION_TYPES "Debug" "Release" "MinSizeRel" "RelWithDebInfo" "CodeCoverage" )
set ( CMAKE_BUILD_TYPE "Release"
Expand Down Expand Up @@ -88,6 +94,11 @@ string(REGEX REPLACE "-rc[0-9]+$"

project(opencoarrays VERSION "${OPENCOARRAYS_CMAKE_PROJECT_VERSION}" LANGUAGES C Fortran)

if(DEFINED CMAKE_BUILD_TYPE AND "${CMAKE_BUILD_TYPE}" MATCHES "[Rr][Ee][Ll]")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-working-directory")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-working-directory")
endif()

message( STATUS "Building OpenCoarrays version: ${full_git_describe}" )
set(OpenCoarrays_dist_string "OpenCoarrays-${full_git_describe}")
message( STATUS "Building for target architecture: ${CMAKE_SYSTEM_PROCESSOR}" )
Expand Down Expand Up @@ -211,7 +222,7 @@ endif()

if(gfortran_compiler)
set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS $<$<COMPILE_LANGUAGE:Fortran>:"-fcoarray=single -ffree-form">)
set(CMAKE_REQUIRED_FLAGS $<$<COMPILE_LANGUAGE:Fortran>:-fcoarray=single -ffree-form>)
endif()
include(CheckFortranSourceCompiles)
CHECK_Fortran_SOURCE_COMPILES("
Expand Down Expand Up @@ -483,7 +494,6 @@ set(CMAKE_C_COMPILE_FLAGS "${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS}")
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS}")
set(CMAKE_Fortran_COMPILE_FLAGS "${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS}")
set(CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS}")
include_directories(BEFORE ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH})

#---------------------------------------------------
# Use standardized GNU install directory conventions
Expand Down Expand Up @@ -527,8 +537,9 @@ function(caf_compile_executable target main_depend)
-o "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}"
"${CMAKE_CURRENT_SOURCE_DIR}/${main_depend}"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libopencoarrays_test_utilities.a"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libopencoarrays_mod.a"
${ARGN}
DEPENDS "${main_depend}" ${ARGN} caf_mpi_static opencoarrays_test_utilities
DEPENDS "${main_depend}" ${ARGN} caf_mpi_static opencoarrays_test_utilities opencoarrays_mod
VERBATIM
)
add_custom_target("build_${target}" ALL
Expand Down Expand Up @@ -591,8 +602,6 @@ define_property(TARGET
#-------------------------------
# Recurse into the src directory
#-------------------------------
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)

add_subdirectory(src)

#-----------------------------------------------------
Expand Down Expand Up @@ -621,10 +630,6 @@ install(
"${CMAKE_INSTALL_LIBDIR}/cmake/opencoarrays"
)

add_library(OpenCoarrays INTERFACE)
target_compile_options(OpenCoarrays INTERFACE $<$<COMPILE_LANGUAGE:Fortran>:"-fcoarray=lib")
target_link_libraries(OpenCoarrays INTERFACE caf_mpi)

#------------------------------------------
# Add portable unistall command to makefile
#------------------------------------------
Expand All @@ -639,6 +644,14 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
# See JSON-Fortran's CMakeLists.txt file to find out how to get the check target to depend
# on the test executables

#------------------------------------
# Add command to hash installed files
#------------------------------------
configure_file( "${CMAKE_SOURCE_DIR}/cmake/hash-installed.cmake.in" "${CMAKE_BINARY_DIR}/hash-installed.cmake"
@ONLY)
add_custom_target( hash_installed
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/hash-installed.cmake")

#---------------------------------------------------------------------------------------
# Define macro for adding CAF tests, and ensuring proper flags are passed to MPI runtime
#---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -916,3 +929,7 @@ foreach(SCRIPT ${TRAVIS_SCRIPTS})
lint_script("${CMAKE_SOURCE_DIR}/developer-scripts/travis" ${SCRIPT})
endif()
endforeach()

install(FILES "${CMAKE_BINARY_DIR}/sha256_install_manifest.txt"
DESTINATION "${CMAKE_INSTALL_DATADIR}/opencoarrays"
OPTIONAL)
18 changes: 18 additions & 0 deletions cmake/hash-installed.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Adapted from http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F May 1, 2014

if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")

file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
file(WRITE "@CMAKE_BINARY_DIR@/sha256_install_manifest.txt" "")
foreach(file ${files})
if(IS_SYMLINK $ENV{DESTDIR}${file})
list(APPEND symbolic_links ${file})
endif()
file(SHA256 $ENV{DESTDIR}${file} ${file}_sha256)
message(STATUS "${${file}_sha256} $ENV{DESTDIR}${file}")
file(APPEND "@CMAKE_BINARY_DIR@/sha256_install_manifest.txt" "${${file}_sha256} $ENV{DESTDIR}${file}\n")
endforeach()
message(STATUS "Symbolic links: ${symbolic_links}")
8 changes: 8 additions & 0 deletions cmake/uninstall.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")

file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
if(NOT IS_SYMLINK $ENV{DESTDIR}${file})
file(SHA256 $ENV{DESTDIR}${file} ${file}_sha256)
message(STATUS "${${file}_sha256} $ENV{DESTDIR}${file}")
else()
message(STATUS "$ENV{DESTDIR}${file} is a symbolic link.")
endif()
endforeach()
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
Expand Down
2 changes: 2 additions & 0 deletions developer-scripts/travis/test-script.cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ for version in ${GCC}; do
ctest "${CTEST_FLAGS[@]}"
fi
make install
make hash_installed
make install
make uninstall
)
done
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ if(openmpi)
set(openmpi ${openmpi} PARENT_SCOPE)
endif()

install( FILES libcaf.h libcaf-gfortran-descriptor.h
install( FILES libcaf.h libcaf-gfortran-descriptor.h libcaf-version-def.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
49 changes: 25 additions & 24 deletions src/mpi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,32 @@ target_compile_options(opencoarrays_mod
target_link_libraries(opencoarrays_mod
PUBLIC ${MPI_Fortran_LINK_FLAGS}
PUBLIC ${MPI_Fortran_LIBRARIES})
target_include_directories(opencoarrays_mod
PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${MPI_Fortran_INCLUDE_PATH}>)
target_link_libraries(opencoarrays_mod
PUBLIC caf_mpi_static)
target_include_directories(opencoarrays_mod PUBLIC
$<$<COMPILE_LANGUAGE:Fortran>:${MPI_Fortran_INCLUDE_PATH}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/${mod_dir_tail}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${mod_dir_tail}>)

add_library(caf_mpi SHARED mpi_caf.c ../common/caf_auxiliary.c)
add_library(caf_mpi_static STATIC mpi_caf.c ../common/caf_auxiliary.c)
target_link_libraries(caf_mpi
PUBLIC ${MPI_C_LINK_FLAGS}
PUBLIC ${MPI_C_LIBRARIES}
PRIVATE opencoarrays_mod)
PUBLIC ${MPI_C_LIBRARIES})
target_link_libraries(caf_mpi_static
PUBLIC ${MPI_C_LINK_FLAGS}
PUBLIC ${MPI_C_LIBRARIES}
PRIVATE opencoarrays_mod)
PUBLIC ${MPI_C_LIBRARIES})
set_target_properties(caf_mpi_static
PROPERTIES
POSITION_INDEPENDENT_CODE TRUE)
target_include_directories(caf_mpi
PUBLIC $<$<COMPILE_LANGUAGE:C>:${MPI_C_INCLUDE_PATH}>)
target_include_directories(caf_mpi_static
PUBLIC $<$<COMPILE_LANGUAGE:C>:${MPI_C_INCLUDE_PATH}>)
target_include_directories(caf_mpi PUBLIC
$<$<COMPILE_LANGUAGE:C>:${MPI_C_INCLUDE_PATH}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_include_directories(caf_mpi_static PUBLIC
$<$<COMPILE_LANGUAGE:C>:${MPI_C_INCLUDE_PATH}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_options(caf_mpi
PUBLIC $<$<COMPILE_LANGUAGE:C>:${MPI_C_COMPILE_FLAGS}>)
target_compile_options(caf_mpi_static
Expand Down Expand Up @@ -77,7 +83,7 @@ if(UNIX)
endif()

install(DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.mod")
FILES_MATCHING PATTERN "opencoarrays.mod")

set_target_properties( caf_mpi_static
PROPERTIES
Expand All @@ -86,22 +92,15 @@ set_target_properties( caf_mpi_static
)

if (gfortran_compiler)
target_compile_options(caf_mpi INTERFACE $<$<COMPILE_LANGUAGE:Fortran>:"-fcoarray=lib">)
target_compile_options(caf_mpi_static INTERFACE $<$<COMPILE_LANGUAGE:Fortran>:"-fcoarray=lib">)
target_compile_options(caf_mpi INTERFACE $<$<COMPILE_LANGUAGE:Fortran>:-fcoarray=lib>)
target_compile_options(caf_mpi_static INTERFACE $<$<COMPILE_LANGUAGE:Fortran>:-fcoarray=lib>)
endif()

install(TARGETS opencoarrays_mod EXPORT OpenCoarraysTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
install(TARGETS caf_mpi EXPORT OpenCoarraysTargets
install(TARGETS opencoarrays_mod caf_mpi caf_mpi_static EXPORT OpenCoarraysTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
install(TARGETS caf_mpi_static EXPORT OpenCoarraysTargets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
)

#----------------------------------
# Determine if we're using Open MPI
Expand All @@ -128,12 +127,14 @@ elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "PGI")
endif()

if(gfortran_compiler AND (NOT opencoarrays_aware_compiler))
target_compile_definitions(opencoarrays_mod PUBLIC -DCOMPILER_SUPPORTS_CAF_INTRINSICS)
target_compile_definitions(opencoarrays_mod
PUBLIC -DCOMPILER_SUPPORTS_CAF_INTRINSICS)
endif()

option(CAF_EXPOSE_INIT_FINALIZE "Expose caf_init and caf_finalize in opencoarrays module" FALSE)
if(CAF_EXPOSE_INIT_FINALIZE)
target_compile_definitions(opencoarrays_mod PRIVATE -DEXPOSE_INIT_FINALIZE)
target_compile_definitions(opencoarrays_mod
PRIVATE -DEXPOSE_INIT_FINALIZE)
endif()

include(CheckIncludeFile)
Expand Down

0 comments on commit 0152690

Please sign in to comment.