Skip to content

Commit 8202f18

Browse files
committed
Normalize installation structure to match GNU
Fixes #79 - Use the CMake GNUInstallDirs module to help locate where to put stuff - Install library header files too - Put module into include, but also namespace it with compiler ID and version Directory structure looks like this: ``` /usr/local/Cellar/OpenCoarrays/1.8.3 ├── bin │   ├── caf │   └── cafrun ├── include │   ├── OpenCoarrays │   │   └── GNU │   │   └── 6.3.0 │   │   └── opencoarrays.mod │   ├── libcaf-gfortran-descriptor.h │   ├── libcaf.h │   └── opencoarrays.mod -> /usr/local/Cellar/OpenCoarrays/1.8.3/include/OpenCoarrays/GNU/6.3.0/opencoarrays.mod └── lib ├── cmake │   └── opencoarrays │   ├── OpenCoarraysConfig.cmake │   ├── OpenCoarraysConfigVersion.cmake │   ├── OpenCoarraysTargets-release.cmake │   └── OpenCoarraysTargets.cmake └── libcaf_mpi.a 8 directories, 11 files ```
1 parent 6709118 commit 8202f18

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ set(CMAKE_Fortran_COMPILE_FLAGS ${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COM
290290
set(CMAKE_Fortran_LINK_FLAGS ${CMAKE_Fortran_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
291291
include_directories(BEFORE ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH})
292292

293+
#---------------------------------------------------
294+
# Use standardized GNU install directory conventions
295+
#---------------------------------------------------
296+
include(GNUInstallDirs)
297+
293298
#-------------------------------
294299
# Recurse into the src directory
295300
#-------------------------------
@@ -304,7 +309,7 @@ install(EXPORT OpenCoarraysTargets
304309
NAMESPACE
305310
OpenCoarrays::
306311
DESTINATION
307-
lib/cmake/opencoarrays
312+
"${CMAKE_INSTALL_LIBDIR}/cmake/opencoarrays"
308313
)
309314
include(CMakePackageConfigHelpers) # standard CMake module
310315
write_basic_package_version_file(
@@ -320,15 +325,13 @@ install(
320325
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/OpenCoarraysConfig.cmake"
321326
"${CMAKE_CURRENT_BINARY_DIR}/OpenCoarraysConfigVersion.cmake"
322327
DESTINATION
323-
lib/cmake/opencoarrays
328+
"${CMAKE_INSTALL_LIBDIR}/cmake/opencoarrays"
324329
)
325330

326331
add_library(OpenCoarrays INTERFACE)
327332
target_compile_options(OpenCoarrays INTERFACE -fcoarray=lib)
328333
target_link_libraries(OpenCoarrays INTERFACE caf_mpi)
329334

330-
install(DIRECTORY ${CMAKE_BINARY_DIR}/mod DESTINATION .)
331-
332335
#------------------------------------------
333336
# Add portable unistall command to makefile
334337
#------------------------------------------

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ set(directories_to_build mpi tests)
22
foreach(directory ${directories_to_build})
33
add_subdirectory(${directory})
44
endforeach()
5+
6+
install( FILES libcaf.h libcaf-gfortran-descriptor.h
7+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
8+
)

src/mpi/CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,22 @@ endif()
5353
include_directories(${CMAKE_BINARY_DIR}/mod)
5454

5555
install(TARGETS caf_mpi EXPORT OpenCoarraysTargets
56-
ARCHIVE DESTINATION lib
57-
LIBRARY DESTINATION lib
56+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
57+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
5858
)
59-
install(DIRECTORY ${CMAKE_BINARY_DIR}/mod DESTINATION .)
59+
60+
# Install modules to standard include dir, but namespace them with compiler/version
61+
set (mod_install "${CMAKE_INSTALL_FULL_INCLUDEDIR}/OpenCoarrays/${CMAKE_Fortran_COMPILER_ID}/${CMAKE_Fortran_COMPILER_VERSION}")
62+
install(DIRECTORY "${CMAKE_BINARY_DIR}/mod/"
63+
DESTINATION "${mod_install}"
64+
FILES_MATCHING PATTERN "*.mod"
65+
)
66+
67+
# Now add a link in standard include dir so that compilers will find by default... this may or may not actually be a good idea...
68+
if ( "${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU" )
69+
INSTALL(CODE "execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink ${mod_install}/opencoarrays.mod ${CMAKE_INSTALL_FULL_INCLUDEDIR}/opencoarrays.mod )"
70+
)
71+
endif ()
6072

6173
# Now we write the script that passes CAF source to the compiler with the necessary arguments
6274
# and, if necessary, performs some code transformations prior to invoking the compiler.
@@ -65,12 +77,12 @@ set(compiler_wrapper ${exe_dir}/caf)
6577
install(
6678
FILES "${compiler_wrapper}"
6779
PERMISSIONS WORLD_EXECUTE WORLD_READ WORLD_WRITE OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_EXECUTE GROUP_READ GROUP_WRITE
68-
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/
80+
DESTINATION "${CMAKE_INSTALL_BINDIR}"
6981
)
7082
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../extensions/caf-head CAF_HEADER)
7183
file(WRITE "${compiler_wrapper}" "${CAF_HEADER}\n")
72-
file(APPEND "${compiler_wrapper}" "caf_mod_dir=${CMAKE_INSTALL_PREFIX}/mod\n")
73-
file(APPEND "${compiler_wrapper}" "caf_lib_dir=${CMAKE_INSTALL_PREFIX}/lib\n")
84+
file(APPEND "${compiler_wrapper}" "caf_mod_dir=\"${CMAKE_INSTALL_INCLUDEDIR}/mod\"\n")
85+
file(APPEND "${compiler_wrapper}" "caf_lib_dir=\"${CMAKE_INSTALL_LIBDIR}\"\n")
7486
file(APPEND "${compiler_wrapper}" "caf_version=${PROJECT_VERSION}\n")
7587
if(gfortran_compiler)
7688
file(APPEND "${compiler_wrapper}" "link_args='-fcoarray=lib -lcaf_mpi'\n")
@@ -98,7 +110,7 @@ set(caf_launcher ${exe_dir}/cafrun)
98110
install(
99111
FILES "${caf_launcher}"
100112
PERMISSIONS WORLD_EXECUTE WORLD_READ WORLD_WRITE OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_EXECUTE GROUP_READ GROUP_WRITE
101-
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
113+
DESTINATION "${CMAKE_INSTALL_BINDIR}"
102114
)
103115
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../extensions/cafrun-head CAFRUN_HEADER)
104116
file(WRITE "${caf_launcher}" "${CAFRUN_HEADER}\n")

src/single/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
add_library(caf_single single.c ../common/caf_auxiliary.c)
22
target_compile_options(caf_single INTERFACE -fcoarray=lib)
33
install(TARGETS caf_single EXPORT OpenCoarraysTargets
4-
ARCHIVE DESTINATION lib
4+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
55
)

0 commit comments

Comments
 (0)