From 72c795861412c500e2a41ff4e05618c4feb4dae7 Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Wed, 20 Mar 2019 18:22:57 -0400 Subject: [PATCH 1/9] Make build reproducible on macOS & modernize CMake - Use target properties - More robust/easier/transitive usage - More robust/easier CMake config files for use with `find_package(OPENCOARRAYS)` - Make builds reproducible when: - `ZERO_AR_DATE=1` - `SOURCE_DATE_EPOCH=` - Modules not checked/verified, these may also be needed: - Source/build directory: - `/Users/ibeekman/Sandbox/OpenCoarrays{,/build}` - `LC_ALL=C` - `TZ=UTC` --- CMakeLists.txt | 18 +++++++++++++----- src/mpi/CMakeLists.txt | 18 ++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72564003e..4ddf3df12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" @@ -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}" ) @@ -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 @@ -591,8 +601,6 @@ define_property(TARGET #------------------------------- # Recurse into the src directory #------------------------------- -include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src) - add_subdirectory(src) #----------------------------------------------------- diff --git a/src/mpi/CMakeLists.txt b/src/mpi/CMakeLists.txt index 014547681..3d09a0be4 100644 --- a/src/mpi/CMakeLists.txt +++ b/src/mpi/CMakeLists.txt @@ -26,8 +26,10 @@ 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 $<$:${MPI_Fortran_INCLUDE_PATH}>) +target_include_directories(opencoarrays_mod PUBLIC + $<$:${MPI_Fortran_INCLUDE_PATH}> + $ + $) 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) @@ -42,10 +44,14 @@ target_link_libraries(caf_mpi_static set_target_properties(caf_mpi_static PROPERTIES POSITION_INDEPENDENT_CODE TRUE) -target_include_directories(caf_mpi - PUBLIC $<$:${MPI_C_INCLUDE_PATH}>) -target_include_directories(caf_mpi_static - PUBLIC $<$:${MPI_C_INCLUDE_PATH}>) +target_include_directories(caf_mpi PUBLIC + $<$:${MPI_C_INCLUDE_PATH}> + $ + $) +target_include_directories(caf_mpi_static PUBLIC + $<$:${MPI_C_INCLUDE_PATH}> + $ + $) target_compile_options(caf_mpi PUBLIC $<$:${MPI_C_COMPILE_FLAGS}>) target_compile_options(caf_mpi_static From 202fd9a792edce337438ae5b6e14a0d8cb57db7d Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Thu, 21 Mar 2019 11:57:05 -0400 Subject: [PATCH 2/9] Add hashing script and sha256 output to uninstall --- cmake/hash-installed.cmake.in | 18 ++++++++++++++++++ cmake/uninstall.cmake.in | 8 ++++++++ 2 files changed, 26 insertions(+) create mode 100644 cmake/hash-installed.cmake.in diff --git a/cmake/hash-installed.cmake.in b/cmake/hash-installed.cmake.in new file mode 100644 index 000000000..74313ea56 --- /dev/null +++ b/cmake/hash-installed.cmake.in @@ -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}") diff --git a/cmake/uninstall.cmake.in b/cmake/uninstall.cmake.in index dd3959305..daeccc8d0 100644 --- a/cmake/uninstall.cmake.in +++ b/cmake/uninstall.cmake.in @@ -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}") From 994fd166210ef5923593cb62c5338d4a1b60bbe5 Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Thu, 21 Mar 2019 11:57:57 -0400 Subject: [PATCH 3/9] Ensure all header files get installed --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0947c6f9c..0cee444fc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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}" ) From db36c5d4f1c2a67eae826c8b03ecc8b6d880c63a Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Thu, 21 Mar 2019 12:00:04 -0400 Subject: [PATCH 4/9] Add custome target for hashing installed files - Install the manifest including hashes too, if present --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ddf3df12..c38a44f89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -647,6 +647,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 #--------------------------------------------------------------------------------------- @@ -924,3 +932,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) From 9daefda1ddd4a40cbea6fcc0798d1e98bf940d19 Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Thu, 21 Mar 2019 12:01:10 -0400 Subject: [PATCH 5/9] Fix flags & logic pertaining to installed targets - `find_package(opencoarrays)` works now - libs and flags are mostly correctly passed - Still need to eliminate `add_definitions()` in top level CMakeLists.txt - Need to abstract/modularize CMake & reduce complexity --- CMakeLists.txt | 6 +----- src/mpi/CMakeLists.txt | 31 +++++++++++++------------------ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c38a44f89..386f902a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,7 +222,7 @@ endif() if(gfortran_compiler) set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS $<$:"-fcoarray=single -ffree-form">) + set(CMAKE_REQUIRED_FLAGS $<$:-fcoarray=single -ffree-form>) endif() include(CheckFortranSourceCompiles) CHECK_Fortran_SOURCE_COMPILES(" @@ -629,10 +629,6 @@ install( "${CMAKE_INSTALL_LIBDIR}/cmake/opencoarrays" ) -add_library(OpenCoarrays INTERFACE) -target_compile_options(OpenCoarrays INTERFACE $<$:"-fcoarray=lib") -target_link_libraries(OpenCoarrays INTERFACE caf_mpi) - #------------------------------------------ # Add portable unistall command to makefile #------------------------------------------ diff --git a/src/mpi/CMakeLists.txt b/src/mpi/CMakeLists.txt index 3d09a0be4..9867db07a 100644 --- a/src/mpi/CMakeLists.txt +++ b/src/mpi/CMakeLists.txt @@ -26,6 +26,8 @@ target_compile_options(opencoarrays_mod target_link_libraries(opencoarrays_mod PUBLIC ${MPI_Fortran_LINK_FLAGS} PUBLIC ${MPI_Fortran_LIBRARIES}) +target_link_libraries(opencoarrays_mod + PUBLIC caf_mpi_static) target_include_directories(opencoarrays_mod PUBLIC $<$:${MPI_Fortran_INCLUDE_PATH}> $ @@ -35,12 +37,10 @@ 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) @@ -83,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 @@ -92,22 +92,15 @@ set_target_properties( caf_mpi_static ) if (gfortran_compiler) - target_compile_options(caf_mpi INTERFACE $<$:"-fcoarray=lib">) - target_compile_options(caf_mpi_static INTERFACE $<$:"-fcoarray=lib">) + target_compile_options(caf_mpi INTERFACE $<$:-fcoarray=lib>) + target_compile_options(caf_mpi_static INTERFACE $<$:-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 @@ -134,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) From 5ba66ed7b42dc4db4c8bb5dc3f031ae0a52c7fb0 Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Thu, 21 Mar 2019 12:15:09 -0400 Subject: [PATCH 6/9] Update TravisCI to use reproducible settings --- .travis.yml | 5 +++++ developer-scripts/travis/test-script.cmake.sh | 2 ++ 2 files changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index dee531531..d3d2445e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,9 @@ os: osx env: global: + - ZERO_AR_DATE=1 + - TZ=UTC + - LC_ALL=C - CACHE="${HOME}/.local" - MPICH_VER="3.2.1" - MPICH_URL_HEAD="https://www.mpich.org/static/downloads/${MPICH_VER}" @@ -102,6 +105,8 @@ install: script: - pwd + - export SOURCE_DATE_EPOCH=$(git show -s --format=%ct $TRAVIS_COMMIT) + - echo "SOURCE_DATE_EPOCH = ${COURCE_DATE_EPOCH}" - ./developer-scripts/travis/test-script.${BUILD_TYPE:-cmake}.sh after_script: diff --git a/developer-scripts/travis/test-script.cmake.sh b/developer-scripts/travis/test-script.cmake.sh index baa278472..24838a8ee 100755 --- a/developer-scripts/travis/test-script.cmake.sh +++ b/developer-scripts/travis/test-script.cmake.sh @@ -68,6 +68,8 @@ for version in ${GCC}; do ctest "${CTEST_FLAGS[@]}" fi make install + make hash_installed + make install make uninstall ) done From aca137fb3dfa5b43de732415607144df7cb87955 Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Thu, 21 Mar 2019 12:35:26 -0400 Subject: [PATCH 7/9] Don't override LC_ALL on travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d3d2445e2..d15bdd303 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ env: global: - ZERO_AR_DATE=1 - TZ=UTC - - LC_ALL=C - CACHE="${HOME}/.local" - MPICH_VER="3.2.1" - MPICH_URL_HEAD="https://www.mpich.org/static/downloads/${MPICH_VER}" From f3a4d6987153077a8d533565ce8d87fc5a80b04e Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Thu, 21 Mar 2019 12:50:21 -0400 Subject: [PATCH 8/9] Fix typo and unset ZERO_AR_DATE in .travis.yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d15bdd303..3ca50475d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ os: osx env: global: - - ZERO_AR_DATE=1 +# - ZERO_AR_DATE=1 - TZ=UTC - CACHE="${HOME}/.local" - MPICH_VER="3.2.1" @@ -105,7 +105,7 @@ install: script: - pwd - export SOURCE_DATE_EPOCH=$(git show -s --format=%ct $TRAVIS_COMMIT) - - echo "SOURCE_DATE_EPOCH = ${COURCE_DATE_EPOCH}" + - echo "SOURCE_DATE_EPOCH = ${SOURCE_DATE_EPOCH}" - ./developer-scripts/travis/test-script.${BUILD_TYPE:-cmake}.sh after_script: From 5ee4cad8e8c5218935e3e668bc40dde6d74304b0 Mon Sep 17 00:00:00 2001 From: Izaak Beekman Date: Thu, 21 Mar 2019 14:02:39 -0400 Subject: [PATCH 9/9] Fix paralle build bug --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 386f902a6..ead31b23e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -537,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