From a2ed3b6c0b396db577eb42a02456de94b1337611 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Tue, 4 Jan 2022 16:08:07 +0100
Subject: [PATCH] `add_subdirectory` instead of include

It was difficult to find the `CMakeLists.txt` that controlled the the
compilation of a given file from the message of a compilation error.
---
 Inst_eddies/CMakeLists.txt       | 21 +++++++++++++-
 Inst_eddies/Tests/CMakeLists.txt | 49 +++++++++++++++-----------------
 2 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/Inst_eddies/CMakeLists.txt b/Inst_eddies/CMakeLists.txt
index ca846def..25f59887 100644
--- a/Inst_eddies/CMakeLists.txt
+++ b/Inst_eddies/CMakeLists.txt
@@ -22,4 +22,23 @@ file(COPY inst_eddies_Aviso.py DESTINATION . FILE_PERMISSIONS
   OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ
   WORLD_EXECUTE)
 
-include(Tests/CMakeLists.txt)
+add_subdirectory(Tests)
+
+target_sources(test_get_1_outerm PRIVATE get_1_outerm.f90 good_contour.f90)
+
+target_sources(test_set_all_outerm PRIVATE set_all_outerm.f90
+  local_extrema.f90 get_1_outerm.f90 good_contour.f90 nearby_extr.f90
+  get_var.f90 config.f90)
+
+target_sources(test_good_contour PRIVATE good_contour.f90)
+target_sources(test_inside_4 PRIVATE inside_4.f90)
+target_sources(test_mean_speed PRIVATE mean_speed.f90)
+
+target_sources(test_max_speed_contour_ssh PRIVATE max_speed_contour_ssh.f90
+  get_var.f90)
+
+target_sources(test_nearby_extr PRIVATE nearby_extr.f90)
+target_sources(test_local_extrema PRIVATE local_extrema.f90)
+
+target_sources(test_set_max_speed PRIVATE set_max_speed.f90 good_contour.f90
+  max_speed_contour_ssh.f90 mean_speed.f90 inside_4.f90 get_var.f90)
diff --git a/Inst_eddies/Tests/CMakeLists.txt b/Inst_eddies/Tests/CMakeLists.txt
index b30bc556..d17b31a4 100644
--- a/Inst_eddies/Tests/CMakeLists.txt
+++ b/Inst_eddies/Tests/CMakeLists.txt
@@ -1,9 +1,9 @@
 # test_get_1_outerm
 
-add_executable(test_get_1_outerm good_contour.f90
-  ${PROJECT_SOURCE_DIR}/Common/derived_types.f90 get_1_outerm.f90
+add_executable(test_get_1_outerm
+  ${PROJECT_SOURCE_DIR}/Common/derived_types.f90
   ${PROJECT_SOURCE_DIR}/Common/spher_polyline_area.f90
-  ${CMAKE_CURRENT_LIST_DIR}/test_get_1_outerm.f90
+  test_get_1_outerm.f90
   ${PROJECT_SOURCE_DIR}/Common/shpc_create.f90
   ${PROJECT_SOURCE_DIR}/Common/write_eddy.f90
   ${PROJECT_SOURCE_DIR}/Common/shpc_close.f90)
@@ -15,11 +15,10 @@ target_link_libraries(test_get_1_outerm Geometry::geometry
 # test_set_all_outerm
 
 add_executable(test_set_all_outerm
-  ${PROJECT_SOURCE_DIR}/Common/derived_types.f90 set_all_outerm.f90
-  local_extrema.f90 get_1_outerm.f90 good_contour.f90
-  ${PROJECT_SOURCE_DIR}/Common/spher_polyline_area.f90 nearby_extr.f90
-  get_var.f90 ${CMAKE_CURRENT_LIST_DIR}/test_set_all_outerm.f90
-  config.f90 ${PROJECT_SOURCE_DIR}/Common/shpc_create.f90
+  ${PROJECT_SOURCE_DIR}/Common/derived_types.f90
+  ${PROJECT_SOURCE_DIR}/Common/spher_polyline_area.f90
+  test_set_all_outerm.f90
+  ${PROJECT_SOURCE_DIR}/Common/shpc_create.f90
   ${PROJECT_SOURCE_DIR}/Common/write_eddy.f90
   ${PROJECT_SOURCE_DIR}/Common/shpc_close.f90)
 
@@ -30,8 +29,8 @@ target_link_libraries(test_set_all_outerm PRIVATE Geometry::geometry
 
 # test_good_contour
 
-add_executable(test_good_contour good_contour.f90
-  ${CMAKE_CURRENT_LIST_DIR}/test_good_contour.f90)
+add_executable(test_good_contour
+  test_good_contour.f90)
 
 target_link_libraries(test_good_contour PRIVATE Geometry::geometry
   NetCDF95::netcdf95 Shapelib_03::shapelib_03 Contour_531::contour_531
@@ -39,16 +38,16 @@ target_link_libraries(test_good_contour PRIVATE Geometry::geometry
 
 # test_inside_4
 
-add_executable(test_inside_4 inside_4.f90
-  ${CMAKE_CURRENT_LIST_DIR}/test_inside_4.f90)
+add_executable(test_inside_4
+  test_inside_4.f90)
 
 target_link_libraries(test_inside_4 Geometry::geometry Shapelib_03::shapelib_03
   Jumble::jumble)
 
 # test_mean_speed
 
-add_executable(test_mean_speed mean_speed.f90
-  ${CMAKE_CURRENT_LIST_DIR}/test_mean_speed.f90)
+add_executable(test_mean_speed
+  test_mean_speed.f90)
 
 target_link_libraries(test_mean_speed Numer_Rec_95::numer_rec_95
   NetCDF95::netcdf95 Shapelib_03::shapelib_03 Contour_531::contour_531
@@ -57,9 +56,8 @@ target_link_libraries(test_mean_speed Numer_Rec_95::numer_rec_95
 # test_max_speed_contour_ssh
 
 add_executable(test_max_speed_contour_ssh
-  ${PROJECT_SOURCE_DIR}/Common/derived_types.f90 max_speed_contour_ssh.f90
-  get_var.f90
-  ${CMAKE_CURRENT_LIST_DIR}/test_max_speed_contour_ssh.f90)
+  ${PROJECT_SOURCE_DIR}/Common/derived_types.f90
+  test_max_speed_contour_ssh.f90)
 
 target_link_libraries(test_max_speed_contour_ssh PRIVATE
   fortrangis::fortranGIS NetCDF95::netcdf95 Contour_531::contour_531
@@ -67,9 +65,9 @@ target_link_libraries(test_max_speed_contour_ssh PRIVATE
 
 # test_nearby_extr
 
-add_executable(test_nearby_extr nearby_extr.f90
+add_executable(test_nearby_extr
   ${PROJECT_SOURCE_DIR}/Common/derived_types.f90
-  ${CMAKE_CURRENT_LIST_DIR}/test_nearby_extr.f90
+  test_nearby_extr.f90
   ${PROJECT_SOURCE_DIR}/Common/read_snapshot.f90
   ${PROJECT_SOURCE_DIR}/Common/read_eddy.f90
   ${PROJECT_SOURCE_DIR}/Common/read_field_indices.F90
@@ -81,8 +79,8 @@ target_link_libraries(test_nearby_extr Shapelib_03::shapelib_03
 
 # test_local_extrema
 
-add_executable(test_local_extrema local_extrema.f90
-  ${CMAKE_CURRENT_LIST_DIR}/test_local_extrema.f90
+add_executable(test_local_extrema
+  test_local_extrema.f90
   ${PROJECT_SOURCE_DIR}/Tests/write_extr_map.f90)
 
 target_link_libraries(test_local_extrema NetCDF95::netcdf95
@@ -91,16 +89,15 @@ target_link_libraries(test_local_extrema NetCDF95::netcdf95
 # test_set_max_speed
 
 add_executable(test_set_max_speed
-  ${PROJECT_SOURCE_DIR}/Common/derived_types.f90 set_max_speed.f90
-  good_contour.f90 max_speed_contour_ssh.f90 mean_speed.f90
-  ${PROJECT_SOURCE_DIR}/Common/spher_polyline_area.f90 inside_4.f90
-  ${CMAKE_CURRENT_LIST_DIR}/test_set_max_speed.f90
+  ${PROJECT_SOURCE_DIR}/Common/derived_types.f90
+  ${PROJECT_SOURCE_DIR}/Common/spher_polyline_area.f90
+  test_set_max_speed.f90
   ${PROJECT_SOURCE_DIR}/Common/shpc_open.F90
   ${PROJECT_SOURCE_DIR}/Common/shpc_close.f90
   ${PROJECT_SOURCE_DIR}/Common/read_field_indices.F90
   ${PROJECT_SOURCE_DIR}/Common/read_eddy.f90
   ${PROJECT_SOURCE_DIR}/Common/shpc_create.f90
-  ${PROJECT_SOURCE_DIR}/Common/write_eddy.f90 get_var.f90)
+  ${PROJECT_SOURCE_DIR}/Common/write_eddy.f90)
 
 target_link_libraries(test_set_max_speed Geometry::geometry
   Numer_Rec_95::numer_rec_95 NetCDF95::netcdf95
-- 
GitLab