View Issue Details [ Jump to Notes ] | [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0016026 | CMake | (No Category) | public | 2016-03-20 14:35 | 2016-06-10 14:31 | ||||
Reporter | Stephen Kelly | ||||||||
Assigned To | Kitware Robot | ||||||||
Priority | normal | Severity | minor | Reproducibility | have not tried | ||||
Status | closed | Resolution | moved | ||||||
Platform | OS | OS Version | |||||||
Product Version | |||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0016026: CMake provides no reliable variable for 'the file a function is declared in' | ||||||||
Description | Given $ cat cmake/thefunc.cmake set(somevar "${CMAKE_CURRENT_LIST_DIR}") function(thefunc) message("somevar: ${somevar}") message("listdir: ${CMAKE_CURRENT_LIST_DIR}") endfunction() $ cat dir1/CMakeLists.txt include(thefunc) thefunc() include(GenerateExportHeader) $ cat CMakeLists.txt cmake_minimum_required(VERSION 2.8.12) project(ttt CXX) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) add_subdirectory(dir1) thefunc() if (COMMAND generate_export_header) add_library(foo foo.cpp) generate_export_header(foo) endif() the build output is somevar: /home/stephen/dev/src/playground/cmake/cmake listdir: /home/stephen/dev/src/playground/cmake/dir1 somevar: listdir: /home/stephen/dev/src/playground/cmake CMake Error: File /exportheader.cmake.in does not exist. CMake Error at /home/stephen/dev/prefix/qtbase/kde/share/cmake-3.5/Modules/GenerateExportHeader.cmake:362 (configure_file): configure_file Problem configuring file Call Stack (most recent call first): /home/stephen/dev/prefix/qtbase/kde/share/cmake-3.5/Modules/GenerateExportHeader.cmake:378 (_do_generate_export_header) CMakeLists.txt:14 (generate_export_header) -- Configuring incomplete, errors occurred! That is: CMake doesn't provide a way to determine the file a macro or function is defined in. The workaround is to determine that outside of the function/macro scope. However, that workaround breaks down because the variable and the function/macro do not follow the same scoping rules. The function/macro is available 'globally' after definition, so users can make the mistake of trying to use it in a scope which does not contain the `include()`. This affects at least the GenerateExportHeader module and perhaps other modules shipped with cmake. One workaround is to check the existence of the variable in the function: https://git.reviewboard.kde.org/r/127432/diff/1 [^] Another would be to use a global property instead of a variable for the workaround. A better solution may be for cmake to provide the 'path of the file this code resides in' in a variable. | ||||||||
Tags | No tags attached. | ||||||||
Attached Files | |||||||||
Relationships | |
Relationships |
Notes | |
(0042967) Kitware Robot (administrator) 2016-06-10 14:29 |
Resolving issue as `moved`. This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page. |
Notes |
Issue History | |||
Date Modified | Username | Field | Change |
2016-03-20 14:35 | Stephen Kelly | New Issue | |
2016-06-10 14:29 | Kitware Robot | Note Added: 0042967 | |
2016-06-10 14:29 | Kitware Robot | Status | new => resolved |
2016-06-10 14:29 | Kitware Robot | Resolution | open => moved |
2016-06-10 14:29 | Kitware Robot | Assigned To | => Kitware Robot |
2016-06-10 14:31 | Kitware Robot | Status | resolved => closed |
Issue History |
Copyright © 2000 - 2018 MantisBT Team |