Repository: LLNL/Caliper (language: python)

Issue:
Request to add Fortran module directory to exported target include path
I think Caliper is missing the Fortran module directory in its exported target's include paths.  (or I'm overlooking it, can let me know)

The code structure looks similar to Umpire, so may be something that can be quickly adapted from:
https://github.com/LLNL/Umpire/blob/develop/src/umpire/interface/c_fortran/CMakeLists.txt
Request to have Caliper include its Adiak location in target
I'm currently building a code that uses Caliper, and my Caliper was built with Adiak enabled.

I would like the ability to do these two use cases:
1. provide an adiak target for caliper
OR
2. not provide an adiak target, and have caliper use the one it was built and installed against.

(I have some user requests for both of the above)

I think I've found an example from UMPIRE that does this that could be modelled off of (tagging @davidbeckingsale in case he has suggestions):
```
47 if (NOT TARGET camp)                                                                                                                                                                                                                                 
 48   set(UMPIRE_CAMP_DIR "/foo/bar/camp-2022.10.1-vtkaejk5syv36ypagru2gf7ekydttcsu/lib/cmake/camp")                                                                                    
 49   if(NOT camp_DIR)                                                                                                                                                                                                                                   
 50     set(camp_DIR ${UMPIRE_CAMP_DIR})                                                                                                                                                                                                                 
 51   endif()                                                                                                                                                                                                                                            
 52                                                                                                                                                                                                                                                      
 53   find_dependency(camp CONFIG NO_DEFAULT_PATH PATHS                                                                                                                                                                                                  
 54     ${camp_DIR}                                                                                                                                                                                                                                      
 55     ${camp_DIR}/lib/cmake/camp                                                                                                                                                                                                                       
 56     ${PACKAGE_PREFIX_DIR}                                                                                                                                                                                                                            
 57     ${PACKAGE_PREFIX_DIR}/lib/cmake/camp)                                                                                                                                                                                                            
 58 endif ()   
 ```

If I set up a camp target in my code, then umpire will use it.  If I don't set up a camp target myself, then umpire defaults to the one it was built with.
Request to add Fortran module directory to exported target include path
I think Caliper is missing the Fortran module directory in its exported target's include paths.  (or I'm overlooking it, can let me know)

The code structure looks similar to Umpire, so may be something that can be quickly adapted from:
https://github.com/LLNL/Umpire/blob/develop/src/umpire/interface/c_fortran/CMakeLists.txt


Discussion / hints:

Fix patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 35a75aa69..4bf1e4a9a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -114,6 +114,7 @@ if (WITH_FORTRAN)
   enable_language(Fortran)
   set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/fortran")
   set(CALIPER_Fortran_CMAKE_MSG "Yes, using ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION}")
+  set(CALIPER_HAVE_FORTRAN TRUE)
 endif()
 
 if (BUILD_TESTING)
@@ -306,8 +307,11 @@ if (WITH_ADIAK)
       list(APPEND CALIPER_EXTERNAL_LIBS ${CMAKE_DL_LIBS})
     endif()
   else()
+    set(CALIPER_HAVE_ADIAK FALSE)
     message(WARNING "Adiak support was requested but Adiak was not found")
   endif()
+else()
+  set(CALIPER_HAVE_ADIAK FALSE)
 endif()
 
 if (WITH_KOKKOS)
@@ -452,7 +456,7 @@ endif()
 if (WITH_LDMS)
   include(FindLDMS)
   if (LDMS_FOUND)
-     set(CALIPER_HAVE_LDMS TRUE)     
+     set(CALIPER_HAVE_LDMS TRUE)
      set(CALIPER_LDMS_CMAKE_MSG "Yes, using ${LDMS_LIBLDMS} ${LDMS_LIBSTREAM}")
      list(APPEND CALIPER_EXTERNAL_LIBS ${LDMS_LIBLDMS} ${LDMS_LIBSTREAM})
      message("Include Directory: ${LDMS_INCLUDE_DIRS}")
@@ -473,7 +477,19 @@ configure_file(
 include_directories(${PROJECT_BINARY_DIR}/include)
 include_directories(include)
 
-if(INSTALL_HEADERS)
+add_subdirectory(ext)
+add_subdirectory(src)
+
+add_subdirectory(examples/apps EXCLUDE_FROM_ALL)
+
+if (BUILD_TESTING)
+  add_subdirectory(test)
+endif()
+if (BUILD_DOCS)
+  add_subdirectory(doc EXCLUDE_FROM_ALL)
+endif()
+
+if (INSTALL_HEADERS)
   install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
     FILES_MATCHING PATTERN "*.h")
   install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
@@ -487,7 +503,7 @@ if(INSTALL_HEADERS)
     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/caliper
     FILES_MATCHING PATTERN "*.h")
 
-  if (WITH_FORTRAN)
+  if (CALIPER_HAVE_FORTRAN)
     install(
       DIRECTORY   ${CMAKE_Fortran_MODULE_DIRECTORY}/
       DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/caliper/fortran
@@ -495,7 +511,7 @@ if(INSTALL_HEADERS)
   endif()
 endif()
 
-if(INSTALL_CONFIG)
+if (INSTALL_CONFIG)
   # Create pkg-config .pc file
   set(PKG_CONFIG_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
   set(PKG_CONFIG_LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
@@ -506,31 +522,48 @@ if(INSTALL_CONFIG)
     ${PROJECT_SOURCE_DIR}/caliper.pc.in
     ${PROJECT_BINARY_DIR}/caliper.pc)
 
-  # Make caliper findable for cmake
-  configure_file(
-    ${PROJECT_SOURCE_DIR}/caliper-config.cmake.in
-    ${PROJECT_BINARY_DIR}/caliper-config.cmake
-    @ONLY)
+  include(CMakePackageConfigHelpers)
 
-  install(FILES ${PROJECT_BINARY_DIR}/caliper-config.cmake
-    DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/caliper)
-  install(EXPORT caliper-targets
-    DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/caliper)
+  write_basic_package_version_file(
+      "${CMAKE_CURRENT_BINARY_DIR}/caliper-config-version.cmake"
+    VERSION
+      ${LIBTOOL_INTERFACE}.${LIBTOOL_REVISION}.${LIBTOOL_AGE}
+    COMPATIBILITY
+      SameMajorVersion
+  )
 
-  install(FILES ${PROJECT_BINARY_DIR}/caliper.pc
-    DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
-endif()
+  set(caliper_INSTALL_INCLUDE_DIR "include/")
 
-add_subdirectory(ext)
-add_subdirectory(src)
+  configure_package_config_file(
+    "${CMAKE_CURRENT_SOURCE_DIR}/caliper-config.cmake.in"
+    "${CMAKE_CURRENT_BINARY_DIR}/caliper-config.cmake"
+    INSTALL_DESTINATION
+      ${CMAKE_INSTALL_DATAROOTDIR}/cmake/caliper
+    PATH_VARS
+      caliper_INSTALL_INCLUDE_DIR
+  )
 
-add_subdirectory(examples/apps EXCLUDE_FROM_ALL)
+  install(
+    FILES
+      "${CMAKE_CURRENT_BINARY_DIR}/caliper-config-version.cmake"
+      "${CMAKE_CURRENT_BINARY_DIR}/caliper-config.cmake"
+    DESTINATION
+      "${CMAKE_INSTALL_DATAROOTDIR}/cmake/caliper"
+  )
 
-if (BUILD_TESTING)
-  add_subdirectory(test)
-endif()
-if (BUILD_DOCS)
-  add_subdirectory(doc EXCLUDE_FROM_ALL)
+  install(
+    EXPORT
+      caliper-targets
+    DESTINATION
+      "${CMAKE_INSTALL_DATAROOTDIR}/cmake/caliper"
+  )
+
+  install(
+    FILES 
+      ${PROJECT_BINARY_DIR}/caliper.pc
+    DESTINATION 
+      ${CMAKE_INSTALL_LIBDIR}/pkgconfig
+  )
 endif()
 
 #
diff --git a/caliper-config.cmake.in b/caliper-config.cmake.in
index 51177c861..c3a6f9476 100644
--- a/caliper-config.cmake.in
+++ b/caliper-config.cmake.in
@@ -1,58 +1,28 @@
-# - caliper: Context Annotation Library
-#
-#=============================================================================
-# Caliper is a program instrumentation and performance measurement
-# framework. It provides data collection mechanisms and a source-code
-# annotation API for a variety of performance engineering use cases,
-# e.g., performance profiling, tracing, monitoring, and
-# auto-tuning.
-#
-#=== Usage ===================================================================
-# This file allows caliper to be automatically detected by other libraries
-# using CMake.  To build with caliper, you can do one of two things:
-#
-#   1. Set the caliper_DIR environment variable to the root of the Caliper
-#      installation.  If you loaded caliper through a dotkit, this may already
-#      be set, and caliper will be autodetected by CMake.
-#
-#   2. Configure your project with this option:
-#      -Dcaliper_DIR=<caliper install prefix>/share/
-#
-# If you have done either of these things, then CMake should automatically find
-# and include this file when you call find_package(caliper) from your
-# CMakeLists.txt file.
-#
-#=== Components ==============================================================
-# (David's TO DO)
-#
-# To link against these, just do, for example:
-#
-#   find_package(caliper REQUIRED)
-#   add_executable(foo foo.c)
-#   target_link_libraries(foo caliper)
-#
-# That's all!
-#
-if (NOT caliper_CONFIG_LOADED)
-  set(caliper_CONFIG_LOADED TRUE)
+@PACKAGE_INIT@
 
-  # Install layout
-  set(caliper_INSTALL_PREFIX @CMAKE_INSTALL_PREFIX@)
-  set(caliper_INCLUDE_DIR    @CMAKE_INSTALL_FULL_INCLUDEDIR@)
-  set(caliper_LIB_DIR        @CMAKE_INSTALL_FULL_LIBDIR@)
-  set(caliper_CMAKE_DIR      @CMAKE_INSTALL_FULL_DATADIR@/cmake/caliper)
+include(CMakeFindDependencyMacro)
 
-  # Includes needed to use caliper
-  set(caliper_INCLUDE_PATH ${caliper_INCLUDE_DIR})
-  set(caliper_LIB_PATH     ${caliper_LIB_DIR})
+include("${CMAKE_CURRENT_LIST_DIR}/caliper-targets.cmake")
 
-  include(CMakeFindDependencyMacro)
-  find_dependency(Threads)
+set_and_check(caliper_INCLUDE_DIR "@PACKAGE_caliper_INSTALL_INCLUDE_DIR@")
 
-  if (@CALIPER_HAVE_ADIAK@)
-    find_dependency(adiak)
+if (@CALIPER_HAVE_ADIAK@)
+  if (NOT TARGET adiak::adiak)
+    set(CALIPER_ADIAK_DIR @adiak_DIR@)
+    if (NOT adiak_DIR)
+      set(adiak_DIR ${CALIPER_ADIAK_DIR})
+    endif()
+    find_dependency(
+        adiak
+      CONFIG
+        NO_DEFAULT_PATH
+      PATHS
+        ${adiak_DIR}
+        ${adiak_DIR}/lib/cmake/adiak
+        ${PACKAGE_PREFIX_DIR}
+        ${PACKAGE_PREFIX_DIR}/lib/cmake/adiak
+    )
   endif()
-
-  # Library targets imported from file
-  include(${caliper_CMAKE_DIR}/caliper-targets.cmake)
 endif()
+
+check_required_components(caliper)
diff --git a/examples/apps/CMakeLists.txt b/examples/apps/CMakeLists.txt
index 4ed6dca6b..9ae6ee3f5 100644
--- a/examples/apps/CMakeLists.txt
+++ b/examples/apps/CMakeLists.txt
@@ -45,7 +45,6 @@ if (WITH_FORTRAN)
   foreach(app ${CALIPER_Fortran_EXAMPLE_APPS})
     add_executable(${app} ${app}.f)
     set_source_files_properties(${app}.f PROPERTIES Fortran_FORMAT FREE)
-    target_include_directories(${app} PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY})
     target_link_libraries(${app} caliper)
   endforeach()
 endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0a5c8642d..13f8e4c2a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -3,7 +3,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
 include(CheckCXXCompilerFlag)
 set(Wall_flag)
 check_cxx_compiler_flag("-Wall" Supports_Wall_Flag)
-if(Supports_Wall_Flag)
+if (Supports_Wall_Flag)
   set(Wall_flag "-Wall")
 endif()
 
@@ -17,7 +17,7 @@ add_subdirectory(reader)
 add_subdirectory(services)
 add_subdirectory(caliper)
 
-set(CALIPER_COMMON_OBJS
+set(CALIPER_ALL_OBJS
   $<TARGET_OBJECTS:caliper-common>
   $<TARGET_OBJECTS:caliper-interface>
   $<TARGET_OBJECTS:caliper-reader>
@@ -26,9 +26,6 @@ set(CALIPER_COMMON_OBJS
   ${CALIPER_SERVICES_LIBS}
   ${CALIPER_EXTERNAL_SOURCES})
 
-list(APPEND CALIPER_ALL_OBJS
-  ${CALIPER_COMMON_OBJS})
-
 add_library(caliper ${CALIPER_ALL_OBJS})
 
 set_target_properties(caliper PROPERTIES SOVERSION ${CALIPER_MAJOR_VERSION})
@@ -36,10 +33,13 @@ set_target_properties(caliper PROPERTIES VERSION ${CALIPER_VERSION})
 
 target_compile_features(caliper PUBLIC cxx_std_11)
 
-target_include_directories(
-  caliper
-  INTERFACE
-  "$<INSTALL_INTERFACE:include>")
+if (CALIPER_HAVE_FORTRAN)
+  target_include_directories(
+      caliper
+    PUBLIC
+      "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/caliper/fortran>"
+  )
+endif()
 
 if (CALIPER_HAVE_MPI)
   target_link_libraries(caliper PUBLIC ${MPI_CXX_LIBRARIES})
@@ -57,7 +57,15 @@ if (WITH_TOOLS)
   add_subdirectory(tools)
 endif()
 
-install(TARGETS caliper
-  EXPORT caliper-targets
-  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
-  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+install(
+  TARGETS
+    caliper
+  EXPORT
+    caliper-targets
+  ARCHIVE DESTINATION
+    ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION
+    ${CMAKE_INSTALL_LIBDIR}
+  INCLUDES DESTINATION
+    ${CMAKE_INSTALL_INCLUDEDIR}
+)
diff --git a/src/interface/c_fortran/CMakeLists.txt b/src/interface/c_fortran/CMakeLists.txt
index 9a617695c..7fa1986d5 100644
--- a/src/interface/c_fortran/CMakeLists.txt
+++ b/src/interface/c_fortran/CMakeLists.txt
@@ -7,11 +7,20 @@ set(CALIPER_INTERFACE_SOURCES
   wrapScopeAnnotation.cpp
   utilCaliper.cpp)
 
-if (WITH_FORTRAN)
+if (CALIPER_HAVE_FORTRAN)
   list(APPEND CALIPER_INTERFACE_SOURCES
     wrapfcaliper.F)
-  set_source_files_properties(wrapfcaliper.F PROPERTIES Fortran_FORMAT FREE)  
+  set_source_files_properties(wrapfcaliper.F PROPERTIES Fortran_FORMAT FREE)
 endif()
 
 add_library(caliper-interface OBJECT ${CALIPER_INTERFACE_SOURCES})
-target_compile_features(caliper-interface PUBLIC cxx_std_11)
\ No newline at end of file
+target_compile_features(caliper-interface PUBLIC cxx_std_11)
+
+if (CALIPER_HAVE_FORTRAN)
+  target_include_directories(
+    caliper-interface
+  PUBLIC
+    "$<BUILD_INTERFACE:${CMAKE_Fortran_MODULE_DIRECTORY}>"
+    "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/caliper/fortran>"
+  )
+endif()
\ No newline at end of file
diff --git a/src/tools/util/CMakeLists.txt b/src/tools/util/CMakeLists.txt
index 13d0ecfc0..2e76a4f35 100644
--- a/src/tools/util/CMakeLists.txt
+++ b/src/tools/util/CMakeLists.txt
@@ -1,5 +1,5 @@
 set(CALIPER_TOOLS_UTIL_SOURCES
-    Args.cpp)
+  Args.cpp)
 
 add_library(caliper-tools-util ${CALIPER_TOOLS_UTIL_SOURCES})
 
@@ -8,7 +8,15 @@ target_compile_features(caliper-tools-util PUBLIC cxx_std_11)
 set_target_properties(caliper-tools-util PROPERTIES SOVERSION ${CALIPER_MAJOR_VERSION})
 set_target_properties(caliper-tools-util PROPERTIES VERSION ${CALIPER_VERSION})
 
-install(TARGETS caliper-tools-util 
-  EXPORT caliper-targets
-  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
-  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+install(
+  TARGETS
+    caliper-tools-util
+  EXPORT
+    caliper-targets
+  ARCHIVE DESTINATION
+    ${CMAKE_INSTALL_LIBDIR}
+  LIBRARY DESTINATION
+    ${CMAKE_INSTALL_LIBDIR}
+  INCLUDES DESTINATION
+    ${CMAKE_INSTALL_INCLUDEDIR}
+)


Test patch:
diff --git a/test/ci_app_tests/CMakeLists.txt b/test/ci_app_tests/CMakeLists.txt
index 23d010691..5fb76461d 100644
--- a/test/ci_app_tests/CMakeLists.txt
+++ b/test/ci_app_tests/CMakeLists.txt
@@ -124,7 +124,6 @@ if (WITH_FORTRAN)
   foreach(app ${CALIPER_CI_Fortran_TEST_APPS})
     add_executable(${app} ${app}.f)
     set_source_files_properties(${app}.f PROPERTIES Fortran_FORMAT FREE)
-    target_include_directories(${app} PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY})
     target_link_libraries(${app} caliper)
   endforeach()