Skip to content

Commit

Permalink
BUILD: Fix up the Automake -> CMake bridge again
Browse files Browse the repository at this point in the history
Now that we're doing a non-recursive automake, the automake file
parser in our CMake scripts needed to be adapted for this as well.

The changes are as follows:
- Don't look in the configure anymore, instead specify the automake
  file to parse directly
- Handle include in the automake file, by recursively parse the
  included files and paste the result into the CMake file
- Don't prepend the full path onto source paths, as source paths are
  already fully path'd now
- Remove the extra src_ at the start of target names
- Since the gitstamp hackery is now in src/version/ instead of
  gitstamp/, we need to make sure its extra automake rule doesn't
  create non-parsable CMake, so we comment it out

The result seems to work, here on GNU/Linux at least.
  • Loading branch information
DrMcCoy committed Oct 16, 2016
1 parent 3d57d6e commit 16df2cc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 36 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ endif(ICONV_SECOND_ARGUMENT_IS_CONST)


# -------------------------------------------------------------------------
# xoreos-tools main targets, parsed from configure.ac and */Makefile.am
include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src)
# xoreos-tools main targets, parsed from the Automake rules.mk files
include_directories(${PROJECT_SOURCE_DIR})
add_definitions(-DPACKAGE_STRING="xoreos-tools ${xoreos-tools_VERSION}")
parse_configure(configure.ac src)
parse_automake(src/rules.mk)
target_link_libraries(gff2xml ${XOREOSTOOLS_LIBRARIES})
target_link_libraries(tlk2xml ${XOREOSTOOLS_LIBRARIES})
target_link_libraries(ssf2xml ${XOREOSTOOLS_LIBRARIES})
Expand Down
73 changes: 40 additions & 33 deletions cmake/CMakeAM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function(am_target_name AM_FOLDER AM_FILE_NAME AM_OUTPUT)
endif()

string(REPLACE "/" "_" AM_TARGET_NAME "${AM_TARGET_NAME}")
string(REGEX REPLACE "^src_" "" AM_TARGET_NAME "${AM_TARGET_NAME}")
set(${AM_OUTPUT} ${AM_TARGET_NAME} PARENT_SCOPE)
endfunction()

Expand All @@ -56,7 +57,7 @@ function(am_add_target AM_TYPE AM_FOLDER AM_FILE AM_SOURCE_FILES AM_LINK_FILES)
set(AM_SOURCES "")
foreach(AM_SOURCE_FILE ${AM_SOURCE_FILES})
if(NOT AM_SOURCE_FILE STREQUAL "$(EMPTY)")
list(APPEND AM_SOURCES ${AM_FOLDER}/${AM_SOURCE_FILE})
list(APPEND AM_SOURCES ${AM_SOURCE_FILE})
endif()
endforeach()

Expand Down Expand Up @@ -84,16 +85,19 @@ function(am_add_target AM_TYPE AM_FOLDER AM_FILE AM_SOURCE_FILES AM_LINK_FILES)
set(${AM_TARGET}_LINK_TARGETS ${AM_LINK_TARGETS} PARENT_SCOPE)
endfunction()

# Internal Automake -> CMake converter, doing the heavy lifting
function(convert_automake_internal AM_INPUT_FILE CMAKE_OUTPUT_FILE)
am_read_lines(${AM_INPUT_FILE} AM_VARIABLE)
foreach(AM_FILE_LINE ${AM_VARIABLE})

function(parse_automake AM_FILE_NAME)
get_filename_component(AM_FOLDER ${AM_FILE_NAME} PATH)
if(NOT EXISTS ${AM_FOLDER})
file(MAKE_DIRECTORY ${AM_FOLDER})
endif()
# Recursively handle include directives
if("${AM_FILE_LINE}" MATCHES "^include ")
string(REGEX REPLACE "^include +" "" AM_INCLUDE_FILE "${AM_FILE_LINE}")
file(APPEND "${CMAKE_OUTPUT_FILE}" "# Including ${AM_INCLUDE_FILE}\n")
convert_automake_internal(${AM_INCLUDE_FILE} ${CMAKE_OUTPUT_FILE})
continue()
endif()

am_read_lines(${AM_FILE_NAME} AM_VARIABLE)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${AM_FILE_NAME}.cmake" "# Autogenerated file, do not edit!\n")
foreach(AM_FILE_LINE ${AM_VARIABLE})
string(REGEX REPLACE " *\\+= *" "+=" AM_FILE_LINE "${AM_FILE_LINE}")
string(REGEX REPLACE " *= *" "=" AM_FILE_LINE "${AM_FILE_LINE}")
string(REGEX REPLACE "^ +" "" AM_FILE_LINE "${AM_FILE_LINE}")
Expand All @@ -111,22 +115,47 @@ function(parse_automake AM_FILE_NAME)
string(REPLACE "#if(" "if(" AM_FILE_LINE "${AM_FILE_LINE}")
string(REPLACE "#endif(" "endif(" AM_FILE_LINE "${AM_FILE_LINE}")

file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/${AM_FILE_NAME}.cmake" "${AM_FILE_LINE}\n")
# Comment out the gitstamp Automake rule hackery
string(REGEX REPLACE "(.*\\$\\([ \t]*eval)" "#\\1" AM_FILE_LINE "${AM_FILE_LINE}")

file(APPEND "${CMAKE_OUTPUT_FILE}" "${AM_FILE_LINE}\n")
endforeach()
include("${CMAKE_CURRENT_BINARY_DIR}/${AM_FILE_NAME}.cmake")
endfunction()

# Create the output file, and start the conversion
function(convert_automake AM_INPUT_FILE CMAKE_OUTPUT_FILE)
file(WRITE "${CMAKE_OUTPUT_FILE}" "# Autogenerated file, do not edit!\n")
convert_automake_internal(${AM_INPUT_FILE} ${CMAKE_OUTPUT_FILE})
endfunction()

function(parse_automake AM_FILE_NAME)
get_filename_component(AM_FOLDER ${AM_FILE_NAME} PATH)
if(NOT EXISTS ${AM_FOLDER})
file(MAKE_DIRECTORY ${AM_FOLDER})
endif()

# Convert this Automake file into a CMake file and include it
set(CMAKE_OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${AM_FILE_NAME}.cmake")
convert_automake(${AM_FILE_NAME} ${CMAKE_OUTPUT_FILE})

include(${CMAKE_OUTPUT_FILE})

# Search for convenience libraries, creating CMake targets
set(AM_TARGETS)
foreach(AM_FILE ${noinst_LTLIBRARIES})
string(REPLACE "." "_" AM_NAME "${AM_FILE}")
string(REPLACE "/" "_" AM_NAME "${AM_NAME}")
am_add_target(lib ${AM_FOLDER} ${AM_FILE} "${${AM_NAME}_SOURCES}" "${${AM_NAME}_LIBADD}")

am_target_name(${AM_FOLDER} ${AM_FILE} AM_TARGET)
set(${AM_TARGET}_LINK_TARGETS ${${AM_TARGET}_LINK_TARGETS} PARENT_SCOPE)
list(APPEND AM_TARGETS ${AM_TARGET})
endforeach()

# Search for programs, creating CMake targets
foreach(AM_FILE ${bin_PROGRAMS})
string(REPLACE "." "_" AM_NAME "${AM_FILE}")
string(REPLACE "/" "_" AM_NAME "${AM_NAME}")
am_add_target(bin ${AM_FOLDER} ${AM_FILE} "${${AM_NAME}_SOURCES}" "${${AM_NAME}_LDADD}")

am_target_name(${AM_FOLDER} ${AM_FILE} AM_TARGET)
Expand All @@ -136,25 +165,3 @@ function(parse_automake AM_FILE_NAME)

set(AM_TARGETS ${AM_TARGETS} PARENT_SCOPE)
endfunction()


function(parse_configure AC_FILE_NAME FOLDER_FILTER)
am_read_lines(${AC_FILE_NAME} CONFIGURE_AC)
set(CONFIGURE_AC_LINE_REGEX "^AC_CONFIG_FILES.*$")
foreach(CONFIGURE_AC_LINE ${CONFIGURE_AC})
if("${CONFIGURE_AC_LINE}" MATCHES "${CONFIGURE_AC_LINE_REGEX}")
string(REGEX MATCHALL "[^[ ]*Makefile" CONFIGURE_AMS "${CONFIGURE_AC_LINE}")

foreach(CONFIGURE_AM ${CONFIGURE_AMS})
if(NOT FOLDER_FILTER OR ${CONFIGURE_AM} MATCHES "${FOLDER_FILTER}/*")
parse_automake(${CONFIGURE_AM}.am)

foreach(AM_TARGET ${AM_TARGETS})
set(${AM_TARGET}_LINK_TARGETS ${${AM_TARGET}_LINK_TARGETS} PARENT_SCOPE)
endforeach()
set(AM_TARGETS ${AM_TARGETS} PARENT_SCOPE)
endif()
endforeach()
endif()
endforeach()
endfunction()

0 comments on commit 16df2cc

Please sign in to comment.