Tests that use their own CMake

Recently, I was having some trouble getting all my tests to pass due a complaint about CMake. The message I was receiving was

CMake Error at CMakeLists.txt:5 (find_package):
  Could not find a package configuration file provided by "OpenMC" with any
  of the following names:

    OpenMCConfig.cmake
    openmc-config.cmake

  Add the installation prefix of "OpenMC" to CMAKE_PREFIX_PATH or set
  "OpenMC_DIR" to a directory containing one of the above files.  If "OpenMC"
  provides a separate development package or SDK, be sure it has been
  installed.

This error occurred three times

regression_tests/cpp_driver/test.py E                                                                                                                                                                                                  
regression_tests/source_dlopen/test.py E                                                                                                                                                                                               
regression_tests/source_parameterized_dlopen/test.py E    

At first, I thought this issue was due to my initial configuration, which used this command:

cmake -DCMAKE_INSTALL_PREFIX=/home/lgross/opt/openmc -DOPENMC_USE_MPI=ON -DCMAKE_BUILD_TYPE=Debug ..

I tried adding the -DCMAKE_PREFIX_PATH flag with a few different paths containing the file OpenMCConfig.cmake but to no success; the complaint remained. What I noticed (with the help of @gonuke) is that all the tests that were failing create their own CMakeLists.txt and store the path as a variable openmc_dir. (tests: the moab tests is skipped for me, but I’d suspect it to fail if I had DAGMC enabled)

I’m wondering why we do this instead of using the original CMake that builds OpenMC. The suggestion of the error did not work because it was the test configuration that failed not the OpenMC initial configuration. I eventually just set the environment variable OpenMC_DIR to the path of my regular OpenMCCmake.config generated during the configuration, which allowed the tests to pass, though I’m not sure this is the best solution.

I’m not exactly sure why these tests failed since it seems like they’re supposed to handle finding CMake (and they’ve never failed for me until recently). If they can pass with my OpenMCConfig.cmake from initial configuration, I’m wondering why we need to use a custom cmake in these tests.

Is there some software reason that is above my understanding to do it this way? Maybe if this isn’t an issue for others, there’s some problem with my environment.