[Cmake] Converting autoconf-project to CMake
Andy Cedilnik
andy . cedilnik at kitware . com
12 Nov 2003 08:26:33 -0500
Hi Bertram,
What you can do is what I did to convert VXL autoconf tests to CMake. It
goes something like this:
You define the following autoconf macros:
AC_DEFUN(CMAKE_STORE_PROCESS_CMAKE_TEST,
___local_var=`cat<<THISISEND | grep "=" | sed "s/^\(.*\)=.*/\1/"
$3
THISISEND
`
LOCALARG3=`cat<<THISISEND | sed "s/\// \/ /g"
$3
THISISEND
`
LOCALARG4=`cat<<THISISEND | sed "s/\// \/ /g"
$4
THISISEND
`
cat>>CMake_from_autoconf.cxx<<THIS_STRING_WILL_NOT_APPEAR_ANYWHERE
#ifdef $___local_var
/* ($LOCALARG3) ($LOCALARG4) ($___local_var) */
$1
int main() { $2;
return 0; }
#endif
THIS_STRING_WILL_NOT_APPEAR_ANYWHERE
echo "PERFORM_CMAKE_TEST("CMake_from_autoconf.cxx" "$___local_var")" >>
CMake_from_autoconf.cmake
)
dnl
AC_DEFUN(CMAKE_AC_TRY_COMPILE,
CMAKE_STORE_PROCESS_CMAKE_TEST($1,$2,$3,$4)
AC_TRY_COMPILE($1,$2,$3,$4)
)
dnl
AC_DEFUN(CMAKE_AC_TRY_LINK,
CMAKE_STORE_PROCESS_CMAKE_TEST($1,$2,$3,$4)
AC_TRY_LINK($1,$2,$3,$4)
)
dnl
AC_DEFUN(CMAKE_AC_CHECK_HEADER, [
___local_var=`cat<<THISISEND | grep "=" | sed "s/^\(.*\)=.*/\1/"
$2
THISISEND
`
echo "PERFORM_CHECK_HEADER("$1" "$___local_var")" >>
CMake_from_autoconf.cmake
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
AC_CHECK_HEADER($1,$2,$3)
AC_LANG_RESTORE
])
Then you replace all try compiles, try links, check header, ... with the
new defined ones. So, then you run autoconf and rerun configure.
Configure will now before performing the test, write the test in the
file CMake_from_autoconf.cxx all the source code for the tests and in
CMake_from_autoconf.cmake the apropriate cmake code. Then all you need
is the CMake macro:
MACRO(PERFORM_CMAKE_TEST FILE TEST)
IF("${TEST}" MATCHES "^${TEST}$")
# Perform test
SET(MACRO_CHECK_FUNCTION_DEFINITIONS
"-D${TEST} ${CMAKE_REQUIRED_FLAGS}")
IF(CMAKE_REQUIRED_LIBRARIES)
SET(TEST_ADD_LIBRARIES
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
ENDIF(CMAKE_REQUIRED_LIBRARIES)
MESSAGE(STATUS "Performing Test ${TEST}")
TRY_COMPILE(${TEST}
${CMAKE_BINARY_DIR}
${vxl_config_SOURCE_DIR}/${FILE}
CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
"${TEST_ADD_LIBRARIES}"
OUTPUT_VARIABLE OUTPUT)
IF(${TEST})
SET(${TEST} 1 CACHE INTERNAL "VXL test ${FUNCTION}")
MESSAGE(STATUS "Performing Test ${TEST} - Success")
ELSE(${TEST})
MESSAGE(STATUS "Performing Test ${TEST} - Failed")
SET(${TEST} 0 CACHE INTERNAL "Test ${FUNCTION}")
WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeError.log
"Performing Test ${TEST} failed with the following output:\n"
"${OUTPUT}\n" APPEND)
ENDIF(${TEST})
ELSE("${TEST}" MATCHES "^${TEST}$")
# Have result
#FOREACH(tst ${TEST})
# MESSAGE("Test ${TEST} resulted in ${${tst}}")
#ENDFOREACH(tst ${TEST})
ENDIF("${TEST}" MATCHES "^${TEST}$")
ENDMACRO(PERFORM_CMAKE_TEST FILE TEST)
And some hand work and you are done.
That said, there is sometimes simpler to just go and handwrite tests. I
did that for Curl, HDF5, Swig, ... and it never took me longer than
couple of hours.
Andy
On Tue, 2003-11-11 at 05:07, Bertram Herzog wrote:
> I was using CMake for Wrapping the offis Oldenburg DICOM Toolkit
> (dicom.offis.de) a while ago to Tcl via CABLE. It turned out that CABLE
> could not handle all that needed to be handled (esp. file-stream factory
> design patterns used to encapsulate the file read/write operations from
> the internal DICOM object layer, probably to have openSSL in between).
> However, I want to try the project again using CSWIG this time.
> But no matter what, it all needs a solid CMake build configuration first
> to get the libraries of DCMTK to get wrapped.
>
> DCMTK uses the Autoconf configuration and build system. Is there an
> "easier" way of converting to CMake taking into account all the
> configuration command line parameters other than "manual re-development"?
>
> I'd be glad to hear a "yes", or "somehow". Otherwise, I'll start digging
> into it.
>
> Thanks a lot,
> Yours Bertram Herzog
>
> P.S.: Thanks for the CMake System, though! I like it really a lot.
> Unfortunately, I wasn't able to buy the book from Germany, yet.