[Insight-developers] SimpleITK - CMake question (The Saga of Eggs on Windows…)

David Cole david.cole at kitware.com
Tue Sep 20 18:33:37 EDT 2011


If the file has one @var@ per line, the following code works to
extract those variable names. If more than one, you'll have to add to
this code, but it should be reasonably achievable. The code gives you
a sorted list of non-duplicated variable names. (But does nothing to
even detect if there is more than one @var@ per line...


# save as "read_variables.cmake"
# usage: 'cmake -Dfilename=config.h.in -P read_variables.cmake'

if(NOT DEFINED filename)
  message(FATAL_ERROR "usage: 'cmake -Dfilename=config.h.in -P
read_variables.cmake'")
endif()

set(regex "^.*@([^@]+)@.*$")
file(STRINGS "${filename}" results REGEX "${regex}")
set(vars "")

foreach(line ${results})
  string(REGEX MATCH "${regex}" line_match "${line}")
  set(vars ${vars} ${CMAKE_MATCH_1})
  list(SORT vars)
  list(REMOVE_DUPLICATES vars)

  message("line_match='${line_match}'")
  message("CMAKE_MATCH_0='${CMAKE_MATCH_0}'")
  message("CMAKE_MATCH_1='${CMAKE_MATCH_1}'")
  message("")
endforeach()

message("vars='${vars}'")




HTH,
David


On Mon, Sep 19, 2011 at 9:08 PM, Bradley Lowekamp
<blowekamp at mail.nih.gov> wrote:
> Hello David,
>
> I was thinking about just making a generic re-usable macro to accomplish this. What would make this macro really useful is not having to passing a list of cmake variables, which need to be passed to the launched CMake subprocess.
>
> Would you happen to have some cmake code which would scan a configuration file, and obtain a list of CMake variables which are going to be substituted?
>
> Thanks,
> Brad
>
> On Sep 19, 2011, at 1:54 PM, David Cole wrote:
>
>> On Sat, Sep 17, 2011 at 5:26 PM, Bradley Lowekamp
>> <blowekamp at mail.nih.gov> wrote:
>>> Thanks JC,
>>> That is very helpful and explains what is going on. And explains that this
>>> is a bit of a tricky problem.
>>> It appears that the LOCATION property from:
>>>
>>>> get_target_property( SIMPLEITK_BINARY_MODULE
>>>>    ${SWIG_MODULE_SimpleITK_REAL_NAME} LOCATION )
>>>>  configure_file(
>>>> ${SimpleITK_SOURCE_DIR}/Wrapping/PythonPackage/setup.py.in
>>>>    ${SimpleITK_BINARY_DIR}/Wrapping/PythonPackage/setup.py )
>>>
>>> already has the CMAKE_CFG_INITDIR value embedded in it. So the value of
>>>  SIMPLEITK_BINARY_MODULE is
>>> "C:Build/SimpleITK/lib/$(Configuration)/_SimpleITK.pyd".
>>> This value is then later used at configuration time in a "configure_file".
>>> Unfortunately, the documentation linked below, reminds me that the
>>> configuration type is not known at configuration time and is only known at
>>> compilation. So it's impossible to know the value of "$(Configure)"  when
>>> the configuration file is generated.
>>> I guess I need a build time version of "configure_file" which is aware of
>>> what build type is occurring…. Anyone done that before?
>>
>>
>> Sure, you can run a cmake script as an add_custom_command at build
>> time, and then inside the script, you can use configure_file. You'll
>> have to pass -D variable values down into the command if you need
>> variable values defined for the configure_file call. It is definitely
>> something I've done before.
>>
>> Let me know specifics if you'd like a recommendation on converting an
>> existing configure_file call into a build-time scripted call to it
>> instead...
>>
>>
>> David C.
>>
>>
>>> Thanks,
>>> Brad
>>>
>>> ========================================================
>>>
>>> Bradley Lowekamp
>>>
>>> Lockheed Martin Contractor for
>>>
>>> Office of High Performance Computing and Communications
>>>
>>> National Library of Medicine
>>>
>>> blowekamp at mail.nih.gov
>>>
>>> On Sep 17, 2011, at 5:07 PM, Jean-Christophe Fillion-Robin wrote:
>>>
>>> Hi Bradley,
>>>
>>> I am assuming you want the variable to be substituted at build time ...
>>>
>>> Instead of ${Configure} .. try with ${CMAKE_CFG_INTDIR}
>>>
>>> See
>>> http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_CFG_INTDIR
>>>
>>> Hth
>>> Jc
>>>
>>> On Sat, Sep 17, 2011 at 2:59 PM, Bradley Lowekamp <blowekamp at mail.nih.gov>
>>> wrote:
>>>>
>>>> Hello,
>>>>
>>>> There is a cmake variable which is having the following value:
>>>> "C:Build/SimpleITK/lib/$(Configure)/_SimpleITK.pyd"
>>>>
>>>> And is needs to be:
>>>> "C:Build/SimpleITK/lib/Release/_SimpleITK.pyd"
>>>>
>>>> I can finally get the python egg for distribution on windows system, But
>>>> for some reason the "Configure" is not being substituted as needed.
>>>>
>>>> Here is some other CMake snippets relevant:
>>>>
>>>> # from SimpleITK/CMAKE/UseSWIGLocal.cmake
>>>> ...
>>>> ADD_LIBRARY(${SWIG_MODULE_${name}_REAL_NAME}
>>>>    MODULE
>>>>    ${swig_generated_sources}
>>>>    ${swig_other_sources})
>>>> ...
>>>>
>>>> # from SimpleITK/Wrapping/CMakeLists.txt
>>>> ..
>>>>  get_target_property( SIMPLEITK_BINARY_MODULE
>>>>    ${SWIG_MODULE_SimpleITK_REAL_NAME} LOCATION )
>>>>  configure_file(
>>>> ${SimpleITK_SOURCE_DIR}/Wrapping/PythonPackage/setup.py.in
>>>>    ${SimpleITK_BINARY_DIR}/Wrapping/PythonPackage/setup.py )
>>>>>>>>
>>>>
>>>> Any help would be appreciated.
>>>>
>>>> Thanks,
>>>> Brad
>>>>
>>>> _______________________________________________
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at
>>>> http://www.kitware.com/opensource/opensource.html
>>>>
>>>> Kitware offers ITK Training Courses, for more information visit:
>>>> http://kitware.com/products/protraining.html
>>>>
>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.itk.org/mailman/listinfo/insight-developers
>>>
>>>
>>>
>>> --
>>> +1 919 869 8849
>>>
>>>
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Kitware offers ITK Training Courses, for more information visit:
>>> http://kitware.com/products/protraining.html
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-developers
>>>
>>>
>
>


More information about the Insight-developers mailing list