From: <hez...@us...> - 2009-09-21 18:30:20
|
Revision: 10448 http://plplot.svn.sourceforge.net/plplot/?rev=10448&view=rev Author: hezekiahcarty Date: 2009-09-21 18:30:09 +0000 (Mon, 21 Sep 2009) Log Message: ----------- Support systems without ocamlopt; Build examples with ocamlopt when available PLplot's OCaml support will now build if ocamlopt is not present. The ocamlopt compiler is not available for as many OS and architecture combinations as ocamlc. The build-tree examples are now built with ocamlopt when it is available. This produces slightly faster executables, though there isn't much of a difference for most of the examples since most of the execution time for the examples is spent in the C plotting functions. Finally, the native code versions of the OCaml compilers, ocamlc.opt and ocamlopt.opt, are used if they are available. This provides a significant speedup in compilation of the OCaml bindings and examples. Modified Paths: -------------- trunk/bindings/ocaml/CMakeLists.txt trunk/cmake/modules/ocaml.cmake trunk/examples/ocaml/CMakeLists.txt Modified: trunk/bindings/ocaml/CMakeLists.txt =================================================================== --- trunk/bindings/ocaml/CMakeLists.txt 2009-09-21 07:42:59 UTC (rev 10447) +++ trunk/bindings/ocaml/CMakeLists.txt 2009-09-21 18:30:09 UTC (rev 10448) @@ -4,6 +4,7 @@ # # # Copyright (C) 2008 Andrew Ross +# Copyright (C) 2009 Hezekiah M. Carty # # This file is part of PLplot. # @@ -26,7 +27,7 @@ # version of the file should be identical to plplot_h.inc. if(GENERATE_PLPLOT_H_INC) add_custom_command( - OUTPUT + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated_plplot_h.inc COMMAND ${OCAML} ${CMAKE_CURRENT_SOURCE_DIR}/touchup.ml ${CMAKE_CURRENT_SOURCE_DIR}/plplot_h ${CMAKE_CURRENT_BINARY_DIR}/generated_plplot_h.inc DEPENDS @@ -49,10 +50,10 @@ ) add_custom_command( - OUTPUT + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.idl ${camlidl_GENERATED_SOURCE} - # camlidl source file must be in ${CMAKE_CURRENT_BINARY_DIR}. + # camlidl source file must be in ${CMAKE_CURRENT_BINARY_DIR}. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplot_core.idl ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.idl COMMAND ${CAMLIDL} -header -I ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.idl DEPENDS @@ -81,7 +82,7 @@ ) add_custom_command( - OUTPUT + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmi ${CMAKE_CURRENT_BINARY_DIR}/plplot.mli ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmi @@ -98,21 +99,40 @@ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmi ) + # ocamlc add_custom_command( - OUTPUT + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmo + ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml + ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmo + COMMAND ${OCAMLC} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.ml + # ocamlc and ocamlopt *.ml source file must be in + # ${CMAKE_CURRENT_BINARY_DIR}. + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplot.ml ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml + COMMAND ${OCAMLC} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml + DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.ml + ${CMAKE_CURRENT_SOURCE_DIR}/plplot.ml + ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmi + ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmi + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + add_custom_target(target_plplot_core_cmo + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmo + ) + + # ocamlopt + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmx ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.o ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml - ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmo ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmx ${CMAKE_CURRENT_BINARY_DIR}/plplot.o - COMMAND ${OCAMLC} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.ml COMMAND ${OCAMLOPT} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.ml - # ocamlc and ocamlopt *.ml source file must be in + # ocamlc and ocamlopt *.ml source file must be in # ${CMAKE_CURRENT_BINARY_DIR}. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/plplot.ml ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml - COMMAND ${OCAMLC} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml COMMAND ${OCAMLOPT} -c ${CMAKE_CURRENT_BINARY_DIR}/plplot.ml DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.ml @@ -121,41 +141,56 @@ ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmi WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_custom_target(target_plplot_core_cmo - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmo + add_custom_target(target_plplot_core_cmx + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmx ) + # ocamlc add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plplot.cma - ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa - ${CMAKE_CURRENT_BINARY_DIR}/plplot.a COMMAND ${OCAMLC} -a -custom -o ${CMAKE_CURRENT_BINARY_DIR}/plplot.cma ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmo ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmo -dllib -lplplot_stubs -ccopt -L${CMAKE_CURRENT_BINARY_DIR} -cclib -lplplot_stubs -ccopt -L${CAMLIDL_LIB_DIR} -cclib -lcamlidl -ccopt -L${CMAKE_BINARY_DIR}/src -cclib -lplplot${LIB_TAG} -dllpath ${CMAKE_BINARY_DIR}/src - COMMAND ${OCAMLOPT} -a -o ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmx ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmx -ccopt -L${CMAKE_CURRENT_BINARY_DIR} -cclib -lplplot_stubs -ccopt -L${CAMLIDL_LIB_DIR} -cclib -lcamlidl -ccopt -L${CMAKE_BINARY_DIR}/src -cclib -lplplot${LIB_TAG} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmo ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmo - ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmx - ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmx WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) add_custom_target(target_plplot_cma DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plplot.cma + ) + + # ocamlopt + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa + ${CMAKE_CURRENT_BINARY_DIR}/plplot.a + COMMAND ${OCAMLOPT} -a -o ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmx ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmx -ccopt -L${CMAKE_CURRENT_BINARY_DIR} -cclib -lplplot_stubs -ccopt -L${CAMLIDL_LIB_DIR} -cclib -lcamlidl -ccopt -L${CMAKE_BINARY_DIR}/src -cclib -lplplot${LIB_TAG} + DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/plplot_core.cmx + ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmx + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) + add_custom_target(target_plplot_cmxa + DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa + ) # These targets depend on common files in their respective # file-dependency chains. Therefore, to avoid screwing up parallel - # builds must serialize with target depends. + # builds must serialize with target depends. add_dependencies(target_plplot_core_cmi target_lib_plplot_stubs) + # ocamlc add_dependencies(target_plplot_core_cmo target_plplot_core_cmi) add_dependencies(target_plplot_cma target_plplot_core_cmo) + # ocamlopt + add_dependencies(target_plplot_core_cmx target_plplot_core_cmi) + add_dependencies(target_plplot_cmxa target_plplot_core_cmx) # Basic build done, now trying to finish up by adapting bits # and pieces of old build procedure below. - - # Configure the META file + + # Configure the META file # Configure pkg-config *.pc file corresponding to plplot.cma if(PKG_CONFIG_EXECUTABLE) if(LIB_TAG) @@ -169,7 +204,7 @@ # BINDING - ENABLE_${BINDING} keeps track of whether a # binding has been enabled (ON) or not (OFF). # Also, ${BINDING} used to determine PC_FILE_SUFFIX - # which helps to determine name of configured + # which helps to determine name of configured # *.pc file. # PC_SHORT_NAME - Used in *.pc NAME: field # PC_LONG_NAME - Used in *.pc Description: field @@ -201,29 +236,42 @@ endif(PKG_CONFIG_EXECUTABLE) add_custom_target(plplot_ocaml ALL) - add_dependencies(plplot_ocaml target_plplot_cma) + if (OCAMLOPT) + add_dependencies(plplot_ocaml target_plplot_cma target_plplot_cmxa) + else (OCAMLOPT) + add_dependencies(plplot_ocaml target_plplot_cma) + endif (OCAMLOPT) # Need to keep track of file dependencies since this is a custom target. set_property(GLOBAL PROPERTY FILES_plplot_ocaml ${CMAKE_CURRENT_BINARY_DIR}/plplot.cma - ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa - ${CMAKE_CURRENT_BINARY_DIR}/plplot.a ) - + if (OCAMLOPT) + set_property(GLOBAL APPEND PROPERTY FILES_plplot_ocaml + ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa + ${CMAKE_CURRENT_BINARY_DIR}/plplot.a + ) + endif (OCAMLOPT) + set(OCAML_FULL_INSTALL_FILES ${CMAKE_CURRENT_BINARY_DIR}/plplot.cma - ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa - ${CMAKE_CURRENT_BINARY_DIR}/plplot.a ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmi ${CMAKE_CURRENT_BINARY_DIR}/libplplot_stubs.a ${CMAKE_CURRENT_BINARY_DIR}/plplot.mli ) - + if (OCAMLOPT) + set(OCAML_FULL_INSTALL_FILES + ${OCAML_FULL_INSTALL_FILES} + ${CMAKE_CURRENT_BINARY_DIR}/plplot.cmxa + ${CMAKE_CURRENT_BINARY_DIR}/plplot.a + ) + endif (OCAMLOPT) + # Most files go in the plplot subdirectory install(FILES ${OCAML_FULL_INSTALL_FILES} ${CMAKE_CURRENT_BINARY_DIR}/META DESTINATION ${OCAML_INSTALL_DIR}/plplot ) - + # Shared library stubs go in stublibs install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/dllplplot_stubs.so DESTINATION ${OCAML_INSTALL_DIR}/stublibs Modified: trunk/cmake/modules/ocaml.cmake =================================================================== --- trunk/cmake/modules/ocaml.cmake 2009-09-21 07:42:59 UTC (rev 10447) +++ trunk/cmake/modules/ocaml.cmake 2009-09-21 18:30:09 UTC (rev 10448) @@ -1,6 +1,7 @@ # cmake/modules/ocaml.cmake # # Copyright (C) 2008 Andrew Ross +# Copyright (C) 2009 Hezekiah M. Carty # # This file is part of PLplot. # @@ -32,7 +33,7 @@ endif(ENABLE_ocaml AND NOT BUILD_SHARED_LIBS) if(ENABLE_ocaml) - find_program(OCAMLC ocamlc) + find_program(OCAMLC NAMES ocamlc.opt ocamlc) if (OCAMLC) message(STATUS "OCAMLC = ${OCAMLC}") else (OCAMLC) @@ -65,13 +66,12 @@ endif(ENABLE_ocaml) if(ENABLE_ocaml) - find_program(OCAMLOPT ocamlopt) + find_program(OCAMLOPT NAMES ocamlopt.opt ocamlopt) if (OCAMLOPT) message(STATUS "OCAMLOPT = ${OCAMLOPT}") else (OCAMLOPT) message(STATUS "WARNING:" - "ocamlopt not found. Disabling ocaml bindings") - set(ENABLE_ocaml OFF CACHE BOOL "Enable OCaml bindings" FORCE) + "ocamlopt not found. Disabling native code OCaml bindings") endif (OCAMLOPT) endif(ENABLE_ocaml) @@ -93,7 +93,7 @@ "camlidl library not found. Disabling ocaml bindings") set(ENABLE_ocaml OFF CACHE BOOL "Enable OCaml bindings" FORCE) endif(CAMLIDL_LIB_DIR) - + # Installation follows the Debian ocaml policy for want of a better # standard. set(OCAML_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib/ocaml/${OCAML_VERSION} @@ -141,6 +141,6 @@ "One or all of topfind, unix, or pcre components of ocaml are not installed. Disabling generation of generated_plplot_h.inc") set(GENERATE_PLPLOT_H_INC OFF CACHE BOOL "Generate generated_plplot_h.inc" FORCE) endif(output OR error) - + endif(GENERATE_PLPLOT_H_INC) endif(ENABLE_ocaml) Modified: trunk/examples/ocaml/CMakeLists.txt =================================================================== --- trunk/examples/ocaml/CMakeLists.txt 2009-09-21 07:42:59 UTC (rev 10447) +++ trunk/examples/ocaml/CMakeLists.txt 2009-09-21 18:30:09 UTC (rev 10448) @@ -5,6 +5,7 @@ # # Copyright (C) 2008 Andrew Ross # Copyright (C) 2009 Alan W. Irwin +# Copyright (C) 2009 Hezekiah M. Carty # # This file is part of PLplot. # @@ -89,6 +90,17 @@ endif(CORE_BUILD) if(BUILD_TEST) + # Default to using ocaml if ocamlopt is not available. Make sure the proper + # files are cleaned up after a build, depending on the compiler used. + set(ocaml_lib_extension cma) + set(ocaml_cleanup_extensions cmo cmi) + set(ocaml_compiler ${OCAMLC}) + if (OCAMLOPT) + set(ocaml_lib_extension cmxa) + set(ocaml_cleanup_extensions cmx cmi o) + set(ocaml_compiler ${OCAMLOPT}) + endif (OCAMLOPT) + set(ocaml_EXTRA_CLEAN_FILES) if(CORE_BUILD) set(I_OPTION ${CMAKE_BINARY_DIR}/bindings/ocaml) @@ -104,11 +116,13 @@ foreach(STRING_INDEX ${ocaml_STRING_INDICES}) set(EXECUTABLE_NAME x${STRING_INDEX}ocaml) set(SOURCE_FILE x${STRING_INDEX}.ml) - set(ocaml_EXTRA_CLEAN_FILES ${ocaml_EXTRA_CLEAN_FILES} x${STRING_INDEX}.cmo x${STRING_INDEX}.cmi) - # Copy source code to build tree since ocamlc is a bit broken and will + foreach(EXTENSION ${ocaml_cleanup_extensions}) + set(ocaml_EXTRA_CLEAN_FILES ${ocaml_EXTRA_CLEAN_FILES} x${STRING_INDEX}.${EXTENSION}) + endforeach(EXTENSION ocaml_cleanup_extensions) + # Copy source code to build tree since ocamlc is a bit broken and will # otherwise litter the source tree with intermediate files if(STRING_INDEX STREQUAL "17") - set(unix_bytecode_lib unix.cma) + set(unix_bytecode_lib unix.${ocaml_lib_extension}) else(STRING_INDEX STREQUAL "17") set(unix_bytecode_lib) endif(STRING_INDEX STREQUAL "17") @@ -121,13 +135,13 @@ ) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE_NAME} - COMMAND ${OCAMLC} + COMMAND ${ocaml_compiler} -g -I ${I_OPTION} -ccopt ${ccopt_OPTION} - plplot.cma + plplot.${ocaml_lib_extension} ${unix_bytecode_lib} - -o ${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE_NAME} + -o ${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_FILE} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_FILE} @@ -136,7 +150,7 @@ VERBATIM ) add_custom_target( - target_${EXECUTABLE_NAME} ALL + target_${EXECUTABLE_NAME} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE_NAME} ) if(CORE_BUILD) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |