diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 44106e9b24fd09f70f68e601e79df35aa97aec64..e5932d0f16a7009ef4e7270a518f2175bf12807b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -94,7 +94,7 @@ variables:
 .xercesc-build-template-job: &xercesc-job
   stage: step-A
   variables:
-    CMAKE_ARGS: ${CMAKE_BASE_ARGS}
+    CMAKE_ARGS: -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../install/xerces-c-${XERCESC_VERSION} # was: ${CMAKE_BASE_ARGS}
     XERCESC_VERSION: ${XERCESC_VERSION_BASE}
   script:
     - pwd; ls
@@ -123,7 +123,7 @@ variables:
     - cd ../
     - mkdir Geant4-build
     - cd Geant4-build
-    - cmake ${CMAKE_ARGS} -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=ON -DGEANT4_BUILD_MULTITHREADED=ON -DXERCESC_ROOT_DIR=../install/xerces-c-${XERCESC_VERSION}/ ../geant4 -DGEANT4_USE_SYSTEM_EXPAT=OFF
+    - cmake ${CMAKE_ARGS} -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=ON -DGEANT4_BUILD_MULTITHREADED=ON -DXERCESC_ROOT_DIR=install/xerces-c-${XERCESC_VERSION}/ ../geant4 -DGEANT4_USE_SYSTEM_EXPAT=OFF
     - make -j4
     - make install
   artifacts:
@@ -144,8 +144,10 @@ variables:
     - cmake --version # CI debug only
     - mkdir build
     - cd build
-    - echo "CMAKE_ARGS - ${CMAKE_ARGS}"
-    - cmake ${CMAKE_ARGS} ${CMAKE_EXTRA_FLAGS} .. # the CMAKE_EXTRA_FLAGS are set by specific jobs when needed
+    - echo "CMAKE_ARGS -- ${CMAKE_ARGS}"
+    - echo "CMAKE_CONFIG_FLAGS -- ${CMAKE_CONFIG_FLAGS}"
+    - echo "CMAKE_EXTRA_FLAGS -- ${CMAKE_EXTRA_FLAGS}"
+    - cmake ${CMAKE_ARGS} ${CMAKE_CONFIG_FLAGS} ${CMAKE_EXTRA_FLAGS} .. # the CMAKE_EXTRA_FLAGS are set by specific jobs when needed
     - cmake --build . -- -j2
     - cmake --build . -- install
     - pwd; ls # CI debug only
@@ -286,6 +288,17 @@ ubu-gm-gmg4-builtinjson:
     CMAKE_CONFIG_FLAGS: -DGEOMODEL_BUILD_GEOMODELG4=TRUE
     CMAKE_EXTRA_FLAGS: -DGEOMODEL_USE_BUILTIN_JSON=TRUE
 
+ubu-gm-gmg4-builtinxercesc-builtinjson:
+  <<: *ubuntu-job
+  <<: *geomodel-job
+  stage: step-C
+  needs: ["ubu-geant4"]
+  variables:
+    CMAKE_ARGS: ${CMAKE_BASE_ARGS}
+    CMAKE_CONFIG_FLAGS: -DGEOMODEL_BUILD_GEOMODELG4=TRUE
+    CMAKE_EXTRA_FLAGS: -DGEOMODEL_USE_BUILTIN_JSON=TRUE -DGEOMODEL_USE_BUILTIN_XERCESC=TRUE
+
+
 ubu-gm-fullsimlight-builtinjson:
   <<: *ubuntu-job
   <<: *geomodel-job
@@ -296,6 +309,17 @@ ubu-gm-fullsimlight-builtinjson:
     CMAKE_CONFIG_FLAGS: -DGEOMODEL_BUILD_FULLSIMLIGHT=TRUE
     CMAKE_EXTRA_FLAGS: -DGEOMODEL_USE_BUILTIN_JSON=TRUE
 
+ubu-gm-fullsimlight-builtinxercesc-builtinjson:
+  <<: *ubuntu-job
+  <<: *geomodel-job
+  stage: step-C
+  needs: ["ubu-geant4"]
+  variables:
+    CMAKE_ARGS: ${CMAKE_BASE_ARGS}
+    CMAKE_CONFIG_FLAGS: -DGEOMODEL_BUILD_FULLSIMLIGHT=TRUE
+    CMAKE_EXTRA_FLAGS: -DGEOMODEL_USE_BUILTIN_JSON=TRUE -DGEOMODEL_USE_BUILTIN_XERCESC=TRUE 
+
+
 ubu-gm-fullsimlight-customxercesc-builtinjson:
   <<: *ubuntu-job
   <<: *geomodel-job
@@ -305,7 +329,7 @@ ubu-gm-fullsimlight-customxercesc-builtinjson:
     XERCESC_VERSION: 3.2.3
     CMAKE_ARGS: ${CMAKE_BASE_ARGS}
     CMAKE_CONFIG_FLAGS: -DGEOMODEL_BUILD_FULLSIMLIGHT=TRUE
-    CMAKE_EXTRA_FLAGS: -DGEOMODEL_USE_BUILTIN_JSON=TRUE -DXercesC_INCLUDE_DIR=../install/xerces-c-${XERCESC_VERSION}/include -DXercesC_LIBRARY=../install/xerces-c-${XERCESC_VERSION}/lib/libxerces-c.dylib 
+    CMAKE_EXTRA_FLAGS: -DGEOMODEL_USE_BUILTIN_JSON=TRUE -DXercesC_INCLUDE_DIR=./install/xerces-c-${XERCESC_VERSION}/include -DXercesC_LIBRARY=./install/xerces-c-${XERCESC_VERSION}/lib/libxerces-c.dylib 
 
 
 ### Documentation
diff --git a/FullSimLight/CMakeLists.txt b/FullSimLight/CMakeLists.txt
index 422d40a9269c9c04bbe24adb5a1fb5185e0b00da..ac33977af2a5fca2560f1e6b366ebc65a6f7a560 100644
--- a/FullSimLight/CMakeLists.txt
+++ b/FullSimLight/CMakeLists.txt
@@ -70,6 +70,7 @@ find_package(Pythia QUIET) # optional
 # Setup Geant4 include directories and compile definitions
 # Setup include directory for this project
 #
+#message("Geant4_USE_FILE: ${Geant4_USE_FILE}") # debug msg
 include(${Geant4_USE_FILE})
 include_directories(${PROJECT_SOURCE_DIR}/include)
 
@@ -108,7 +109,6 @@ if( GEOMODEL_USE_BUILTIN_JSON )
   add_dependencies( gmclash JSONExt )
   add_dependencies( fillHistogramExample JSONExt )
   add_dependencies( gmgeantino JSONExt )
-  # add_dependencies( plotGeantinoMaps JSONExt )
   add_dependencies( testMagneticField JSONExt )
   add_dependencies( gmtogdml JSONExt )
   # Acquire Installation Directory of JSONExt
@@ -116,7 +116,15 @@ if( GEOMODEL_USE_BUILTIN_JSON )
   # Include the installed 'include' PATH
   include_directories (${install_dir}/include)
 endif()
-
+# If the in-house build of the Xerces-C library is used, add explicit dependency: for Geant4
+if( GEOMODEL_USE_BUILTIN_XERCESC )
+    add_dependencies( fullSimLight XercesCBuiltIn )
+    add_dependencies( gmclash XercesCBuiltIn )
+    add_dependencies( fillHistogramExample XercesCBuiltIn )
+    add_dependencies( gmgeantino XercesCBuiltIn )
+    add_dependencies( testMagneticField XercesCBuiltIn )
+    add_dependencies( gmtogdml XercesCBuiltIn )
+endif()
 #----------------------------------------------------------------------------
 # Link all needed libraries
 #
diff --git a/FullSimLight/MagneticField/MagFieldServices/CMakeLists.txt b/FullSimLight/MagneticField/MagFieldServices/CMakeLists.txt
index 2b04fee0e09c2bba7fb771f5ef7784b48c79a75a..dd6f7e13b72c0d4c1f58f36784de203fc6e8f351 100644
--- a/FullSimLight/MagneticField/MagFieldServices/CMakeLists.txt
+++ b/FullSimLight/MagneticField/MagFieldServices/CMakeLists.txt
@@ -15,6 +15,7 @@ if( Eigen3_FOUND )
 else()
  message(STATUS "Eigen3 not found")
 endif()
+
 #----------------------------------------------------------------------------
 # Find Geant4 package, batch mode only executable (i.e. no need ui and vis).
 #
@@ -60,6 +61,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${OUTPUT})
 
 # Set target and properties
 add_library( MagFieldServices SHARED ${HEADERS} ${SOURCES} )
+# If the in-house build of the Xerces-C library is used, add explicit dependency: for Geant4
+if( GEOMODEL_USE_BUILTIN_XERCESC )
+    add_dependencies( MagFieldServices XercesCBuiltIn )
+endif()
 target_link_libraries( MagFieldServices PUBLIC ${Geant4_LIBRARIES} MagFieldInterfaces)
 target_include_directories( MagFieldServices PUBLIC ${EIGEN3_INCLUDE_DIR}
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
diff --git a/GeoModelG4/.gitlab-ci.yml b/GeoModelG4/.gitlab-ci.yml
deleted file mode 100644
index 7a3f3c4dff5c7b237a2c9aa0eacc336a0dbfa987..0000000000000000000000000000000000000000
--- a/GeoModelG4/.gitlab-ci.yml
+++ /dev/null
@@ -1,141 +0,0 @@
-stages:
-  - deps-geomodelcore
-  - deps-xerces-c
-  - deps-Geant4
-  - build
-
-
-variables:
-  CMAKE_BASE_ARGS: -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../install
-  GIT_SUBMODULE_STRATEGY: recursive
-
-
-# TEMPLATES FOR BUILDING ON DIFFERENT PLATFORMS
-.macos-template-job: &macos-job
-  tags:
-    - macos-geomodeldev
-  allow_failure: true
-  timeout: 60 minutes
-  before_script:
-    - export PATH="/usr/local/opt/qt/bin:$PATH" # to make Qt5 discoverable by CMake
-
-.ubuntu-template-job: &ubuntu-job
-  image: gitlab-registry.cern.ch/mbandier/geant4-ubuntu/base-image:1.1
-  tags:
-    - docker
-  before_script: 
-    - apt-get update -qq && apt-get install -y -qq libeigen3-dev libsqlite3-dev
-
-.geomodelcore-build-template-job: &geomodelcore-job
-  stage: deps-geomodelcore
-  variables:
-    CMAKE_ARGS: ${CMAKE_BASE_ARGS}
-  script:
-    - pwd; ls
-    - git clone https://gitlab.cern.ch/GeoModelDev/GeoModelCore.git
-    - mkdir geomodelcore-build
-    - cd geomodelcore-build
-    - cmake ${CMAKE_ARGS} ../GeoModelCore
-    - make -j4
-    - make install
-  artifacts:
-    paths:
-      - install
-
-.xerces-c-build-template-job: &xerces-c-job
-  stage: deps-xerces-c
-  variables:
-    CMAKE_ARGS: ${CMAKE_BASE_ARGS}
-  script:
-    - pwd; ls
-    - wget https://archive.apache.org/dist/xerces/c/3/sources/xerces-c-3.2.2.tar.gz
-    - tar -xf xerces-c-3.2.2.tar.gz
-    - mkdir xerces-c-build
-    - cd xerces-c-build
-    - cmake ${CMAKE_ARGS} ../xerces-c-3.2.2
-    - make -j4
-    - make install
-  artifacts:
-    paths:
-      - install
-
-
-.Geant4-build-template-job: &Geant4-job
-  stage: deps-Geant4
-  variables:
-    CMAKE_ARGS: ${CMAKE_BASE_ARGS}
-  script:
-    - pwd; ls
-    - git clone https://gitlab.cern.ch/geant4/geant4.git
-    - cd geant4
-    - git checkout tags/v10.6.0
-    - cd ../
-    - mkdir Geant4-build
-    - cd Geant4-build
-    - cmake ${CMAKE_ARGS} -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_GDML=ON -DGEANT4_BUILD_MULTITHREADED=ON -DXERCESC_ROOT_DIR=../install/xerces-c/ ../geant4 -DGEANT4_USE_SYSTEM_EXPAT=OFF
-    - make -j4
-    - make install
-  artifacts:
-    paths:
-      - install
-
-.geomodelg4-build-template: &geomodelg4-job
-  stage: build
-  variables:
-    CMAKE_ARGS: ${CMAKE_BASE_ARGS}
-  script:
-    - pwd; ls
-    - mkdir build
-    - cd build
-    - cmake ${CMAKE_ARGS} ..
-    - make -j4
-    - make install
-  artifacts:
-    paths:
-      - install
-
-# ACTUAL JOBS
-
-### MACOS PATH
-geomodelcore-mac:
-  <<: *macos-job
-  <<: *geomodelcore-job
-
-xerces-c-mac:
-  <<: *macos-job
-  <<: *xerces-c-job
-
-Geant4-mac:
-  <<: *macos-job
-  <<: *Geant4-job
-  needs: ["xerces-c-mac"]
-
-geomodelg4-mac:
-  <<: *macos-job
-  <<: *geomodelg4-job
-  needs: ["geomodelcore-mac", "Geant4-mac"]
-
-
-### UBUNTU PATH
-geomodelcore-ubuntu:
-  <<: *ubuntu-job
-  <<: *geomodelcore-job
-
-#geomodelio-ubuntu:
-#  <<: *ubuntu-job
-#  <<: *geomodelio-job
-#  needs: ["geomodelcore-ubuntu"]
-
-# xerces-c-ubuntu:
-#   <<: *ubuntu-job
-#   <<: *xerces-c-job
-
-# Geant4-ubuntu:
-#   <<: *ubuntu-job
-#   <<: *Geant4-job
-#   needs: ["xerces-c-ubuntu"]
-
-geomodelg4-ubuntu:
-  <<: *ubuntu-job
-  <<: *geomodelg4-job
-  needs: ["geomodelcore-ubuntu"]
diff --git a/GeoModelG4/CI/Dockerfile b/GeoModelG4/CI/Dockerfile
deleted file mode 100644
index 407663da17bf54ad488bde578c4afdef3ef47dd2..0000000000000000000000000000000000000000
--- a/GeoModelG4/CI/Dockerfile
+++ /dev/null
@@ -1,12 +0,0 @@
-FROM cern/slc6-base:latest
-
-
-# minimal development packages
-RUN yum -y update \
-    && yum -y install \
-        cmake \
-        glibc-devel \
-        which \
-    && yum -y clean all
-
-
diff --git a/GeoModelG4/CI/setup_lcg.sh b/GeoModelG4/CI/setup_lcg.sh
deleted file mode 100755
index 1b036825adb8199c15d50099c25b84f3dbb28185..0000000000000000000000000000000000000000
--- a/GeoModelG4/CI/setup_lcg.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh -ex
-#
-# setup LCG release via cvmfs
-
-# determine os release
-if [ "$(cat /etc/redhat-release | grep 'Scientific Linux CERN SLC release 6')" ]; then
-  os=slc6
-  compiler=gcc62-opt
-elif [ "$(cat /etc/centos-release | grep 'CentOS Linux release 7')" ]; then
-  os=centos7
-  compiler=gcc7-opt
-else
-  echo "Unknown OS" 1>&2
-  exit 1
-fi
-
-release=LCG_95
-platform=x86_64-${os}-${compiler}
-lcg=/cvmfs/sft.cern.ch/lcg/views/${release}/${platform}
-
-source ${lcg}/setup.sh
-
-
diff --git a/GeoModelG4/CMakeLists.txt b/GeoModelG4/CMakeLists.txt
index b869561aad18ed05451e05cba34addd11b1a98ca..d184b36e3d1764421dc83447757fcfe6124e53e9 100644
--- a/GeoModelG4/CMakeLists.txt
+++ b/GeoModelG4/CMakeLists.txt
@@ -2,8 +2,8 @@
 cmake_minimum_required( VERSION 3.1 )
 project( "GeoModelG4" VERSION 1.1.0 LANGUAGES CXX )
 
-message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
-message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
+#message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}") # debug msg
+#message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}") # debug msg
 if( (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) OR GEOMODEL_BUILD_GEOMODELG4_FROM_FULLSIMLIGHT )
     # I am top-level project.
     # Make the root module directory visible to CMake.
@@ -18,14 +18,19 @@ if( (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) OR GEOMODEL_BUILD_GEOMODELG4_
          "Framework finding behaviour on macOS" )
     # Find the base GeoModel packages, which must be installed on the target system already
     find_package( GeoModelCore REQUIRED 4.0.0 ) #TODO: the version should be se in the root folder
+    # Find Geant4, if not triggered by FullSimLight, where Geant4 is already found/set.
+    if( NOT GEOMODEL_BUILD_GEOMODELG4_FROM_FULLSIMLIGHT )
+        find_package( Geant4 REQUIRED )
+        include( SetupXercesC )
+    endif()
     # Set a flag to steer the  of the subpackages
     set( ${PROJECT_NAME}_INDIVIDUAL_BUILD ON )
 else()
     # I am called from other project with add_subdirectory().
     message( STATUS "Building ${PROJECT_NAME} as part of the root GeoModel project.")
+    # External dependencies:
+    find_package( Geant4 REQUIRED )
 endif()
-# External dependencies:
-find_package( Geant4 REQUIRED )
 
 # Set up the build of the three libraries of the project.
 add_subdirectory(GeoSpecialShapes)
diff --git a/GeoModelG4/GeoMaterial2G4/CMakeLists.txt b/GeoModelG4/GeoMaterial2G4/CMakeLists.txt
index a5f6e9f21023e94114ddbc06f126882b63c2231d..992deb6c52a8b88c4e249fb5670c8fde2d48c6fe 100644
--- a/GeoModelG4/GeoMaterial2G4/CMakeLists.txt
+++ b/GeoModelG4/GeoMaterial2G4/CMakeLists.txt
@@ -18,7 +18,10 @@ include(${Geant4_USE_FILE})
 
 # Set target and properties
 add_library( GeoMaterial2G4 SHARED ${HEADERS} ${SOURCES} )
-
+# If the in-house build of the nlohmann_json library is used, add explicit dependency
+if( GEOMODEL_USE_BUILTIN_XERCESC )
+    add_dependencies( GeoMaterial2G4 XercesCBuiltIn )
+endif()
 # Check if we are building FullSimLight individually,
 # or as a part of the main GeoModel.
 # In the first case, we link against the imported targets, which are taken
diff --git a/GeoModelG4/GeoSpecialShapes/CMakeLists.txt b/GeoModelG4/GeoSpecialShapes/CMakeLists.txt
index 9ec7c2e37e78e643ef3e3bda90c6f98a5ad59fd4..1e4f17dd98b1bca702edc8c2fd8fd3e568c7303d 100644
--- a/GeoModelG4/GeoSpecialShapes/CMakeLists.txt
+++ b/GeoModelG4/GeoSpecialShapes/CMakeLists.txt
@@ -17,6 +17,10 @@ file( GLOB HEADERS GeoSpecialShapes/*.h src/LArWheelCalculator_Impl/*.h)
 
 # Set the library.
 add_library( GeoSpecialShapes SHARED ${HEADERS} ${SOURCES} )
+# If the in-house build of the nlohmann_json library is used, add explicit dependency
+if( GEOMODEL_USE_BUILTIN_XERCESC )
+    add_dependencies( GeoSpecialShapes XercesCBuiltIn )
+endif()
 target_link_libraries( GeoSpecialShapes PRIVATE ${Geant4_LIBRARIES})
 # Check if we are building FullSimLight individually,
 # or as a part of the main GeoModel.
diff --git a/GeoModelG4/LICENSE b/GeoModelG4/LICENSE
deleted file mode 100644
index c8f313a89ab99d4c3c3bda6be312aa07d2009497..0000000000000000000000000000000000000000
--- a/GeoModelG4/LICENSE
+++ /dev/null
@@ -1,201 +0,0 @@
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
-   APPENDIX: How to apply the Apache License to your work.
-
-      To apply the Apache License to your work, attach the following
-      boilerplate notice, with the fields enclosed by brackets "{}"
-      replaced with your own identifying information. (Don't include
-      the brackets!)  The text should be enclosed in the appropriate
-      comment syntax for the file format. We also recommend that a
-      file or class name and description of purpose be included on the
-      same "printed page" as the copyright notice for easier
-      identification within third-party archives.
-
-   Copyright 2019 GeoModelDev
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
diff --git a/GeoModelTools/GDMLtoGM/CMakeLists.txt b/GeoModelTools/GDMLtoGM/CMakeLists.txt
index 58d8df4d07e7b08781c47e3119b9925d0e0e2556..0ad2e90acbbfa31910b4b860e08280e8003c2fe9 100644
--- a/GeoModelTools/GDMLtoGM/CMakeLists.txt
+++ b/GeoModelTools/GDMLtoGM/CMakeLists.txt
@@ -6,6 +6,12 @@ file( GLOB HEADERS GDMLInterface/*.h )
 
 # Create the library.
 add_library( GDMLtoGM SHARED ${HEADERS} ${SOURCES} )
+
+# If the in-house build of the Xerces-C library is used, add explicit dependency
+if( GEOMODEL_USE_BUILTIN_XERCESC )
+    add_dependencies( GDMLtoGM XercesCBuiltIn )
+endif()
+
 target_link_libraries( GDMLtoGM PUBLIC XercesC::XercesC
    ExpressionEvaluator GeoModelXMLParser GeoModelKernel )
 target_include_directories( GDMLtoGM PUBLIC
@@ -16,9 +22,6 @@ source_group( "src" FILES ${SOURCES} )
 set_target_properties( GDMLtoGM PROPERTIES
    VERSION ${PROJECT_VERSION}
    SOVERSION ${PROJECT_VERSION_MAJOR} )
-if( GEOMODEL_USE_BUILTIN_XERCESC )
-   add_dependencies( GDMLtoGM XercesC )
-endif()
 
 # Install the library.
 install( TARGETS GDMLtoGM
diff --git a/GeoModelTools/GeoModelXMLParser/CMakeLists.txt b/GeoModelTools/GeoModelXMLParser/CMakeLists.txt
index 47d12c2623b2eea3f023dbdbc3663f8a9636f8cd..cc59c76c6f2f424ea725b138a8162d9faf916745 100644
--- a/GeoModelTools/GeoModelXMLParser/CMakeLists.txt
+++ b/GeoModelTools/GeoModelXMLParser/CMakeLists.txt
@@ -6,6 +6,10 @@ file( GLOB HEADERS GeoModelXMLParser/*.h )
 
 # Create the library.
 add_library( GeoModelXMLParser SHARED ${HEADERS} ${SOURCES} )
+# If the in-house build of the Xerces-C library is used, add explicit dependency
+if( GEOMODEL_USE_BUILTIN_XERCESC )
+    add_dependencies( GeoModelXMLParser XercesCBuiltIn )
+endif()
 target_link_libraries( GeoModelXMLParser PUBLIC XercesC::XercesC
    ExpressionEvaluator )
 target_include_directories( GeoModelXMLParser PUBLIC
@@ -16,9 +20,6 @@ source_group( "src" FILES ${SOURCES} )
 set_target_properties( GeoModelXMLParser PROPERTIES
    VERSION ${PROJECT_VERSION}
    SOVERSION ${PROJECT_VERSION_MAJOR} )
-if( GEOMODEL_USE_BUILTIN_XERCESC )
-   add_dependencies( GeoModelXMLParser XercesC )
-endif()
 
 # Install the library.
 install( TARGETS GeoModelXMLParser
diff --git a/cmake/SetupXercesC.cmake b/cmake/SetupXercesC.cmake
index e36c03577e8bc990fcfdeebc3c0b2206d49665de..785c2e977463156d4dafef6c79133c841185adec 100644
--- a/cmake/SetupXercesC.cmake
+++ b/cmake/SetupXercesC.cmake
@@ -20,11 +20,12 @@ if( GEOMODEL_USE_BUILTIN_XERCESC )
 
    # The include directory and library that will be produced.
    set( XercesC_INCLUDE_DIR
-      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/${CMAKE_INSTALL_INCLUDEDIR}" )
-  set( XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}" FORCE )
+       "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH "Path to the Xerces-C include directory" FORCE )
+  set( XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}" )
    set( XercesC_LIBRARY
-      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/lib/${CMAKE_SHARED_LIBRARY_PREFIX}xerces-c${CMAKE_SHARED_LIBRARY_SUFFIX}" )
+       "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall/lib/${CMAKE_SHARED_LIBRARY_PREFIX}xerces-c${CMAKE_SHARED_LIBRARY_SUFFIX}" CACHE PATH "Path to the Xerces-C library file" FORCE )
    set( XercesC_LIBRARIES "${XercesC_LIBRARY}" )
+   set( XercesC_LIBRARY_RELEASE "${XercesC_LIBRARY}" CACHE PATH "Path to the Xerces-C library" FORCE )
    set( XercesC_VERSION "3.2.3" )
 
    # Create the include directory already, otherwise CMake refuses to
@@ -33,7 +34,7 @@ if( GEOMODEL_USE_BUILTIN_XERCESC )
 
    # Build/install Eigen3 using ExternalProject_Add(...).
    include( ExternalProject )
-   ExternalProject_Add( XercesC
+   ExternalProject_Add( XercesCBuiltIn
       PREFIX "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCBuild"
       INSTALL_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/XercesCInstall"
       URL "https://cern.ch/lcgpackages/tarFiles/sources/xerces-c-${XercesC_VERSION}.tar.gz"