Thanks for your comments, Brad.

I added a patch to convert the file(WRITE) calls in
_ep_write_log_script to file(GENERATE) calls. It works OK in my tests,
but honestly I'm not confident enough in those changes. Any test
recommendations?

I also added a patch to write init and log scripts to "xxx-$<CONFIG>".
Also works, but I don't think my tests covered all cases.

Full patch set attached.

---
>From cedeaaa4a285eab4b233e8a34be1e468e917e092 Mon Sep 17 00:00:00 2001
From: Pokrovskiy <pok...@amazon.com>
Date: Thu, 16 Apr 2015 21:42:19 -0700
Subject: [PATCH 1/3] ExternalProject_Add: Allow generator expressions in
 CMAKE_CACHE_ARGS

---
 Modules/ExternalProject.cmake | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
index 0c73d41..1c7cf51 100644
--- a/Modules/ExternalProject.cmake
+++ b/Modules/ExternalProject.cmake
@@ -1126,10 +1126,7 @@ function(_ep_write_initial_cache target_name
script_filename script_initial_cach
   # Replace location tags.
   _ep_replace_location_tags(${target_name} script_initial_cache)
   # Write out the initial cache file to the location specified.
-  if(NOT EXISTS "${script_filename}.in")
-    file(WRITE "${script_filename}.in" "\@script_initial_cache\@\n")
-  endif()
-  configure_file("${script_filename}.in" "${script_filename}")
+  file(GENERATE OUTPUT "${script_filename}" CONTENT "${script_initial_cache}")
 endfunction()


-- 
2.3.2 (Apple Git-55)

>From ef7f2279ccc4c8b557bb61310283c64f3901b7d8 Mon Sep 17 00:00:00 2001
From: Pokrovskiy <pok...@amazon.com>
Date: Mon, 20 Apr 2015 23:28:21 -0700
Subject: [PATCH 2/3]  ExternalProject_Add: Allow generator expressions in
 CMAKE_ARGS when LOG_BUILD is set

---
 Modules/ExternalProject.cmake | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
index 1c7cf51..c238d60 100644
--- a/Modules/ExternalProject.cmake
+++ b/Modules/ExternalProject.cmake
@@ -1299,14 +1299,14 @@ endif()
       endif()
     endforeach()
     set(code "${code}set(command \"${cmd}\")${code_execute_process}")
-    file(WRITE ${stamp_dir}/${name}-${step}-impl.cmake "${code}")
+    file(GENERATE OUTPUT "${stamp_dir}/${name}-${step}-impl.cmake"
CONTENT "${code}")
     set(command ${CMAKE_COMMAND} "-Dmake=\${make}"
"-Dconfig=\${config}" -P ${stamp_dir}/${name}-${step}-impl.cmake)
   endif()

   # Wrap the command in a script to log output to files.
   set(script ${stamp_dir}/${name}-${step}.cmake)
   set(logbase ${stamp_dir}/${name}-${step})
-  file(WRITE ${script} "
+  set(code "
 ${code_cygpath_make}
 set(command \"${command}\")
 execute_process(
@@ -1327,6 +1327,7 @@ else()
   message(STATUS \"\${msg}\")
 endif()
 ")
+  file(GENERATE OUTPUT "${script}" CONTENT "${code}")
   set(command ${CMAKE_COMMAND} ${make} ${config} -P ${script})
   set(${cmd_var} "${command}" PARENT_SCOPE)
 endfunction()
-- 
2.3.2 (Apple Git-55)

>From 722d2d93d41a8a9aa406485a903a2813a620a1e8 Mon Sep 17 00:00:00 2001
From: Pokrovskiy <pok...@amazon.com>
Date: Mon, 20 Apr 2015 23:51:28 -0700
Subject: [PATCH 3/3] ExternalProject_Add: per-configuration init and log
 scripts

---
 Modules/ExternalProject.cmake | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
index c238d60..03d6b82 100644
--- a/Modules/ExternalProject.cmake
+++ b/Modules/ExternalProject.cmake
@@ -1299,12 +1299,12 @@ endif()
       endif()
     endforeach()
     set(code "${code}set(command \"${cmd}\")${code_execute_process}")
-    file(GENERATE OUTPUT "${stamp_dir}/${name}-${step}-impl.cmake"
CONTENT "${code}")
+    file(GENERATE OUTPUT
"${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake" CONTENT "${code}")
     set(command ${CMAKE_COMMAND} "-Dmake=\${make}"
"-Dconfig=\${config}" -P ${stamp_dir}/${name}-${step}-impl.cmake)
   endif()

   # Wrap the command in a script to log output to files.
-  set(script ${stamp_dir}/${name}-${step}.cmake)
+  set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake)
   set(logbase ${stamp_dir}/${name}-${step})
   set(code "
 ${code_cygpath_make}
@@ -2052,7 +2052,7 @@ function(_ep_add_configure_command name)
     get_property(cmake_cache_default_args TARGET ${name} PROPERTY
_EP_CMAKE_CACHE_DEFAULT_ARGS)

     if(cmake_cache_args OR cmake_cache_default_args)
-      set(_ep_cache_args_script "${tmp_dir}/${name}-cache.cmake")
+      set(_ep_cache_args_script "${tmp_dir}/${name}-cache-$<CONFIG>.cmake")
       if(cmake_cache_args)
         _ep_command_line_to_initial_cache(script_initial_cache_force
"${cmake_cache_args}" 1)
       endif()
-- 
2.3.2 (Apple Git-55)

On Mon, Apr 20, 2015 at 6:26 PM, Andrey Pokrovskiy
<wonder.m...@gmail.com> wrote:
> Please disregard my previous email, didn't notice Brad's reply.
>
> On Mon, Apr 20, 2015 at 6:25 PM, Andrey Pokrovskiy
> <wonder.m...@gmail.com> wrote:
>> Will it go to mainline? Is there any formal code review process?
>>
>> On Fri, Apr 17, 2015 at 10:58 AM, David Cole <dlrd...@aol.com> wrote:
>>> Great -- thanks for checking. This proposed change looks reasonable to me...
>>>
>>> On Fri, Apr 17, 2015 at 12:27 PM, Andrey Pokrovskiy
>>> <wonder.m...@gmail.com> wrote:
>>>>> does the external project's configure step re-run when you edit only the 
>>>>> CMAKE_CACHE_ARGS for it?
>>>>
>>>> Yes. Verified with the following example:
>>>>
>>>> ----
>>>> cmake_minimum_required(VERSION 3.2)
>>>>
>>>> project(CMakeExternalProjectGenExpr)
>>>>
>>>> include(ExternalProject)
>>>>
>>>> set(ZF_QUEUE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/zf_queue.install")
>>>>
>>>> ExternalProject_Add(zf_queue_ep
>>>>     GIT_REPOSITORY https://github.com/wonder-mice/zf_queue.git
>>>>     UPDATE_COMMAND ""
>>>>     INSTALL_DIR ${ZF_QUEUE_INSTALL_PREFIX}
>>>>     CMAKE_CACHE_ARGS
>>>>         -DCMAKE_INSTALL_PREFIX:string=<INSTALL_DIR>)
>>>>
>>>> On Fri, Apr 17, 2015 at 4:19 AM, David Cole <dlrd...@aol.com> wrote:
>>>>> With this change, does the external project's configure step re-run
>>>>> when you edit only the CMAKE_CACHE_ARGS for it?
>>>>>
>>>>> (It did with the *.in / configure_file approach...)
>>>>>
>>>>>
>>>>> On Fri, Apr 17, 2015 at 12:55 AM, Andrey Pokrovskiy
>>>>> <wonder.m...@gmail.com> wrote:
>>>>>> In current implementation of ExternalProject_Add generator expressions
>>>>>> are supported in CMAKE_ARGS (probably by coincidence), but not in
>>>>>> CMAKE_CACHE_ARGS. This patch will enable generators expressions in
>>>>>> CMAKE_CACHE_ARGS.
>>>>>>
>>>>>> Use case:
>>>>>> set(LIBEV_LIBRARIES $<TARGET_FILE:ev>)
>>>>>> ExternalProject_Add(
>>>>>>     ...
>>>>>>     CMAKE_CACHE_ARGS
>>>>>>          -DLIBEV_LIBRARIES=${LIBEV_LIBRARIES}
>>>>>>     ...)
>>>>>>
>>>>>> ---
>>>>>>  Modules/ExternalProject.cmake | 5 +----
>>>>>>  1 file changed, 1 insertion(+), 4 deletions(-)
>>>>>>
>>>>>> diff --git a/Modules/ExternalProject.cmake 
>>>>>> b/Modules/ExternalProject.cmake
>>>>>> index 0c73d41..1c7cf51 100644
>>>>>> --- a/Modules/ExternalProject.cmake
>>>>>> +++ b/Modules/ExternalProject.cmake
>>>>>> @@ -1126,10 +1126,7 @@ function(_ep_write_initial_cache target_name
>>>>>> script_filename script_initial_cach
>>>>>>    # Replace location tags.
>>>>>>    _ep_replace_location_tags(${target_name} script_initial_cache)
>>>>>>    # Write out the initial cache file to the location specified.
>>>>>> -  if(NOT EXISTS "${script_filename}.in")
>>>>>> -    file(WRITE "${script_filename}.in" "\@script_initial_cache\@\n")
>>>>>> -  endif()
>>>>>> -  configure_file("${script_filename}.in" "${script_filename}")
>>>>>> +  file(GENERATE OUTPUT "${script_filename}" CONTENT 
>>>>>> "${script_initial_cache}")
>>>>>>  endfunction()
>>>>>>
>>>>>>
>>>>>> --
>>>>>> 2.3.2 (Apple Git-55)
>>>>>>
>>>>>> --
>>>>>>
>>>>>> Powered by www.kitware.com
>>>>>>
>>>>>> Please keep messages on-topic and check the CMake FAQ at: 
>>>>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>>>>
>>>>>> Kitware offers various services to support the CMake community. For more 
>>>>>> information on each offering, please visit:
>>>>>>
>>>>>> CMake Support: http://cmake.org/cmake/help/support.html
>>>>>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>>>>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>>>>>
>>>>>> Visit other Kitware open-source projects at 
>>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>>
>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>> http://public.kitware.com/mailman/listinfo/cmake-developers

Attachment: 0003-ExternalProject_Add-per-configuration-init-and-log-s.patch
Description: Binary data

Attachment: 0002-ExternalProject_Add-Allow-generator-expressions-in-C.patch
Description: Binary data

Attachment: 0001-ExternalProject_Add-Allow-generator-expressions-in-C.patch
Description: Binary data

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to