Wow, impressive ... I think.  Looks like voodoo to me :)

Anyone have thoughts on this?  It would mean less to maintain for sure with
multiple build systems, with the caveat of it being hard to fix if it doesn't
work in the future for some reason.

-Brad

On 09/30/2016 02:24 PM, bdoetsch wrote:
> Hey Brad,
> 
> I found a cmake function that converts Makefile.inc files into cmake 
> directives, already in use sitting in the curl project (this one is from 
> curl-7.43.0).  It allows the CMake build to use all the ".c" and ".h" files 
> already defined in Makefile.inc using a bunch of regex replacements.  Not 
> sure how
> resilient it is, but it's working for me on your latest github commit 
> (e46e59454c9e813822052d73e6c77efc731923e8) with macOS 10.11.6. Attached is a 
> patch against your CMakeLists.txt if you're interested in it.
> 
> Thought maybe it could help.  No worries either way,
> 
> Brady
> 
> 
> 
> 
> On 9/29/16 6:14 AM, Brad House via c-ares wrote:
>> On 9/28/16 9:19 AM, Brad House via c-ares wrote:
>>> On 9/28/16 7:40 AM, David Drysdale wrote:
>>>> Any pull request will get run through Travis automatically [1], so you
>>>> shouldn't need a Travis account.
>>>>
>>>> If you're not used to Travis, it's probably easier for me to add
>>>> something -- first attempt at [2], with output at [3].  Does that look
>>>> sensible?
>>>>
>>>> D.
>>>>
>>>> [1] https://travis-ci.org/c-ares/c-ares/builds/163269776
>>>> [2] 
>>>> https://github.com/daviddrysdale/c-ares/commit/fc7917e3c5b99ca4f9be66ea5060a2b49a5bbcec
>>>> [3] https://travis-ci.org/daviddrysdale/c-ares/builds/163350713
>>>>
>>>
>>> Seems reasonable to me.  Built both shared and static variants and test 
>>> utilities,
>>> and tests ran successfully.
>>
>>
>> David, should I import your travis modification commit into my repo so it
>> is part of the c-ares pull request (64)?
>>
>> Thanks.
>> -Brad
> 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f6a779d..7ef257d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -480,61 +480,96 @@ INCLUDE_DIRECTORIES (
        ${CARES_INCLUDE_DIRS}
 )
 
+#      TRANSFORM_MAKEFILE_INC
+#
+# This function consumes the "Makefile.inc" autotools file, and converts it 
into
+#  "Makefile.inc.cmake", a cmake include file; transforming this:
+#
+# CSOURCES = ares__close_sockets.c     \
+#   ares__get_hostent.c                        \
+#   ares__read_line.c                  \
+#   ...
+#
+#   into this:
+# 
+# SET (CSOURCES
+#      ares__close_sockets.c
+#      ares__get_hostent.c
+#      ares__read_line.c
+#      ...
+function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
+  file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
+  string(REPLACE "$(top_srcdir)"   "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT 
${MAKEFILE_INC_TEXT})
+  string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT 
${MAKEFILE_INC_TEXT})
+
+  string(REGEX REPLACE "\\\\\n" "ß!ß" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
+  string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" 
"SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
+  string(REPLACE "ß!ß" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
+
+  string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" 
MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})    # Replace $() with ${}
+  string(REGEX REPLACE "@([a-zA-Z_][a-zA-Z0-9_]*)@" "\${\\1}" 
MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})    # Replace @@ with ${}, even if that 
may not be read by CMake scripts.
+  file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
+endfunction()
+
+# run the function...
+transform_makefile_inc("Makefile.inc" 
"${PROJECT_BINARY_DIR}/Makefile.inc.cmake")
+include(${PROJECT_BINARY_DIR}/Makefile.inc.cmake)
+
 # Source files.
-SET (CARES_SOURCES
-       ares__close_sockets.c
-       ares__get_hostent.c
-       ares__read_line.c
-       ares__timeval.c
-       ares_cancel.c
-       ares_data.c
-       ares_destroy.c
-       ares_expand_name.c
-       ares_expand_string.c
-       ares_fds.c
-       ares_free_hostent.c
-       ares_free_string.c
-       ares_getenv.c
-       ares_gethostbyaddr.c
-       ares_gethostbyname.c
-       ares_getnameinfo.c
-       ares_getsock.c
-       ares_init.c
-       ares_library_init.c
-       ares_llist.c
-       ares_mkquery.c
-       ares_create_query.c
-       ares_nowarn.c
-       ares_options.c
-       ares_parse_a_reply.c
-       ares_parse_aaaa_reply.c
-       ares_parse_mx_reply.c
-       ares_parse_naptr_reply.c
-       ares_parse_ns_reply.c
-       ares_parse_ptr_reply.c
-       ares_parse_soa_reply.c
-       ares_parse_srv_reply.c
-       ares_parse_txt_reply.c
-       ares_platform.c
-       ares_process.c
-       ares_query.c
-       ares_search.c
-       ares_send.c
-       ares_strcasecmp.c
-       ares_strdup.c
-       ares_strerror.c
-       ares_timeout.c
-       ares_version.c
-       ares_writev.c
-       bitncmp.c
-       inet_net_pton.c
-       inet_ntop.c
-       windows_port.c
-)
+# SET (CSOURCES
+#      ares__close_sockets.c
+#      ares__get_hostent.c
+#      ares__read_line.c
+#      ares__timeval.c
+#      ares_cancel.c
+#      ares_data.c
+#      ares_destroy.c
+#      ares_expand_name.c
+#      ares_expand_string.c
+#      ares_fds.c
+#      ares_free_hostent.c
+#      ares_free_string.c
+#      ares_getenv.c
+#      ares_gethostbyaddr.c
+#      ares_gethostbyname.c
+#      ares_getnameinfo.c
+#      ares_getsock.c
+#      ares_init.c
+#      ares_library_init.c
+#      ares_llist.c
+#      ares_mkquery.c
+#      ares_create_query.c
+#      ares_nowarn.c
+#      ares_options.c
+#      ares_parse_a_reply.c
+#      ares_parse_aaaa_reply.c
+#      ares_parse_mx_reply.c
+#      ares_parse_naptr_reply.c
+#      ares_parse_ns_reply.c
+#      ares_parse_ptr_reply.c
+#      ares_parse_soa_reply.c
+#      ares_parse_srv_reply.c
+#      ares_parse_txt_reply.c
+#      ares_platform.c
+#      ares_process.c
+#      ares_query.c
+#      ares_search.c
+#      ares_send.c
+#      ares_strcasecmp.c
+#      ares_strdup.c
+#      ares_strerror.c
+#      ares_timeout.c
+#      ares_version.c
+#      ares_writev.c
+#      bitncmp.c
+#      inet_net_pton.c
+#      inet_ntop.c
+#      windows_port.c
+# )
 
 # Build the dynamic/shared library
 IF (CARES_SHARED)
-       ADD_LIBRARY (${PROJECT_NAME} SHARED ${CARES_SOURCES})
+       ADD_LIBRARY (${PROJECT_NAME} SHARED ${CSOURCES})
        SET_TARGET_PROPERTIES (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS 
"-DHAVE_CONFIG_H=1 -DCARES_BUILDING_LIBRARY")
 
        # Convert CARES_LIB_VERSIONINFO libtool version format into VERSION and 
SOVERSION
@@ -560,7 +595,7 @@ ENDIF ()
 
 # Build the static library
 IF (CARES_STATIC)
-       ADD_LIBRARY (${PROJECT_NAME}${STATIC_SUFFIX} STATIC ${CARES_SOURCES})
+       ADD_LIBRARY (${PROJECT_NAME}${STATIC_SUFFIX} STATIC ${CSOURCES})
        SET_TARGET_PROPERTIES (${PROJECT_NAME}${STATIC_SUFFIX} PROPERTIES 
COMPILE_FLAGS "-DHAVE_CONFIG_H=1 -DCARES_STATICLIB" OUTPUT_NAME ${PROJECT_NAME})
        IF (CARES_STATIC_PIC)
                SET_TARGET_PROPERTIES (${PROJECT_NAME}${STATIC_SUFFIX} 
PROPERTIES POSITION_INDEPENDENT_CODE True)
@@ -580,14 +615,14 @@ ENDIF ()
 
 
 # Common sources for all examples
-SET (CARES_EXAMPLE_SOURCES
-       ares_getopt.c
-       ares_nowarn.c
-       ares_strcasecmp.c
-)
+# SET (SAMPLESOURCES
+#      ares_getopt.c
+#      ares_nowarn.c
+#      ares_strcasecmp.c
+# )
 
 # Build ahost
-ADD_EXECUTABLE (ahost ahost.c ${CARES_EXAMPLE_SOURCES})
+ADD_EXECUTABLE (ahost ahost.c ${SAMPLESOURCES})
 SET_TARGET_PROPERTIES(ahost PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H=1 
${CARES_DEFINITIONS}")
 TARGET_LINK_LIBRARIES (ahost ${CARES_LIBRARIES} ${CARES_DEPENDENT_LIBS})
 IF (CARES_INSTALL)
@@ -596,7 +631,7 @@ ENDIF ()
 
 
 # Build adig
-ADD_EXECUTABLE (adig adig.c ${CARES_EXAMPLE_SOURCES})
+ADD_EXECUTABLE (adig adig.c ${SAMPLESOURCES})
 SET_TARGET_PROPERTIES(adig PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H=1 
${CARES_DEFINITIONS}")
 TARGET_LINK_LIBRARIES (adig ${CARES_LIBRARIES} ${CARES_DEPENDENT_LIBS})
 IF (CARES_INSTALL)
@@ -605,7 +640,7 @@ ENDIF ()
 
 
 # Build acountry
-ADD_EXECUTABLE (acountry acountry.c ${CARES_EXAMPLE_SOURCES})
+ADD_EXECUTABLE (acountry acountry.c ${SAMPLESOURCES})
 SET_TARGET_PROPERTIES(acountry PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H=1 
${CARES_DEFINITIONS}")
 TARGET_LINK_LIBRARIES (acountry ${CARES_LIBRARIES} ${CARES_DEPENDENT_LIBS})
 IF (CARES_INSTALL)

Reply via email to