Repository: SINTEF/dlite (language: python)

Issue:
Building without Python support fails
One of the tests expects a reference which seems to be generated only with -DWITH_PYTHON=ON

```
$ mkdir out/build/noPython
$ cd out/build/noPython
$ cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE:STRING="Release" -DWITH_DOC=OFF -DWITH_HDF5=OFF -DWITH_PYTHON=OFF -DALLOW_WARNINGS=ON ../../.. 
$ cmake --build . --config Release
...
[ 74%] Linking C executable test_mapping
/usr/bin/ld: ../libdlite.so: undefined reference to `dlite_python_mapping_next'
/usr/bin/ld: ../libdlite.so: undefined reference to `dlite_python_mapping_paths_get'
collect2: error: ld returned 1 exit status
make[2]: *** [src/tests/CMakeFiles/test_mapping.dir/build.make:86: src/tests/test_mapping] Error 1
make[1]: *** [CMakeFiles/Makefile2:1994: src/tests/CMakeFiles/test_mapping.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
```

Obvious workaround

- Compile with Python support
- One (or more?) tests must be excluded when setting -DWITH_PYTHON=OFF


Discussion / hints:
Hi @pscff, I guess this issue is fixed and can be closed?
The issue is still present for the current master, the build fails already in the cmake-configure step now. How to reproduce: Set `-DWITH_PYTHON=OFF` in your build-system and try to build.

Fix patch:
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index d60e5ce0d..83fcf8a1d 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -2,9 +2,11 @@
 project(dlite-examples)
 
 # Python examples
+if(WITH_PYTHON)
 set(python_examples
   read-csv
   )
+endif()
 
 
 # CMake toolchain option
@@ -76,7 +78,8 @@ if(FORCE_EXAMPLES OR EXISTS ${CMAKE_INSTALL_PREFIX}/share/dlite/examples)
     test_example(ex4)
   endif()
   #test_example(ex5d)
-
+  if(WITH_PYTHON)
+  endif()
 
   # Run python examples
   foreach(name ${python_examples})
@@ -103,7 +106,7 @@ endif()
 
 
 install(
-  DIRECTORY ex1 ex2 ex3 ex4 ex5d
+  DIRECTORY ex1 ex2 ex3 ex4 ex5d read-csv dehydrogenation
   DESTINATION share/dlite/examples
   PATTERN "*~" EXCLUDE
   PATTERN build EXCLUDE
diff --git a/src/dlite-mapping-plugins.c b/src/dlite-mapping-plugins.c
index 1ae49836c..c7498eb16 100644
--- a/src/dlite-mapping-plugins.c
+++ b/src/dlite-mapping-plugins.c
@@ -140,7 +140,7 @@ const DLiteMappingPlugin *dlite_mapping_plugin_get(const char *name)
   if ((api = dlite_python_mapping_get_api(name))) return api;
 #endif
   /* Cannot find API */
-  int i, j, m=0;
+  int i, j=2, m=0;
   char *buf=NULL;
   size_t size=0;
   const char **paths;
@@ -150,9 +150,11 @@ const DLiteMappingPlugin *dlite_mapping_plugin_get(const char *name)
   if ((paths = dlite_mapping_plugin_paths()))
     for (i=0; paths[i]; i++)
       m += asnpprintf(&buf, &size, m, "    %s\n", paths[i]);
+#ifdef WITH_PYTHON
   if ((paths = dlite_python_mapping_paths_get()))
     for (j=0; paths[j]; j++)
       m += asnpprintf(&buf, &size, m, "    %s\n", paths[j]);
+#endif
   if (i <= 1 || j <= 1)
     m += asnpprintf(&buf, &size, m,
                     "Are the DLITE_MAPPING_PLUGIN_DIRS and "
@@ -191,11 +193,13 @@ dlite_mapping_plugin_next(DLiteMappingPluginIter *iter)
   const DLiteMappingPlugin *api;
   if ((api = (const DLiteMappingPlugin *)plugin_api_iter_next(&iter->iter)))
     return api;
+#ifdef WITH_PYTHON
   if (!iter->stop) {
     int n = iter->n;
     api = dlite_python_mapping_next(dlite_globals_get(), &iter->n);
     if (iter->n == n) iter->stop = 1;
   }
+#endif
   return api;
 }
 


Test patch:
diff --git a/storages/json/tests/CMakeLists.txt b/storages/json/tests/CMakeLists.txt
index 0409f4132..54accc607 100644
--- a/storages/json/tests/CMakeLists.txt
+++ b/storages/json/tests/CMakeLists.txt
@@ -17,13 +17,16 @@ add_custom_target(
     ${dlite_BINARY_DIR}/storages/json/tests
   )
 
-get_filename_component(Python3_LIBDIR ${Python3_LIBRARY_DIRS} DIRECTORY)
 set(dlite_PATH
   $<TARGET_FILE_DIR:dlite>
   $<TARGET_FILE_DIR:dlite-utils>
   $<TARGET_FILE_DIR:dlite-plugins-json>
-  ${Python3_LIBDIR}
   )
+if(WITH_PYTHON)
+  get_filename_component(Python3_LIBDIR ${Python3_LIBRARY_DIRS} DIRECTORY)
+  list(APPEND dlite_PATH ${Python3_LIBDIR})
+endif()
+
 set(dlite_PATH_NATIVE "")
 foreach(path ${dlite_PATH})
   list(APPEND dlite_PATH_NATIVE1 $<SHELL_PATH:${path}>)