# Issue with TARGETS\_EXPORT\_NAME

**URL:** <https://discourse.cmake.org/t/issue-with-targets-export-name/2508>\
**Category:** Code\
**Created:** [January 11, 2021, 1:41pm UTC](https://discourse.cmake.org/t/issue-with-targets-export-name/2508 "2021-01-11T13:41:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrmsdbdl](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mrmsdbdl/32/2686_2.png) [@mrmsdbdl](https://discourse.cmake.org/u/mrmsdbdl)\
**Post date:** [January 11, 2021, 1:41pm UTC](https://discourse.cmake.org/t/issue-with-targets-export-name/2508/1 "2021-01-11T13:41:07Z")

</div>

Hi,

I’ve this random issue that I don’t really understand why it’s happening. So, while ago, I put some time and improved the `mlpack` CMake’s script, and I think for the most part I got everything right. But, every now and then, I see this random error where `mlpack-targets.cmake` is not being generated correctly.

I’m using [this template](https://github.com/mlpack/mlpack/blob/master/CMake/mlpack-config.cmake.in) to generate the `mlpack-targets`

```auto
@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake)

set_and_check(MLPACK_INCLUDE_DIRS "@PACKAGE_MLPACK_INCS_DIR@")
set(MLPACK_LIBRARIES mlpack::mlpack)

```

but for some reason, the output file, `mlpack-targets.cmake` can end up not being complete,

```auto
include(${CMAKE_CURRENT_LIST_DIR}/.cmake) # ← **NOTICE HERE**

set_and_check(MLPACK_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include")
set(MLPACK_LIBRARIES mlpack::mlpack)

```

This of course causes CMake to throw and not being able to configure mlpack in my project. I think I did everything correctly, but apparently not. My workaround is to manually change this file, but that’s a horrible solution. I really appreciate if someone could help me track this down.

The parent `CMakeLists.txt` is [here](https://github.com/mlpack/mlpack/blob/907b7848d83372ae596eabb2da2a0b137be24973/src/mlpack/CMakeLists.txt#L140). And, the only thing I can think of is that since `CMakeLists.txt` is not in a parent directly, CMake gets confused and cannot handle the case correctly! The project has two `CMakeLists.txt` files, and `mlpack-config.cmake.in` is not in the same directory as either of them.

```auto
mlpack/CMakeLists.txt
mlpack/src/mlpack/CMakeLists.txt
mlpack/CMake/mlpack-config.cmake.in

```

and this is the error if `mlpack-targets.cmake` is incomplete:

```auto
CMake Error at /usr/local/lib/cmake/mlpack/mlpack-config.cmake:27 (include):
include could not find load file:

    /usr/local/lib/cmake/mlpack/.cmake
Call Stack (most recent call first):
CMakeLists.txt:40 (find_package)

```

Thanks in advance,  
Amir.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [January 11, 2021, 2:47pm UTC](https://discourse.cmake.org/t/issue-with-targets-export-name/2508/2 "2021-01-11T14:47:35Z")

</div>

Could you post what `mlpack-config.cmake` ends up being when configured? It looks like `TARGETS_EXPORT_NAME` is not valid when it is being configured somehow?

---

<div class="post-metadata">

**Author:** ![mrmsdbdl](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mrmsdbdl/32/2686_2.png) [@mrmsdbdl](https://discourse.cmake.org/u/mrmsdbdl)\
**Post date:** [January 11, 2021, 2:56pm UTC](https://discourse.cmake.org/t/issue-with-targets-export-name/2508/3 "2021-01-11T14:56:12Z")

</div>

I think that’s exactly what happens, but I don’t know why. Here is `mlpack-config.cmake`:

```auto

####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was mlpack-config.cmake.in ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

macro(check_required_components _NAME)
  foreach(comp ${${_NAME}_FIND_COMPONENTS})
    if(NOT ${_NAME}_${comp}_FOUND)
      if(${_NAME}_FIND_REQUIRED_${comp})
        set(${_NAME}_FOUND FALSE)
      endif()
    endif()
  endforeach()
endmacro()

####################################################################################

include(${CMAKE_CURRENT_LIST_DIR}/.cmake)

set_and_check(MLPACK_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include")
set(MLPACK_LIBRARIES mlpack::mlpack)

```

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [January 11, 2021, 2:57pm UTC](https://discourse.cmake.org/t/issue-with-targets-export-name/2508/4 "2021-01-11T14:57:46Z")

</div>

Running `cmake --trace-expand` and looking at the code which gets executed around the `configure_file` for it should show it. I suspect that variable is a parameter to the command which isn’t being passed in.

---

<div class="post-metadata">

**Author:** ![mrmsdbdl](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mrmsdbdl/32/2686_2.png) [@mrmsdbdl](https://discourse.cmake.org/u/mrmsdbdl)\
**Post date:** [January 11, 2021, 4:57pm UTC](https://discourse.cmake.org/t/issue-with-targets-export-name/2508/5 "2021-01-11T16:57:04Z")

</div>

Thanks! I didn’t know about the `--trace-expand`. The result is interesting since I see this:

```auto
CMakeLists.txt(174): set(TARGETS_EXPORT_NAME mlpack-targets )

```

I think as I was expecting and proposed a fixed for, `TARGETS_EXPORT_NAME` should be upper case. I fixed that but today I noticed that the Homebrew version was behind, and I’m guessing that this might be the actual issue.

I’ve updated the formula, and waiting to see how it goes! 🙂
