diff --git a/C/text.c b/C/text.c index 003a1eed4..894682e72 100644 --- a/C/text.c +++ b/C/text.c @@ -77,6 +77,29 @@ int pop_text_stack__(int i) { return lvl; } +void *pop_output_text_stack__(int i, void *export) { + int lvl = LOCAL_TextBuffer->lvl; + while (lvl >= i) { + struct mblock *p = LOCAL_TextBuffer->first[lvl]; + while (p) { + struct mblock *np = p->next; + if (p+1 == export) { + size_t sz = p->sz; + memcpy(p, p+1, sz); + export = p; + } else { + free(p); + } + p = np; + } + LOCAL_TextBuffer->first[lvl] = NULL; + LOCAL_TextBuffer->last[lvl] = NULL; + lvl--; + } + LOCAL_TextBuffer->lvl = lvl; + return export; +} + // void pop_text_stack(int i) { LOCAL_TextBuffer->lvl = i; } void insert_block(struct mblock *o) { int lvl = o->lvl; @@ -145,12 +168,6 @@ void *MallocAtLevel(size_t sz, int atL USES_REGS) { return o + 1; } -void *export_block( void *protected) { - struct mblock *o = ((struct mblock *)protected) - 1; - release_block(o); - memcpy(o, protected, o->sz); - return o; -} void *Realloc(void *pt, size_t sz USES_REGS) { sz += sizeof(struct mblock); struct mblock *old = pt, *o; @@ -198,9 +215,8 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) { size_t length = 0; if (t == TermNil) { - st0 = Malloc(4); + st0 = malloc(4); st0[0] = 0; - st0 = export_block( st0); return st0; } if (!IsPairTerm(t)) @@ -252,8 +268,7 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) { } } - st0 = st = Malloc(length + 1); - export_block(st0); + st0 = st = malloc(length + 1); t = t0; if (codes) { while (IsPairTerm(t)) { diff --git a/CMakeLists.txt b/CMakeLists.txt index be051ff39..4c544f914 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,12 +57,607 @@ option(BUILD_SHARED_LIBS "Build shared library" ON) set (CMAKE_POSITION_INDEPENDENT_CODE TRUE) set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) -include(Prelims NO_POLICY_SCOPE) +#begining stuff for top CMakeLists -include(Sources NO_POLICY_SCOPE) +include (MacroLogFeature) -include(Model NO_POLICY_SCOPE) +if (POLICY CMP0042) + cmake_policy( SET CMP0042 NEW) +endif() +function(add_to_group list output) + set (tmp ${${output}}) + foreach (path ${${list}}) + get_source_file_property(path ${path} LOCATION) + list( APPEND tmp ${path}) + endforeach () + set (${output} ${tmp} CACHE INTERNAL "prolog library files") +endfunction(add_to_group list output ) + +function(add_to_libgroup el list) + add_custom_command( TARGET ${el} POST_BUILD +COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py + DEPENDS ${el} ) + list( APPEND ${list} ${${el}}) + set (${list} ${${list}} CACHE INTERNAL "prolog dll files") +endfunction(add_to_libgroup el list ) + + +function(add_to_corelibgroup el list) + add_custom_command( TARGET ${el} POST_BUILD +COMMAND ${CMAKE_COMMAND} -E copy $ $ $ ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py + DEPENDS ${el} ) + list( APPEND ${list} ${${el}}) + set (${list} ${${list}} CACHE INTERNAL "prolog dll files") +endfunction(add_to_corelibgroup el list ) + + +if (ANDROID_OLD) + macro ( MY_add_custom_target) + endmacro() +else() + macro ( MY_add_custom_target ) + add_custom_target (${ARGN}) + endmacro() +endif() + +if (WIN32) + macro ( add_component arg1 ) + add_library ( ${arg1} OBJECT ${ARGN}) + endmacro() +else() + macro ( add_component arg1 ) + add_library ( ${arg1} OBJECT ${ARGN}) + endmacro() +endif() +macro ( add_lib arg1 ) + add_library ( ${arg1} SHARED ${ARGN}) + add_to_libgroup( ${arg1} YAP_DLLS ) +endmacro() +macro ( add_corelib arg1 ) + add_library ( ${arg1} SHARED ${ARGN}) + add_to_corelibgroup( ${arg1} YAP_DLLS ) +endmacro() + +if (ANDROID_OLD) + macro ( MY_add_dependencies) + endmacro() +else() + macro ( MY_add_dependencies ) + add_dependencies (${ARGN}) + endmacro() +endif() + +if (ANDROID_OLD) + macro ( MY_add_library) + endmacro() +else() + macro ( MY_add_library ) + add_library (${ARGN}) + endmacro() +endif() + +if (ANDROID) + macro ( MY_add_subdirectory) + endmacro() +else() + macro ( MY_add_subdirectory ) + add_subdirectory (${ARGN}) + endmacro() +endif() + +if (ANDROID_OLD) + macro ( MY_include) + endmacro() +else() + macro ( MY_include ) + include (${ARGN}) + endmacro() +endif() + +if (ANDROID) + macro ( MY_install) + endmacro() +else() + macro ( MY_install ) + install (${ARGN}) + endmacro() +endif() + +if (ANDROID_OLD) + macro ( MY_set_target_properties) + endmacro() +else() + macro ( MY_set_target_properties ) + set_target_properties (${ARGN}) + endmacro() +endif() + +if (ANDROID_OLD) + macro ( MY_target_link_libraries) + endmacro() +else() + macro ( MY_target_link_libraries ) + target_link_libraries (${ARGN}) + endmacro() +endif() + + +# where we have most scripts +# set path to additional CMake modules + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +include(disallow) + +disallow_intree_builds() + +# set(CMAKE_BUILD_TYPE Debug) + +if (APPLE) + set (MACOSX_RPATH ON) +endif (APPLE ) +if(POLICY CMP0042) + cmake_policy(SET CMP0042 NEW) +endif(POLICY CMP0042) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 NEW) +endif(POLICY CMP0043) + + +if (ANDROID) + set ( prefix ${YAP_APP_DIR}/build ) + set ( datarootdir ${prefix}/assets ) +else() +set ( prefix "${CMAKE_INSTALL_PREFIX}") + set ( datarootdir ${prefix}/share ) +endif() + set ( libpl ${datarootdir}/Yap) +set ( includedir "${prefix}/include") +set ( exec_prefix "${prefix}") +set ( libdir "${exec_prefix}/lib") +set ( datadir "${datarootdir}") +set ( mandir "${datarootdir}/man") +set ( bindir "${exec_prefix}/bin") +set ( docdir "${datarootdir}/doc/Yap") +set ( dlls "${exec_prefix}/lib/Yap") + +set(YAP_ROOTDIR ${prefix}) + +# erootdir -> rootdir +# bindir defined above +# libdir defined above +set(YAP_LIBDIR "${dlls}") +set(YAP_SHAREDIR "${datarootdir}") +set(YAP_BINDIR "${bindir}") +set(YAP_INCLUDEDIR "${includedir}") +set(YAP_ROOTDIR "${prefix}") + +# +# +# include( Sources NO_POLICY_SCOPE ) +# +# include( Model NO_POLICY_SCOPE ) + +include (cudd NO-POLICY-SCOPE) +include (java NO-POLICY-SCOPE) + +set (pl_library "" CACHE INTERNAL "prolog library files" ) +set (pl_os_library "" CACHE INTERNAL "prolog os files" ) +set (pl_boot_library "" CACHE INTERNAL "prolog boot files" ) + +# +# Sources Section +# + + +set (ABSMI_SOURCES + C/absmi.c + C/absmi_insts.h + C/fli_absmi_insts.h + C/or_absmi_insts.h + C/control_absmi_insts.h + C/index_absmi_insts.h + C/prim_absmi_insts.h + C/cp_absmi_insts.h + C/lu_absmi_insts.h + C/unify_absmi_insts.h + C/fail_absmi_insts.h + C/meta_absmi_insts.h + ) + +set (ENGINE_SOURCES + ${ABSMI_SOURCES} + C/agc.c + C/adtdefs.c + C/alloc.c + C/amasm.c + C/analyst.c + C/args.c + C/arrays.c + C/arith0.c + C/arith1.c + C/arith2.c + C/atomic.c + C/attvar.c + C/bignum.c + C/bb.c + C/blobs.c + C/cdmgr.c + C/cmppreds.c + C/compiler.c + C/computils.c + C/corout.c + C/cut_c.c + C/dbase.c + C/dlmalloc.c + C/errors.c + C/eval.c + C/exec.c + C/exo.c + C/exo_udi.c + C/flags.c + C/globals.c + C/gmp_support.c + C/gprof.c + C/grow.c + C/heapgc.c + C/index.c + C/init.c + C/inlines.c + C/depth_bound.c + C/mavar.c + C/modules.c + C/other.c + C/parser.c + C/qlyr.c + C/qlyw.c + C/range.c + C/save.c + C/scanner.c + C/signals.c + C/sort.c + C/stdpreds.c + C/stack.c + C/text.c + C/threads.c + C/tracer.c + C/unify.c + C/userpreds.c + C/utilpreds.c + C/yap-args.c + C/write.c + C/udi.c + #packages/udi/rtree.c + #packages/udi/rtree_udi.c + + # ${IOLIB_SOURCES} + # MPI_SOURCES + ) + +set(C_INTERFACE_SOURCES + ${PROJECT_BINARY_DIR}/GitSHA1.c + C/load_foreign.c + C/load_dl.c + C/load_dld.c + C/load_dyld.c + C/load_none.c + C/load_aout.c + C/load_aix.c + C/load_dll.c + C/load_shl.c + C/c_interface.c + C/clause_list.c + ) + + + find_package (GMP) + # GMP_FOUND - true if GMP/MPIR was found + # GMP_INCLUDE_DIRS - include search path + # GMP_LIBRARIES - libraries to link with + # GMP_LIBRARY_ #add_executable(test ${SOURCES}) + + list(APPEND YAP_SYSTEM_OPTIONS big_numbers) + +list(APPEND LIBYAP_SOURCES ${C_INTERFACE_SOURCES} ${ENGINE_SOURCES}) + +set( BEAM_HEADERS +BEAM/beam.h +) + set (CORE_HEADERS + ${CMAKE_SOURCE_DIR}/H/Atoms.h + ${CMAKE_SOURCE_DIR}/H/Foreign.h + ${CMAKE_SOURCE_DIR}/H/Regs.h + ${CMAKE_SOURCE_DIR}/H/ScannerTypes.h + ${CMAKE_SOURCE_DIR}/H/Tags_24bits.h + ${CMAKE_SOURCE_DIR}/H/Tags_32LowTag.h + ${CMAKE_SOURCE_DIR}/H/Tags_32Ops.h + ${CMAKE_SOURCE_DIR}/H/Tags_32bits.h + ${CMAKE_SOURCE_DIR}/H/Tags_64bits.h + ${CMAKE_SOURCE_DIR}/H/TermExt.h + ${CMAKE_SOURCE_DIR}/H/Yap.h + ${CMAKE_SOURCE_DIR}/H/YapAppliedOpcodes.h + ${CMAKE_SOURCE_DIR}/H/YapCompile.h + ${CMAKE_SOURCE_DIR}/H/YapCompoundTerm.h + ${CMAKE_SOURCE_DIR}/H/YapEval.h + ${CMAKE_SOURCE_DIR}/H/YapFlags.h + ${CMAKE_SOURCE_DIR}/H/YapGFlagInfo.h + ${CMAKE_SOURCE_DIR}/H/YapHandles.h + ${CMAKE_SOURCE_DIR}/H/YapHeap.h + ${CMAKE_SOURCE_DIR}/H/YapLFlagInfo.h + ${CMAKE_SOURCE_DIR}/H/YapOpcodes.h + ${CMAKE_SOURCE_DIR}/H/YapSignals.h + ${CMAKE_SOURCE_DIR}/H/YapTags.h + ${CMAKE_SOURCE_DIR}/H/YapTerm.h + ${CMAKE_SOURCE_DIR}/H/YapText.h + ${CMAKE_SOURCE_DIR}/H/Yapproto.h + ${CMAKE_SOURCE_DIR}/H/Yatom.h + ${CMAKE_SOURCE_DIR}/H/absmi-interpretrer.h + ${CMAKE_SOURCE_DIR}/H/absmi-switch.h + ${CMAKE_SOURCE_DIR}/H/absmi-threaded.h + ${CMAKE_SOURCE_DIR}/H/absmi-traced.h + ${CMAKE_SOURCE_DIR}/H/absmi.h + ${CMAKE_SOURCE_DIR}/H/alloc.h + ${CMAKE_SOURCE_DIR}/H/amidefs.h + ${CMAKE_SOURCE_DIR}/H/amijit.h + ${CMAKE_SOURCE_DIR}/H/amiops.h + ${CMAKE_SOURCE_DIR}/H/arith2.h + ${CMAKE_SOURCE_DIR}/H/arrays.h + ${CMAKE_SOURCE_DIR}/H/attvar.h + ${CMAKE_SOURCE_DIR}/H/clause.h + ${CMAKE_SOURCE_DIR}/H/corout.h + ${CMAKE_SOURCE_DIR}/H/cut_c.h + ${CMAKE_SOURCE_DIR}/H/dlmalloc.h + ${CMAKE_SOURCE_DIR}/H/fields.h + ${CMAKE_SOURCE_DIR}/H/findclause.h + ${CMAKE_SOURCE_DIR}/H/generated/dglobals.h + ${CMAKE_SOURCE_DIR}/H/generated/dhstruct.h + ${CMAKE_SOURCE_DIR}/H/generated/h0globals.h + ${CMAKE_SOURCE_DIR}/H/generated/h0struct.h + ${CMAKE_SOURCE_DIR}/H/generated/hglobals.h + ${CMAKE_SOURCE_DIR}/H/generated/hlocals.h + ${CMAKE_SOURCE_DIR}/H/generated/hstruct.h + ${CMAKE_SOURCE_DIR}/H/generated/i0globals.h + ${CMAKE_SOURCE_DIR}/H/generated/iatoms.h + ${CMAKE_SOURCE_DIR}/H/generated/iglobals.h + ${CMAKE_SOURCE_DIR}/H/generated/ihstruct.h + ${CMAKE_SOURCE_DIR}/H/generated/ilocals.h + ${CMAKE_SOURCE_DIR}/H/generated/ratoms.h + ${CMAKE_SOURCE_DIR}/H/generated/rglobals.h + ${CMAKE_SOURCE_DIR}/H/generated/rhstruct.h + ${CMAKE_SOURCE_DIR}/H/generated/rlocals.h + ${CMAKE_SOURCE_DIR}/H/generated/tatoms.h + ${CMAKE_SOURCE_DIR}/H/globals.h + ${CMAKE_SOURCE_DIR}/H/headclause.h + ${CMAKE_SOURCE_DIR}/H/heap.h + ${CMAKE_SOURCE_DIR}/H/heapgc.h + ${CMAKE_SOURCE_DIR}/H/index.h + ${CMAKE_SOURCE_DIR}/H/inline-only.h + ${CMAKE_SOURCE_DIR}/H/iswiatoms.h + ${CMAKE_SOURCE_DIR}/H/locals.h + ${CMAKE_SOURCE_DIR}/H/nolocks.h + ${CMAKE_SOURCE_DIR}/H/qly.h + ${CMAKE_SOURCE_DIR}/H/rclause.h + ${CMAKE_SOURCE_DIR}/H/rheap.h + ${CMAKE_SOURCE_DIR}/H/saveclause.h + ${CMAKE_SOURCE_DIR}/H/sig.h + ${CMAKE_SOURCE_DIR}/H/sshift.h + ${CMAKE_SOURCE_DIR}/H/threads.h + ${CMAKE_SOURCE_DIR}/H/tracer.h + ${CMAKE_SOURCE_DIR}/H/trim_trail.h + ${CMAKE_SOURCE_DIR}/H/udi_private.h + ${CMAKE_SOURCE_DIR}/H/utarray.h + ${CMAKE_SOURCE_DIR}/H/uthash.h + ${CMAKE_SOURCE_DIR}/H/walkclause.h + ${CMAKE_SOURCE_DIR}/H/yerror.h + ) + +set (INCLUDE_HEADERS + ${CMAKE_SOURCE_DIR}/include/GitSHA1.h + ${CMAKE_SOURCE_DIR}/include/SWI-Prolog.h + ${CMAKE_SOURCE_DIR}/include/VFS.h + ${CMAKE_SOURCE_DIR}/include/YapDefs.h + ${CMAKE_SOURCE_DIR}/include/YapError.h + ${CMAKE_SOURCE_DIR}/include/YapErrors.h + ${CMAKE_SOURCE_DIR}/include/YapFormat.h + ${CMAKE_SOURCE_DIR}/include/YapInterface.h + ${CMAKE_SOURCE_DIR}/include/YapRegs.h + ${CMAKE_SOURCE_DIR}/include/YapStreams.h + ${CMAKE_SOURCE_DIR}/include/blobs.h + ${CMAKE_SOURCE_DIR}/include/c_interface.h + ${CMAKE_SOURCE_DIR}/include/clause_list.h + ${CMAKE_SOURCE_DIR}/include/pl-types.h + ${CMAKE_SOURCE_DIR}/include/udi.h +) + +set (CONFIGURATION_HEADERS +${CMAKE_BINARY_DIR}/YapConfig.h + ${CMAKE_BINARY_DIR}/YapTermConfig.h + ${CMAKE_BINARY_DIR}/config.h + ${CMAKE_BINARY_DIR}/cudd_config.h + ${CMAKE_BINARY_DIR}/dlocals.h + ${CMAKE_BINARY_DIR}/YapIOConfig.h +) + + +set (CXX_HEADERS + ${CMAKE_SOURCE_DIR}/CXX/yapa.hh + ${CMAKE_SOURCE_DIR}/CXX/yapdb.hh + ${CMAKE_SOURCE_DIR}/CXX/yapi.hh + ${CMAKE_SOURCE_DIR}/CXX/yapie.hh + ${CMAKE_SOURCE_DIR}/CXX/yapq.hh + ${CMAKE_SOURCE_DIR}/CXX/yapt.hh + +) +set (PYTHON_HEADERS ${CMAKE_SOURCE_DIR}/packages/python/py4yap.h) + +set (OPTYap_HEADERS + ${CMAKE_SOURCE_DIR}/OPTYap/opt.config.h + ${CMAKE_SOURCE_DIR}/OPTYap/opt.proto.h + ${CMAKE_SOURCE_DIR}/OPTYap/opt.structs.h + ${CMAKE_SOURCE_DIR}/OPTYap/opt.macros.h + ${CMAKE_SOURCE_DIR}/OPTYap/or.macros.h + ${CMAKE_SOURCE_DIR}/OPTYap/or.sba_amiops.h + ${CMAKE_SOURCE_DIR}/OPTYap/or.sba_unify.h + ${CMAKE_SOURCE_DIR}/OPTYap/tab.structs.h + ${CMAKE_SOURCE_DIR}/OPTYap/locks_x86.h + ${CMAKE_SOURCE_DIR}/OPTYap/locks_sparc.h + ${CMAKE_SOURCE_DIR}/OPTYap/locks_mips.h + ${CMAKE_SOURCE_DIR}/OPTYap/locks_mips_funcs.h + ${CMAKE_SOURCE_DIR}/OPTYap/locks_alpha.h + ${CMAKE_SOURCE_DIR}/OPTYap/locks_alpha_funcs.h + ${CMAKE_SOURCE_DIR}/OPTYap/locks_pthread.h + + ) + +set (YAPOS_HEADERS + ${CMAKE_SOURCE_DIR}/os/encoding.h + ${CMAKE_SOURCE_DIR}/os/fmemopen.h + ${CMAKE_SOURCE_DIR}/os/format.h + ${CMAKE_SOURCE_DIR}/os/getw.h + ${CMAKE_SOURCE_DIR}/os/iopreds.h + ${CMAKE_SOURCE_DIR}/os/sysbits.h + ${CMAKE_SOURCE_DIR}/os/yapio.h +) + +list( APPEND c_headers ${CMAKE_SOURCE_DIR}/utf8proc/utf8proc.h ) +list( APPEND c_headers ${YAPOS_HEADERS} ) +list( APPEND c_headers ${OPTYap_HEADERS} ) +list( APPEND c_headers ${INCLUDE_HEADERS} ) +list( APPEND c_headers ${CORE_HEADERS} ) +list (APPEND c_headers ${PYTHON_HEADERS}) +#list( APPEND c_headers ${CONFIGURATION_HEADERS} ) +list( APPEND cxx_headers ${CXX_HEADERS} ) + + +set(STATIC_SOURCES + #NOT INCLUDED FOR NOW + ) + +set(CONSOLE_SOURCES +console/yap.c) + +#MPI STUFF +# library/mpi/mpi.c library/mpi/mpe.c +# library/lammpi/yap_mpi.c library/lammpi/hash.c library/lammpi/prologterms2c.c +# ) + +#WIN STUFF +# SET(PLCONS_SOURCES +# console/LGPL/pl-nt.c +# console/LGPL/pl-ntcon.c +# console/LGPL/pl-ntconsole.c +# console/LGPL/pl-ntmain.c +# ) +set(YAP_FOUND ON) + +set(YAP_MAJOR_VERSION 6) +set(YAP_MINOR_VERSION 3) +set(YAP_PATCH_VERSION 5) + +set(YAP_FULL_VERSION + ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION}.${YAP_PATCH_VERSION}) +set(YAP_FVERSION + ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION}.${YAP_PATCH_VERSION}) +set(YAP_NUMERIC_VERSION + ${YAP_MAJOR_VERSION}*10000+${YAP_MINOR_VERSION}*100+${YAP_PATCH_VERSION}) +set(MYDDAS_VERSION MYDDAS-0.9.1) + +site_name( YAP_SITE ) + + +if (WIN32) + set (YAP_ARCH $ENV{PROCESSOR_ARCHITECTURE}) + set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "MS_WIN64=1" ) + set(YAP_SYSTEM_OPTIONS "windows " ${YAP_SYSTEM_OPTIONS}) +endif() +if (UNIX) + find_program (UNAME uname) + execute_process ( + COMMAND ${UNAME} -m + OUTPUT_VARIABLE YAP_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE ) + set(YAP_SYSTEM_OPTIONS "unix " ${YAP_SYSTEM_OPTIONS}) +endif() + + +# +set ( MIN_STACKSPACE 1024*SIZEOF_INT_P ) +set ( MIN_HEAPSPACE 32*1024*SIZEOF_INT_P ) +set ( MIN_TRAILSPACE 512*SIZEOF_INT_P ) +set ( DEF_STACKSPACE 0 ) +set ( DEF_HEAPSPACE 0 ) +set ( DEF_TRAILSPACE 0 ) + +# option (RATIONAL_TREES "support infinite rational trees" ON) +# dd_definitions (-D) + +## don't touch these opts + set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS DEPTH_LIMIT=1;COROUTINING=1;RATIONAL_TREES=1 ) + +# inform we are compiling YAP + set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_YAP_NOT_INSTALLED_=1;HAVE_CONFIG_H=1;_GNU_SOURCE" ) + +# Compilation model +# target_compile_definitions(libYap PUBLIC _XOPEN_SOURCE=700 ) + +#add_definitions( -Wall -Wstrict-prototypes -Wmissing-prototypes) + +# Model Specific + set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$:DEBUG=1> ) + +#ensure cells are properly aligned in code +set (ALIGN_LONGS 1) + +#ensure best access to slots in environments +set (MSHIFTOFFS 1) + +set (C_COMPILER CMAKE_C_COMPILER_ID) + +if ( ${C_COMPILER} MATCHES "GNU") + set (HAVE_GCC 1) +endif() + +# compatible compilers +if ( ${C_COMPILER} MATCHES "Clang") + set (HAVE_GCC 1) +endif() + +if ( ${C_COMPILER} MATCHES "Intel") + set (HAVE_GCC 1) +endif() + +# Model Specific +if (HAVE_GCC) + set_property( DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -Wall ) +if ( ${C_COMPILER} MATCHES "GNU") + set_property( DIRECTORY APPEND PROPERTY COMPILE_OPTIONS $<$:-O3;-fomit-frame-pointer;-fstrict-aliasing;-freorder-blocks;-fsched-interblock> ) +else() + set_property( DIRECTORY APPEND PROPERTY COMPILE_OPTIONS $<$:-O3;-fstrict-aliasing;-freorder-blocks;-fsched-interblock> ) +endif() + set_property( DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -fexceptions ) +endif() + +# set_property( DIRECTORY APPEND_STRING PROPERTY -fsanitize=memory;-fsanitize-memory-track-origins=2) +if (HAVE_GCC) + # replace instructions codes by the address of their code + option (WITH_THREADED_CODE "threaded code" ON) + if (WITH_THREADED_CODE) + set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS THREADED_CODE=1) + endif (WITH_THREADED_CODE) +endif (HAVE_GCC) + +# +#option (YAP_SWI_IO ON) + +OPTION (WITH_CALL_TRACER +"support for procedure-call tracing" ON) +#TODO: +if (WITH_CALL_TRACER) + list (APPEND YAP_SYSTEM_OPTIONS "call_tracer " ${YAP_SYSTEM_OPTIONS}) +set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$:LOW_LEVEL_TRACER=1> ) +endif (WITH_CALL_TRACER) + +set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS UTF8PROC=1) include_directories ( utf8proc packages/myddas packages/myddas/sqlite3/src) @@ -124,7 +719,7 @@ ENDIF (WITH_PYTHON) -add_lib( # Sets the name of the library. +add_corelib( # Sets the name of the library. libYap # Sets the library as a shared library. @@ -144,11 +739,102 @@ if (WIN32) endif() endif (WIN32) -include(libYap NO_POLICY_SCOPE) -if (USE_READLINE) - target_link_libraries(libYap ${READLINE_LIBRARIES}) -endif (USE_READLINE) + if (GMP_FOUND) + #config.h needs this (TODO: change in code latter) + include_directories( ${GMP_INCLUDE_DIRS} ) + target_link_libraries(libYap ${GMP_LIBRARIES} ) + endif (GMP_FOUND) + + + +include (Sources) + +set(YAP_STARTUP startup.yss) +## define system + + # Optional libraries that affect compilation + # + + +set(CMAKE_TOP_BINARY_DIR ${CMAKE_BINARY_DIR}) +set(YAP_PL_SRCDIR ${CMAKE_SOURCE_DIR}/pl) + +set(YAP_YAPLIB libYap${CMAKE_SHARED_LIBRARY_SUFFIX}) + +string(TIMESTAMP YAP_TIMESTAMP) + +string( SUBSTRING ${CMAKE_SHARED_LIBRARY_SUFFIX} 1 -1 SO_EXT ) + +set_property(DIRECTORY PROPERTY CXX_STANDARD 11) + +# rpath stuff, hopefully it works + +# use, i.e. don't skip the full RPATH for the build tree +SET(CMAKE_SKIP_BUILD_RPATH FALSE) + +# when building, don't use the install RPATH already +# (but later on when installing) +SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + +SET(CMAKE_INSTALL_RPATH "${libdir};${dlls}:") + +# add the automatically determined parts of the RPATH +# which point to directories outside the build tree to the install RPATH +SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + +set_target_properties(libYap + PROPERTIES OUTPUT_NAME Yap + ) + MY_set_target_properties(libYap + PROPERTIES VERSION ${YAP_FULL_VERSION} + SOVERSION ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION} + ) + +# the RPATH to be used when installing, but only if it's not a system directory +LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${libdir};${dlls}" isSystemDir) +IF("${isSystemDir}" STREQUAL "-1") + SET(CMAKE_INSTALL_RPATH "${libdir};${dlls}") +ENDIF("${isSystemDir}" STREQUAL "-1") + + +include_directories (H + H/generated + include os OPTYap utf8proc JIT/HPP) +include_directories (BEFORE ${CMAKE_BINARY_DIR} ${CMAKE_TOP_BINARY_DIR}) + +if (ANDROID) +include_directories (CXX ${CMAKE_SOURCE_DIR}/../generated/src/jni) +endif() +include( Threads ) +# +# include OS and I/o stuff +# +# convenience libraries +# OPTYap exports important flags +# +list(APPEND YAP_SYSTEM_OPTIONS "thread support") + +#utf-8 is not an option +# we use the nice UTF-8 package +#available at the Julia project + + ADD_SUBDIRECTORY ( OPTYap ) + ADD_SUBDIRECTORY ( os ) +ADD_SUBDIRECTORY ( packages/myddas ) +ADD_SUBDIRECTORY ( utf8proc ) +ADD_SUBDIRECTORY ( library/dialect/swi/fli ) +ADD_SUBDIRECTORY ( CXX ) + + +add_subDIRECTORY ( H ) + +#bootstrap and saved state +add_subDIRECTORY ( pl ) + +ADD_SUBDIRECTORY( library) + +ADD_SUBDIRECTORY( swi/library "swiLibrary" ) if (ANDROID) target_link_libraries(libYap android log) @@ -159,9 +845,6 @@ set_target_properties(libYap PROPERTIES OUTPUT_NAME Yap ) -MY_include(Packages NO_POLICY_SCOPE) - - if (PYTHONLIBS_FOUND AND SWIG_FOUND) add_subdirectory(packages/python/swig) @@ -179,8 +862,216 @@ IF (SWIG_FOUND OR ANDROID) add_subDIRECTORY (packages/swig NO_POLICY_SCOPE) ENDIF() + +message(STATUS "Building YAP packages version ${YAP_VERSION}") + + +if (NOT WIN32) + set (BUILD_SHARED_LIBS ON) +endif() + + + +option (WITH_JIT + "just in Time Clause Compilation" OFF) +if (WITH_JIT) + add_subDIRECTORY(JIT) +endif (WITH_JIT) + +add_subDIRECTORY (packages/raptor) + +add_subDIRECTORY (packages/xml) + + +OPTION (WITH_CLPBN " Enable the CLPBN and PFL probabilistic languages" ON) + +OPTION (WITH_CPLINT " Enable the cplint probabilistic language" ON) + +OPTION (WITH_HORUS " Enable the CLPBN and PFL probabilistic languages" ON) + +OPTION (WITH_HORUS " Enable documentation, requires doxygen-yap" ON) + +IF (WITH_CLPBN) + add_subDIRECTORY (packages/CLPBN) +ENDIF(WITH_CLPBN) + +IF (WITH_CPLINT) + add_subDIRECTORY (packages/cplint) + ENDIF(WITH_CPLINT) + + # please install doxygen for prolog first + # git clone http://www.github.com/vscosta/doxygen-yap + # cd doxygen-yap + # mkdir -p build + # cd build + # make; sudo make install + option (WITH_DOCS + "generate YAP docs" OFF) + + IF (WITH_DOCS) + add_subDIRECTORY (docs) + ENDIF (WITH_DOCS) + +# add_subDIRECTORY (packages/cuda) + +option (WITH_GECODE +"interface gecode constraint solver" ON) +if (WITH_GECODE) +add_subDIRECTORY (packages/gecode) +endif() + +add_subDIRECTORY (packages/real) + + +add_subDIRECTORY (packages/jpl) + +add_subDIRECTORY (packages/bdd) + +add_subDIRECTORY (packages/ProbLog) + +add_subDIRECTORY (packages/swi-minisat2) + +add_subDIRECTORY (packages/clpqr) + + +#todo: use cmake target builds +# option (USE_MAXPERFORMANCE +# "try using the best flags for specific architecture" OFF) + +# option (USE_MAXMEMORY +# "try using the best flags for using the memory to the most" ON) +#TODO: check MAXMEMORY + +#TODO: use cmake target builds +# option (USE_DEBUGYAP +# "enable C-debugging for YAP" OFF) + +#TODO: use cmake arch/compiler +# option (USE_CYGWIN +# "use cygwin library in WIN32" OFF) + +option (WITH_PRISM + "use PRISM system in YAP" ON) +#TODO: + + +option (WITH_YAP_DLL + "compile YAP as a DLL" ON) +#TODO: + +option (WITH_YAP_STATIC + "compile YAP statically" OFF) +#TODO: + +option(WITH_YAP_CONDOR + "allow YAP to be used from condor" OFF) + +if (WITH_YAP_CONDOR) + # use default allocator + set ( YAP_STATIC ON ) + set ( YAP_DLL OFF ) +endif() + +#TODO: detect arch before allow this option +# OPTION(WIN64 +# "compile YAP for win64" OFF) + +# option (APRIL +# "compile Yap to support April ILP system" OFF) +# option (DLCOMPAT +# "use dlcompat library for dynamic loading on Mac OS X" OFF) + +# SHARED PACKAGES with SWI + +# swi packages have both Makefile.in which we will use and +# Makefile.mak, we will use the later to identify this packages +# while we keep both autotools amd cmake working side by side +# Search for available packages which all have a Makefile.mak +#file (GLOB PACKAGES packages/*/Makefile.mak) + +# needed by this packages + + + +if(WIN32) + + if(MSVC) + set(MSVC_RUNTIME "dynamic") + ENDIF(MSVC) + + target_link_libraries(libYap wsock32 ws2_32 Shlwapi) + +endif(WIN32) + +add_executable (yap-bin ${CONSOLE_SOURCES}) + +set_target_properties (yap-bin PROPERTIES OUTPUT_NAME yap) + + +target_link_libraries(yap-bin libYap ) + + install(TARGETS libYap yap-bin + RUNTIME DESTINATION ${bindir} + LIBRARY DESTINATION ${libdir} + ARCHIVE DESTINATION ${libdir} + ) + + +CMAKE_DEPENDENT_OPTION (WITH_SYSTEM_MMAP "Use MMAP for shared memory allocation" ON + "NOT WITH_YAPOR_THOR" OFF) + +CMAKE_DEPENDENT_OPTION (WITH_SYSTEM_SHM "Use SHM for shared memory allocation" ON + "NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF ) + + add_subDIRECTORY(library/lammpi) + + if (MPI_C_FOUND) + + CMAKE_DEPENDENT_OPTION( WITH_MPI ON "Interface to OpenMPI/MPICH" + "MPI_C_FOUND" OFF) + macro_optional_add_subDIRECTORY(library/mpi) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MPI_C_COMPILE_FLAGS} ") + include_directories(${MPI_C_INCLUDE_PATH}) + target_link_libraries(yap-bin ${MPI_C_LIBRARIES} ) + if(MPI_C_COMPILE_FLAGS) + set_target_properties(yap-bin PROPERTIES + COMPILE_FLAGS "${MPI_C_COMPILE_FLAGS}") + endif(MPI_C_COMPILE_FLAGS) + + if(MPI_C_LINK_FLAGS) + set_target_properties(yap-bin PROPERTIES + LINK_FLAGS "${MPI_C_LINK_FLAGS}") + endif() + endif (MPI_C_FOUND) + +## add_subDIRECTORY(utils) + +# +# include subdirectories configuration +## after we have all functionality in +# +# ADD_SUBDIRECTORY(console/terminal) + +if (NOT WIN32 AND WITH_READLINE) + include(readline) + macro_optional_find_package (Readline ON) +if (READLINE_FOUND ) + MY_target_link_libraries(libYap ${READLINE_LIBRARIES}) + endif() + endif() + + + + +macro_display_feature_log() +if(POLICY CMP0058) +cmake_policy(SET CMP0058 NEW) +endif(POLICY CMP0058) + include(Config NO_POLICY_SCOPE) + + feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES INCLUDE_QUIET_PACKAGES ) diff --git a/H/YapText.h b/H/YapText.h index 33091b20c..5b0ea0a42 100644 --- a/H/YapText.h +++ b/H/YapText.h @@ -63,6 +63,12 @@ extern int push_text_stack__(USES_REGS1); pop_text_stack__(lvl)) extern int pop_text_stack__(int lvl USES_REGS); +#define pop_output_text_stack(lvl,p) \ + (/*fprintf(stderr, "v %*c %s:%s:%d\n", AllocLevel(), ' ', __FILE__, \ + __FUNCTION__, __LINE__),*/ \ + pop_output_text_stack__(lvl,p)) +extern void *pop_output_text_stack__(int lvl, void *ox USES_REGS); + /****************** character definition table **************************/ #define NUMBER_OF_CHARS 256 diff --git a/Packages.cmake b/Packages.cmake deleted file mode 100644 index 3872dbc5c..000000000 --- a/Packages.cmake +++ /dev/null @@ -1,198 +0,0 @@ - -message(STATUS "Building YAP packages version ${YAP_VERSION}") - - -if (NOT WIN32) - set (BUILD_SHARED_LIBS ON) -endif() - - - -option (WITH_JIT - "just in Time Clause Compilation" OFF) -if (WITH_JIT) - add_subDIRECTORY(JIT) -endif (WITH_JIT) - -add_subDIRECTORY (packages/raptor) - -add_subDIRECTORY (packages/xml) - - -OPTION (WITH_CLPBN " Enable the CLPBN and PFL probabilistic languages" ON) - -OPTION (WITH_CPLINT " Enable the cplint probabilistic language" ON) - -OPTION (WITH_HORUS " Enable the CLPBN and PFL probabilistic languages" ON) - -OPTION (WITH_HORUS " Enable documentation, requires doxygen-yap" ON) - -IF (WITH_CLPBN) - add_subDIRECTORY (packages/CLPBN) -ENDIF(WITH_CLPBN) - -IF (WITH_CPLINT) - add_subDIRECTORY (packages/cplint) - ENDIF(WITH_CPLINT) - - # please install doxygen for prolog first - # git clone http://www.github.com/vscosta/doxygen-yap - # cd doxygen-yap - # mkdir -p build - # cd build - # make; sudo make install - option (WITH_DOCS - "generate YAP docs" OFF) - - IF (WITH_DOCS) - add_subDIRECTORY (docs) - ENDIF (WITH_DOCS) - -# add_subDIRECTORY (packages/cuda) - -option (WITH_GECODE -"interface gecode constraint solver" ON) -if (WITH_GECODE) -add_subDIRECTORY (packages/gecode) -endif() - -add_subDIRECTORY (packages/real) - - -add_subDIRECTORY (packages/jpl) - -add_subDIRECTORY (packages/bdd) - -add_subDIRECTORY (packages/ProbLog) - -add_subDIRECTORY (packages/swi-minisat2) - -add_subDIRECTORY (packages/clpqr) - - -#todo: use cmake target builds -# option (USE_MAXPERFORMANCE -# "try using the best flags for specific architecture" OFF) - -# option (USE_MAXMEMORY -# "try using the best flags for using the memory to the most" ON) -#TODO: check MAXMEMORY - -#TODO: use cmake target builds -# option (USE_DEBUGYAP -# "enable C-debugging for YAP" OFF) - -#TODO: use cmake arch/compiler -# option (USE_CYGWIN -# "use cygwin library in WIN32" OFF) - -option (WITH_PRISM - "use PRISM system in YAP" ON) -#TODO: - - -option (WITH_YAP_DLL - "compile YAP as a DLL" ON) -#TODO: - -option (WITH_YAP_STATIC - "compile YAP statically" OFF) -#TODO: - -option(WITH_YAP_CONDOR - "allow YAP to be used from condor" OFF) - -if (WITH_YAP_CONDOR) - # use default allocator - set ( YAP_STATIC ON ) - set ( YAP_DLL OFF ) -endif() - -#TODO: detect arch before allow this option -# OPTION(WIN64 -# "compile YAP for win64" OFF) - -# option (APRIL -# "compile Yap to support April ILP system" OFF) -# option (DLCOMPAT -# "use dlcompat library for dynamic loading on Mac OS X" OFF) - -# SHARED PACKAGES with SWI - -# swi packages have both Makefile.in which we will use and -# Makefile.mak, we will use the later to identify this packages -# while we keep both autotools amd cmake working side by side -# Search for available packages which all have a Makefile.mak -#file (GLOB PACKAGES packages/*/Makefile.mak) - -# needed by this packages - - - -if(WIN32) - - if(MSVC) - set(MSVC_RUNTIME "dynamic") - ENDIF(MSVC) - - target_link_libraries(libYap wsock32 ws2_32 Shlwapi) - -endif(WIN32) - -add_executable (yap-bin ${CONSOLE_SOURCES}) - -set_target_properties (yap-bin PROPERTIES OUTPUT_NAME yap) - - -target_link_libraries(yap-bin libYap ) - - install(TARGETS libYap yap-bin - RUNTIME DESTINATION ${bindir} - LIBRARY DESTINATION ${libdir} - ARCHIVE DESTINATION ${libdir} - ) - - -CMAKE_DEPENDENT_OPTION (WITH_SYSTEM_MMAP "Use MMAP for shared memory allocation" ON - "NOT WITH_YAPOR_THOR" OFF) - -CMAKE_DEPENDENT_OPTION (WITH_SYSTEM_SHM "Use SHM for shared memory allocation" ON - "NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF ) - - add_subDIRECTORY(library/lammpi) - - if (MPI_C_FOUND) - - CMAKE_DEPENDENT_OPTION( WITH_MPI ON "Interface to OpenMPI/MPICH" - "MPI_C_FOUND" OFF) - macro_optional_add_subDIRECTORY(library/mpi) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MPI_C_COMPILE_FLAGS} ") - include_directories(${MPI_C_INCLUDE_PATH}) - target_link_libraries(yap-bin ${MPI_C_LIBRARIES} ) - if(MPI_C_COMPILE_FLAGS) - set_target_properties(yap-bin PROPERTIES - COMPILE_FLAGS "${MPI_C_COMPILE_FLAGS}") - endif(MPI_C_COMPILE_FLAGS) - - if(MPI_C_LINK_FLAGS) - set_target_properties(yap-bin PROPERTIES - LINK_FLAGS "${MPI_C_LINK_FLAGS}") - endif() - endif (MPI_C_FOUND) - -## add_subDIRECTORY(utils) - -# -# include subdirectories configuration -## after we have all functionality in -# -# ADD_SUBDIRECTORY(console/terminal) - - - - - -macro_display_feature_log() -if(POLICY CMP0058) -cmake_policy(SET CMP0058 NEW) -endif(POLICY CMP0058) diff --git a/cmake/Config.cmake b/cmake/Config.cmake index bc382ba89..7d88ccf8d 100644 --- a/cmake/Config.cmake +++ b/cmake/Config.cmake @@ -308,7 +308,9 @@ check_function_exists(mktemp HAVE_MKTEMP) check_function_exists(nanosleep HAVE_NANOSLEEP) check_function_exists(mktime HAVE_MKTIME) check_function_exists(opendir HAVE_OPENDIR) -check_function_exists(open_memstream HAVE_OPEN_MEMSTREAM) +if (NOT APPLE) + check_function_exists(open_memstream HAVE_OPEN_MEMSTREAM) + endif() check_function_exists(putenv HAVE_PUTENV) check_function_exists(rand HAVE_RAND) check_function_exists(random HAVE_RANDOM) diff --git a/cmake/FindGMP.cmake b/cmake/FindGMP.cmake index 29d957e8f..b54373a94 100644 --- a/cmake/FindGMP.cmake +++ b/cmake/FindGMP.cmake @@ -8,8 +8,6 @@ # GMP_LIBRARY_DLL - library DLL to install. Only available on WIN32. # GMP_LIBRARIES_DIR - the directory the library we link with is found in. -message( "xxxxx ${ANDROID_ABI} yyyyy ${CMAKE_CURRENT_DIR} zzzzzzzzzz" ) - if (ANDROID) set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} ) set (GMP_FOUND ON) @@ -19,7 +17,7 @@ set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} ) else(ANDROID) if(MSVC) find_library(GMP_LIBRARIES NAMES mpir mpird - PATHS + PATHS $ENV{GMP_ROOT} $ENV{GMP_ROOT}/lib ${GMP_ROOT} @@ -58,22 +56,14 @@ else(MSVC) #its proper places -find_path(GMP_INCLUDE_DIRS - NAMES gmp.h - PATHS - . - ${GMP_ROOT} - ${GMP_LIBRARIES_DIR}/../include - ${GMP_LIBRARIES_DIR} - ) - - find_library(GMP_LIBRARIES NAMES gmp - PATHS + find_library(GMP_LIBRARIES + NAMES gmp libgmp + HINTS . - ${GMP_ROOT} - ${GMP_ROOT}/lib $ENV{GMP_ROOT} $ENV{GMP_ROOT}/lib + ${GMP_ROOT} + ${GMP_ROOT}/lib /usr/local/opt/gmp/lib /opt/lib /usr/local/lib @@ -81,6 +71,19 @@ find_path(GMP_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/lib ) + + find_path(GMP_INCLUDE_DIRS + NAMES gmp.h + HINTS + . + $ENV{GMP_ROOT} + $ENV{GMP_ROOT}/include + ${GMP_ROOT} + ${GMP_ROOT}/include + ${GMP_LIBRARIES_DIR}/../include + ${GMP_LIBRARIES_DIR} + ) + get_filename_component(GMP_LIBRARIES_DIR "${GMP_LIBRARIES}" PATH CACHE) diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake index e2ed8f23f..de432a3eb 100644 --- a/cmake/FindReadline.cmake +++ b/cmake/FindReadline.cmake @@ -14,6 +14,7 @@ # # try to extract R from readline to avoid collision IF(APPLE) FIND_PATH(READLINE_INCLUDE_DIR NAMES readline/readline.h PATHS + ${CMAKE_INCLUDE_PATH} ${R_INCLUDE_DIR} /sw/include /opt/local/include @@ -31,6 +32,7 @@ FIND_PATH(READLINE_INCLUDE_DIR NAMES readline/readline.h) # So we look for another one by default IF(APPLE) FIND_LIBRARY(READLINE_readline_LIBRARY NAMES readline PATHS + ${CMAKE_LIBRARY_PATH} /sw/lib /opt/local/lib /usr/local/opt/readline/lib #brew diff --git a/cmake/Prelims.cmake b/cmake/Prelims.cmake deleted file mode 100644 index 5496a46e5..000000000 --- a/cmake/Prelims.cmake +++ /dev/null @@ -1,175 +0,0 @@ - -#begining stuff for top CMakeLists - -include (MacroLogFeature) - -if (POLICY CMP0042) - cmake_policy( SET CMP0042 NEW) -endif() - -function(add_to_group output list) - set (result "") - foreach (path IN LISTS ${list}) - get_source_file_property(result ${path} LOCATION) - list( APPEND tmp ${result}) - endforeach () - list( APPEND ${output} ${tmp}) - set (${output} ${${output}} CACHE INTERNAL "prolog library files") -endfunction(add_to_group output list ) - -function(add_to_libgroup arg list) - set (x ${CMAKE_CURRENT_BINARY_DIR}/*${arg}*${CMAKE_SHARED_LIBRARY_SUFFIX}) - list( APPEND ${list} ${x}) - set(${list} ${${list}} CACHE INTERNAL "prolog library files") -endfunction(add_to_libgroup arg list ) - -if (ANDROID_OLD) - macro ( MY_add_custom_target) - endmacro() -else() - macro ( MY_add_custom_target ) - add_custom_target (${ARGN}) - endmacro() -endif() - -if (WIN32) - macro ( add_component arg1 ) - add_library ( ${arg1} OBJECT ${ARGN}) - endmacro() -else() - macro ( add_component arg1 ) - add_library ( ${arg1} OBJECT ${ARGN}) - endmacro() -endif() -macro ( add_lib arg1 ) - add_library ( ${arg1} SHARED ${ARGN}) - add_to_libgroup( ${arg1} YAP_DLLS ) -endmacro() - -if (ANDROID_OLD) - macro ( MY_add_dependencies) - endmacro() -else() - macro ( MY_add_dependencies ) - add_dependencies (${ARGN}) - endmacro() -endif() - -if (ANDROID_OLD) - macro ( MY_add_library) - endmacro() -else() - macro ( MY_add_library ) - add_library (${ARGN}) - endmacro() -endif() - -if (ANDROID) - macro ( MY_add_subdirectory) - endmacro() -else() - macro ( MY_add_subdirectory ) - add_subdirectory (${ARGN}) - endmacro() -endif() - -if (ANDROID_OLD) - macro ( MY_include) - endmacro() -else() - macro ( MY_include ) - include (${ARGN}) - endmacro() -endif() - -if (ANDROID) - macro ( MY_install) - endmacro() -else() - macro ( MY_install ) - install (${ARGN}) - endmacro() -endif() - -if (ANDROID_OLD) - macro ( MY_set_target_properties) - endmacro() -else() - macro ( MY_set_target_properties ) - set_target_properties (${ARGN}) - endmacro() -endif() - -if (ANDROID_OLD) - macro ( MY_target_link_libraries) - endmacro() -else() - macro ( MY_target_link_libraries ) - target_link_libraries (${ARGN}) - endmacro() -endif() - - -# where we have most scripts -# set path to additional CMake modules - -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -include(disallow) - -disallow_intree_builds() - -# set(CMAKE_BUILD_TYPE Debug) - -if (APPLE) - set (MACOSX_RPATH ON) -endif (APPLE ) -if(POLICY CMP0042) - cmake_policy(SET CMP0042 NEW) -endif(POLICY CMP0042) -if(POLICY CMP0043) - cmake_policy(SET CMP0043 NEW) -endif(POLICY CMP0043) - - -if (ANDROID) - set ( prefix ${YAP_APP_DIR}/build ) - set ( datarootdir ${prefix}/assets ) -else() -set ( prefix "${CMAKE_INSTALL_PREFIX}") - set ( datarootdir ${prefix}/share ) -endif() - set ( libpl ${datarootdir}/Yap) -set ( includedir "${prefix}/include") -set ( exec_prefix "${prefix}") -set ( libdir "${exec_prefix}/lib") -set ( datadir "${datarootdir}") -set ( mandir "${datarootdir}/man") -set ( bindir "${exec_prefix}/bin") -set ( docdir "${datarootdir}/doc/Yap") -set ( dlls "${exec_prefix}/lib/Yap") - -set(YAP_ROOTDIR ${prefix}) - -# erootdir -> rootdir -# bindir defined above -# libdir defined above -set(YAP_LIBDIR "${dlls}") -set(YAP_SHAREDIR "${datarootdir}") -set(YAP_BINDIR "${bindir}") -set(YAP_INCLUDEDIR "${includedir}") -set(YAP_ROOTDIR "${prefix}") - -# -# -# include( Sources NO_POLICY_SCOPE ) -# -# include( Model NO_POLICY_SCOPE ) - -include (cudd NO-POLICY-SCOPE) -include (java NO-POLICY-SCOPE) - -set (pl_library "" CACHE INTERNAL "prolog library files" ) -set (pl_os_library "" CACHE INTERNAL "prolog os files" ) -set (pl_boot_library "" CACHE INTERNAL "prolog boot files" ) - diff --git a/cmake/python.cmake b/cmake/python.cmake index 50da2c33f..f0a0727a8 100644 --- a/cmake/python.cmake +++ b/cmake/python.cmake @@ -30,7 +30,7 @@ endif() include_directories( BEFORE ${PYTHON_INCLUDE_DIRS} ) LIST( APPEND - CMAKE_REQUIRED_INCLUDES ${PYTHON_INCLUDE_DIRS} ${CMAKE_REQUIRED_INCLUDES}) +CMAKE_REQUIRED_INCLUDES ${PYTHON_INCLUDE_DIRS} ${CMAKE_REQUIRED_INCLUDES} ${GMP_INCLUDE_DIRS}) check_include_file(Python.h HAVE_PYTHON_H) diff --git a/info/build.sh b/info/build.sh new file mode 100644 index 000000000..eb06d6e5d --- /dev/null +++ b/info/build.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +export MACOSX_DEPLOYMENT_TARGET=10.12 + +mkdir $PREFIX/conda +cd $PREFIX/conda +# The datarootdir option places the docs into a temp folder that won't +CC=$SYS_PREFIX/bin/clang \ + CXX=$SYS_PREFIX/bin/clang++ \ + $SYS_PREFIX/bin/cmake \ + -DCMAKE_INCLUDE_PATH="$SYS_PREFIX"/include \ + -DCMAKE_LIBRARY_PATH="$SYS_PREFIX"/lib \ + -DCMAKE_BUILD_TYPE=Debug \ + $RECIPE_DIR/.. +CC=$SYS_PREFIX/bin/clang \ + CXX=$SYS_PREFIX/bin/clang++ \ +make +CC=$SYS_PREFIX/bin/clang \ + CXX=$SYS_PREFIX/bin/clang++ \ +make install + +# Remove the created lib64 directory + +rm -rf $PREFIX/conda diff --git a/info/meta.yaml b/info/meta.yaml new file mode 100644 index 000000000..8e6c482d9 --- /dev/null +++ b/info/meta.yaml @@ -0,0 +1,23 @@ +package: + name: yap4py + version: 1.8.0 + +requirements: + build: + - cmake + - swig + - readline + - gmp + run: + - readline + - gmp + + +about: + home: http://www.github.com/vscosta/yap-6.3.git + license: LGPL2 + license_family: LGPL + summary: Prolog System + +source: + path: .. \ No newline at end of file diff --git a/libYap.cmake b/libYap.cmake deleted file mode 100644 index 70a42e47d..000000000 --- a/libYap.cmake +++ /dev/null @@ -1,111 +0,0 @@ - -include (Sources) - -set(YAP_STARTUP startup.yss) -## define system - - # Optional libraries that affect compilation - # - - -set(CMAKE_TOP_BINARY_DIR ${CMAKE_BINARY_DIR}) -set(YAP_PL_SRCDIR ${CMAKE_SOURCE_DIR}/pl) - -set(YAP_YAPLIB libYap${CMAKE_SHARED_LIBRARY_SUFFIX}) - -string(TIMESTAMP YAP_TIMESTAMP) - -string( SUBSTRING ${CMAKE_SHARED_LIBRARY_SUFFIX} 1 -1 SO_EXT ) - -set_property(DIRECTORY PROPERTY CXX_STANDARD 11) - -# rpath stuff, hopefully it works - -# use, i.e. don't skip the full RPATH for the build tree -SET(CMAKE_SKIP_BUILD_RPATH FALSE) - -# when building, don't use the install RPATH already -# (but later on when installing) -SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) - -SET(CMAKE_INSTALL_RPATH "${libdir};${dlls}:") - -# add the automatically determined parts of the RPATH -# which point to directories outside the build tree to the install RPATH -SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - -set_target_properties(libYap - PROPERTIES OUTPUT_NAME Yap - ) - MY_set_target_properties(libYap - PROPERTIES VERSION ${YAP_FULL_VERSION} - SOVERSION ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION} - ) - - if (READLINE_LIBRARIES) - MY_target_link_libraries(libYap READLINE_LIBRARIES) - endif() - -# the RPATH to be used when installing, but only if it's not a system directory -LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${libdir};${dlls}" isSystemDir) -IF("${isSystemDir}" STREQUAL "-1") - SET(CMAKE_INSTALL_RPATH "${libdir};${dlls}") -ENDIF("${isSystemDir}" STREQUAL "-1") - - -include_directories (H - H/generated - include os OPTYap utf8proc JIT/HPP) -include_directories (BEFORE ${CMAKE_BINARY_DIR} ${CMAKE_TOP_BINARY_DIR}) - -if (ANDROID) -include_directories (CXX ${CMAKE_SOURCE_DIR}/../generated/src/jni) -endif() - -find_package (GMP) - - list(APPEND YAP_SYSTEM_OPTIONS big_numbers) - -if (GMP_FOUND) -# GMP_FOUND - true if GMP/MPIR was found -# GMP_INCLUDE_DIRS - include search path -# GMP_LIBRARIES - libraries to link with -# GMP_LIBRARY_ #add_executable(test ${SOURCES}) - #config.h needs this (TODO: change in code latter) - include_directories( ${GMP_INCLUDE_DIRS} ) - target_link_libraries(libYap ${GMP_LIBRARIES} ) -endif (GMP_FOUND) - -include( Threads ) -# -# include OS and I/o stuff -# -# convenience libraries -# OPTYap exports important flags -# -list(APPEND YAP_SYSTEM_OPTIONS "thread support") - -#utf-8 is not an option -# we use the nice UTF-8 package -#available at the Julia project - -ADD_SUBDIRECTORY ( os ) -ADD_SUBDIRECTORY ( OPTYap ) -ADD_SUBDIRECTORY ( packages/myddas ) -ADD_SUBDIRECTORY ( utf8proc ) -ADD_SUBDIRECTORY ( library/dialect/swi/fli ) -ADD_SUBDIRECTORY ( CXX ) - -if (READLINE_LIBS) - target_link_libraries(libYap ${READLINE_LIBS} ) -endif (READLINE_LIBS) - - -add_subDIRECTORY ( H ) - -#bootstrap and saved state -add_subDIRECTORY ( pl ) - -ADD_SUBDIRECTORY( library) - -ADD_SUBDIRECTORY( swi/library "swiLibrary" ) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index ed04a85cf..7c7c3b500 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -74,7 +74,7 @@ MY_add_subdirectory(system) MY_add_subdirectory(tries) MY_add_subdirectory(ytest) -add_to_group( pl_library LIBRARY_PL ) +add_to_group( LIBRARY_PL pl_library) if (0) file(COPY ${LIBRARY_PL} DESTINATION ${libpl}) diff --git a/library/clp/CMakeList.txt b/library/clp/CMakeList.txt deleted file mode 100644 index b40c4ee9c..000000000 --- a/library/clp/CMakeList.txt +++ /dev/null @@ -1,13 +0,0 @@ -set (LIBRARY_PL_VLP - clpfd.pl - clp_distinct.pl - simplex.pl - ) - -install(FILES ${LIBRARY_PL_CLP} - DESTINATION ${libpl} - ) - - - - diff --git a/library/clp/CMakeLists.txt b/library/clp/CMakeLists.txt index 5f61f2911..8dfbd3f99 100644 --- a/library/clp/CMakeLists.txt +++ b/library/clp/CMakeLists.txt @@ -1,11 +1,15 @@ -set (LIBRARY_PL_VLP - clpfd.pl - clp_distinct.pl +set (LIBRARY_PL_CLP + clpfd.pl + clp_distinct.pl simplex.pl ) +add_to_group( LIBRARY_PL_CLP pl_library ) + install(FILES ${LIBRARY_PL_CLP} DESTINATION ${libpl} ) - add_to_group( pl_library LIBRARY_PL_CLP ) + + + diff --git a/library/dialect/swi/fli/CMakeLists.txt b/library/dialect/swi/fli/CMakeLists.txt index 68fa93c26..9be943d5c 100644 --- a/library/dialect/swi/fli/CMakeLists.txt +++ b/library/dialect/swi/fli/CMakeLists.txt @@ -2,10 +2,10 @@ set (LIBSWI_SOURCES swi.c blobs.c ) -add_component (libswi +add_component (libswi ${LIBSWI_SOURCES}) - + MY_set_target_properties(libswi PROPERTIES # RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} @@ -15,9 +15,9 @@ MY_set_target_properties(libswi SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 ) -include_directories (../../../H ../.../../include ../os ${CMAKE_BINARY_DIR} ${GMP_INCLUDE_DIR}) +include_directories (../../../H ../.../../include ../os ${CMAKE_BINARY_DIR} ${GMP_INCLUDE_DIRS}) set (YAP_SWILIB $ ) -set( CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${GMP_INCLUDE_DIR} ) +set( CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${GMP_INCLUDE_DIRS} ) #set( CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${GMP_LIBRARIES} ) diff --git a/library/dialect/swi/fli/swi.c b/library/dialect/swi/fli/swi.c index 24c41b21c..199755c41 100755 --- a/library/dialect/swi/fli/swi.c +++ b/library/dialect/swi/fli/swi.c @@ -208,27 +208,30 @@ X_API int PL_get_nchars(term_t l, size_t *lengthp, char **s, unsigned flags) { inp.val.t = Yap_GetFromSlot(l); inp.type = cvtFlags(flags); out.type = YAP_STRING_CHARS; - out.val.c = *s; + if (flags & (REP_UTF8 | REP_MB)) { out.enc = ENC_ISO_UTF8; } else { out.enc = ENC_ISO_LATIN1; } - - if (flags & BUF_MALLOC) { - out.type |= YAP_STRING_MALLOC; out.val.c = NULL; - } - if (lengthp) { - out.type |= YAP_STRING_NCHARS; - out.max = *lengthp; - } if (!Yap_CVT_Text(&inp, &out PASS_REGS)) { pop_text_stack(lvl); return false; } - if (*s) { - *s = out.val.c; + if (s) { + size_t len = strlen(out.val.c); + if (flags & (BUF_DISCARDABLE|BUF_RING)) { + return true; + } + *s = pop_output_text_stack(lvl, out.val.c); + if (*s == out.val.c) { + char *v = malloc(len+1); + strcpy(v, *s); + *s = v; + } + if (lengthp) + *lengthp = len; } return true; } diff --git a/os/CMakeLists.txt b/os/CMakeLists.txt index 841cf3716..6188d1425 100644 --- a/os/CMakeLists.txt +++ b/os/CMakeLists.txt @@ -50,9 +50,10 @@ set (POSITION_INDEPENDENT_CODE TRUE) set (YAPOS_PL_SOURCES edio.yap chartypes.yap + yio.yap ) -add_to_group( pl_os_library YAPOS_PL_SOURCES ) +add_to_group( YAPOS_PL_SOURCES pl_os_library) if (ANDROID) @@ -61,57 +62,3 @@ else() install (FILES ${YAPOS_PL_SOURCES} DESTINATION ${libpl}/os ) endif() - - -include(CheckFunctionExists) -include(CheckSymbolExists) -include(CheckVariableExists) - - option (WITH_READLINE "GNU readline console" ON) - - if (WIN32) - set (WITH_READLINE OFF) - endif (WIN32) - - if (WITH_READLINE) - macro_optional_find_package (Readline ON) - - if (READLINE_FOUND) - # - Find the readline library - # This module defines - # READLINE_INCLUDE_DIR, path to readline/readline.h, etc. - # READLINE_LIBRARIES, the libraries required to use READLINE. - # READLINE_FOUND, If false, do not try to use READLINE. - # also defined, but not for general use are - # READLINE_readline_LIBRARY, where to find the READLINE library. - # READLINE_ncurses_LIBRARY, where to find the ncurses library [might not be defined] - include_directories (BEFORE ${READLINE_INCLUDE_DIR}) - list( APPEND CMAKE_REQUIRED_LIBRARIES ${READLINE_LIBRARIES} ) - check_include_files( "stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H ) - check_include_files( "stdio.h;readline/history.h" HAVE_READLINE_HISTORY_H ) - if (HAVE_READLINE_READLINE_H) - SET ( USE_READLINE ON PARENT_SCOPE) - set(YAP_SYSTEM_OPTIONS "readline" ${YAP_SYSTEM_OPTIONS} PARENT_SCOPE) - check_library_exists( readline readline "${READLINE_LIBRARIES}" HAVE_LIBREADLINE ) - check_function_exists( add_history HAVE_ADD_HISTORY ) - check_function_exists( rl_begin_undo_group HAVE_RL_BEGIN_UNDO_GROUP) - check_function_exists( rl_clear_pending_input HAVE_RL_CLEAR_PENDING_INPUT) - check_function_exists( rl_discard_argument HAVE_RL_DISCARD_ARGUMENT) - check_symbol_exists( rl_filename_completion_function stdio.h;readline/readline.h HAVE_RL_FILENAME_COMPLETION_FUNCTION) - check_function_exists( rl_free_line_state HAVE_RL_FREE_LINE_STATE ) - check_function_exists( rl_insert_close HAVE_RL_INSERT_CLOSE ) - check_function_exists( rl_reset_after_signal HAVE_RL_RESET_AFTER_SIGNAL ) - check_function_exists( rl_set_keyboard_input_timeout HAVE_RL_SET_KEYBOARD_INPUT_TIMEOUT ) - check_function_exists( rl_set_prompt HAVE_RL_SET_PROMPT) - check_symbol_exists( rl_catch_signals "stdio.h;readline/readline.h" HAVE_DECL_RL_CATCH_SIGNALS ) - check_type_size( rl_completion_func_t RL_COMPLETION_FUNC_T ) - check_symbol_exists( rl_done stdio.h;readline/readline.h HAVE_DECL_RL_DONE ) - CHECK_TYPE_SIZE( rl_hook_func_t RL_HOOK_FUNC_T ) - check_symbol_exists( rl_event_hook stdio.h;readline/readline.h HAVE_DECL_RL_EVENT_HOOK ) - check_symbol_exists( rl_readline_state stdio.h;readline/readline.h HAVE_DECL_RL_READLINE_STATE ) - endif() -endif (READLINE_FOUND) - - set( READLINE_LIBS ${READLINE_LIBRARIES} PARENT_SCOPE) - -endif (WITH_READLINE) diff --git a/os/fmem.c b/os/fmem.c index 400399478..738281f6b 100644 --- a/os/fmem.c +++ b/os/fmem.c @@ -168,10 +168,9 @@ open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */ if (!buf) { return false; } - buf = export_block( (char *)buf ); - pop_text_stack(l); sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding, MEM_BUF_MALLOC); + pop_text_stack(l); t = Yap_MkStream(sno); return Yap_unify(ARG2, t); } diff --git a/os/readline.c b/os/readline.c index e2e5ea65f..ec3007ae7 100644 --- a/os/readline.c +++ b/os/readline.c @@ -1,19 +1,19 @@ /************************************************************************* -* * -* YAP Prolog * -* * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * -* * -************************************************************************** -* * -* File: readline.c * -* Last rev: 5/2/88 * -* mods: * -* comments: Input/Output C implemented predicates * -* * -*************************************************************************/ + * * + * YAP Prolog * + * * + * Yap Prolog was developed at NCCUP - Universidade do Porto * + * * + * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * + * * + ************************************************************************** + * * + * File: readline.c * + * Last rev: 5/2/88 * + * mods: * + * comments: Input/Output C implemented predicates * + * * + *************************************************************************/ #ifdef SCCS static char SccsId[] = "%W% %G%"; #endif @@ -253,13 +253,13 @@ void Yap_ReadlineFlush(int sno) { } } -bool Yap_readline_clear_pending_input(StreamDesc *s) { +bool Yap_readline_clear_pending_input(StreamDesc *s) { rl_clear_pending_input(); if (s->u.irl.buf) { - free( ( void *)s->u.irl.buf ); -} - s->u.irl.ptr = s->u.irl.buf = NULL; - return true; + free((void *)s->u.irl.buf); + } + s->u.irl.ptr = s->u.irl.buf = NULL; + return true; } bool Yap_ReadlineOps(StreamDesc *s) { @@ -273,7 +273,6 @@ bool Yap_ReadlineOps(StreamDesc *s) { return false; } - bool Yap_InitReadline(Term enable) { // don't call readline within emacs if (Yap_embedded) @@ -320,16 +319,18 @@ static bool getLine(int inp) { rl_set_signals(); myrl_line = (unsigned char *)readline(LOCAL_Prompt); rl_clear_signals(); -} else { + } else { rl_set_signals(); myrl_line = (unsigned char *)readline(NULL); rl_clear_signals(); } /* Do it the gnu way */ LOCAL_PrologMode &= ~ConsoleGetcMode; +#if HAVE_RL_PENDING_SIGNAL if (rl_pending_signal()) { LOCAL_PrologMode |= InterruptMode; } +#endif if (LOCAL_PrologMode & InterruptMode) { Yap_HandleSIGINT(); } else { @@ -438,10 +439,10 @@ int Yap_ReadlineForSIGINT(void) { static Int has_readline(USES_REGS1) { #if USE_READLINE - if (!Yap_embedded) { - return true; - } - return false; + if (!Yap_embedded) { + return true; + } + return false; #else return false; #endif diff --git a/pl/yio.yap b/os/yio.yap similarity index 100% rename from pl/yio.yap rename to os/yio.yap diff --git a/packages/myddas/pl/CMakeLists.txt b/packages/myddas/pl/CMakeLists.txt index 5ea666cbb..6456b54f2 100644 --- a/packages/myddas/pl/CMakeLists.txt +++ b/packages/myddas/pl/CMakeLists.txt @@ -75,6 +75,8 @@ foreach (driver ${MYDDAS_DBMS}) cpp_driver(MYDDAS_YAP ${driver} myddas_driver.ypp) endforeach () +add_to_group(MYDDAS_YAP pl_library ) + add_custom_target(plmyddas ALL DEPENDS ${MYDDAS_YAP} ) install(FILES ${MYDDAS_YAP} diff --git a/packages/python/CMakeLists.txt b/packages/python/CMakeLists.txt index 0f20ca685..ea802d0c6 100644 --- a/packages/python/CMakeLists.txt +++ b/packages/python/CMakeLists.txt @@ -5,8 +5,9 @@ set (PYTHON_SOURCES python.c pl2py.c pybips.c py2pl.c pl2pl.c pypreds.c) set (CMAKE_POSITION_INDEPENDENT_CODE TRUE) +message( ${GMP_INCLUDE_DIRS} ) include_directories( ${CMAKE_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/os ) +${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/os ${GMP_INCLUDE_DIRS} ) #talk to python.pl add_lib(YAPPython pyload.c ${PYTHON_HEADERS} ) @@ -18,8 +19,13 @@ add_library (Py4YAP OBJECT ${PYTHON_SOURCES} ${PYTHON_HEADERS}) else() -add_lib(Py4YAP ${PYTHON_SOURCES} ${PYTHON_HEADERS}) +add_corelib(Py4YAP ${PYTHON_SOURCES} ${PYTHON_HEADERS}) +MY_set_target_properties( + Py4YAP +PROPERTIES VERSION ${YAP_FULL_VERSION} +SOVERSION ${YAP_MAJOR_VERSION}.${YAP_MINOR_VERSION} +) target_link_libraries(Py4YAP libYap ${PYTHON_LIBRARIES}) @@ -40,7 +46,7 @@ set (PYTHON_PL python.pl) install(FILES python.pl DESTINATION ${libpl} ) -add_to_group( pl_library PYTHON_PL ) +add_to_group( PYTHON_PL pl_library ) set_target_properties (YAPPython PROPERTIES PREFIX "") @@ -48,4 +54,3 @@ set_target_properties (YAPPython PROPERTIES PREFIX "") LIBRARY DESTINATION ${dlls} RUNTIME DESTINATION ${dlls} ARCHIVE DESTINATION ${dlls} ) - diff --git a/packages/python/swig/CMakeLists.txt b/packages/python/swig/CMakeLists.txt index 36a448ae4..90b3fc75c 100644 --- a/packages/python/swig/CMakeLists.txt +++ b/packages/python/swig/CMakeLists.txt @@ -8,19 +8,23 @@ include(FindPythonModule) list (APPEND pl_library ${CMAKE_CURRENT_SOURCE_DIR}/prolog/jupyter.yap ${CMAKE_CURRENT_SOURCE_DIR}/prolog/yapi.yap ) set (PYTHON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/yapi.py ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/__init__.py ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/__main__.py) +SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES SWIG_FLAGS "-O;-py3") +SET_SOURCE_FILES_PROPERTIES(../../swiyap.i PROPERTIES SWIG_MODULE_NAME yap) +#SET_SOURCE_FILES_PROPERTIES(../../swi/yap.i PROPERTIES OUTPUT_NAME yap) + + configure_file("setup.py.in" ${CMAKE_CURRENT_BINARY_DIR}/setup.py) configure_file("MANIFEST.in" ${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/YAP4PY.md" ${CMAKE_CURRENT_BINARY_DIR}/README) -INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) +INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/include -INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}/yap4py/include") + DEPENDS ${SWIG_SOURCES} YAP++ + ) -SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES CPLUSPLUS ON) -SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES SWIG_FLAGS "-O;-py3") -SET_SOURCE_FILES_PROPERTIES(../../swiyap.i PROPERTIES SWIG_MODULE_NAME yap) -#SET_SOURCE_FILES_PROPERTIES(../../swi/yap.i PROPERTIES OUTPUT_NAME yap) + SWIG_ADD_LIBRARY(Py2YAP LANGUAGE python SHARED SOURCES ../../swig/yap.i ) if (WIN32) @@ -31,14 +35,21 @@ else() set_target_properties ( ${SWIG_MODULE_Py2YAP_REAL_NAME} PROPERTIES NO_SONAME ON - OUTPUT_NAME yapc - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" - DEPENDS YAPPython YAPPython YAP++ + OUTPUT_NAME yap + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS YAPPython + ) - # inform we are compiling YAP + + + SET(SWIG_SOURCES + ${CMAKE_SOURCE_DIR}/packages/swig/yap.i + ) + + # inform we are compiling YAP # s used in MSYS - # - # + + # INSTALL ( TARGETS ${SWIG_MODULE_Py2YAP_REAL_NAME} # RUNTIME DESTINATION ${PYTHON_MODULE_PATH} # ARCHIVE DESTINATION ${PYTHON_MODULE_PATH} @@ -46,25 +57,63 @@ else() # ) - file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4y) + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/include) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/os) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/pl) - file(COPY ../../swig/yap.i DESTINATION .) - file(COPY ${CMAKE_SOURCE_DIR}/CXX/yapi.cpp DESTINATION .) -file(COPY ${pl_library} DESTINATION yap4py/prolog) -file(COPY ${pl_os_library} DESTINATION yap4py/prolog/os) -file(COPY ${c_headers} DESTINATION yap4py/include) -file(COPY ${cxx_headers} DESTINATION yap4py/include) + add_custom_command( OUTPUT yap.i + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/packages/swig/yap.i . + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${CMAKE_SOURCE_DIR}/packages/swig/yap.i ) + + add_custom_command( OUTPUT yapi.cpp +COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/CXX/yapi.cpp . + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${CMAKE_SOURCE_DIR}/CXX/yapi.cpp ) + + add_custom_command( OUTPUT yap4py/prolog/lists.yap +COMMAND ${CMAKE_COMMAND} -E copy ${pl_library} yap4py/prolog + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${pl_library} ) + + add_custom_command( OUTPUT yap4py/prolog/os/yio.yap + COMMAND ${CMAKE_COMMAND} -E copy ${pl_os_library} yap4py/prolog/os + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${pl_os_library} ) + + add_custom_command( OUTPUT yap4py/prolog/pl/boot.yap + COMMAND ${CMAKE_COMMAND} -E copy ${pl_boot_library} yap4py/prolog/pl + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +DEPENDS ${pl_boot_library} ) + + add_custom_command( OUTPUT yap4py/include/YapInterface.h +COMMAND ${CMAKE_COMMAND} -E copy ${c_headers} yap4py/include + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${c_headers} ) + + add_custom_command( OUTPUT yap4py/include/yapi.hh + COMMAND ${CMAKE_COMMAND} -E copy ${cxx_headers} yap4py/include + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${cxx_headers} ) + +if (CONDA) + set(bdist bdist_conda) +else() + set(bdist bdist_wheel) +endif() + add_custom_target( YAP4PY ALL COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/startup.yss ${CMAKE_CURRENT_BINARY_DIR}/yap4py COMMAND ${CMAKE_COMMAND} -E copy ${CONFIGURATION_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/include - COMMAND ${PYTHON_EXECUTABLE} setup.py sdist bdist_wheel + COMMAND ${SWIG_EXECUTABLE} -c++ -python -O -py3 -module "yap" -outcurrentdir -addextern -Iyap4py/include -outdir ${CMAKE_CURRENT_BINARY_DIR} -I${GMP_INCLUDE_DIRS} -DX_API="" -o yapPyTHON_wrap.cxx ${SWIG_SOURCES} + COMMAND ${PYTHON_EXECUTABLE} setup.py sdist ${bdist} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS STARTUP ${PYTHON_SOURCES} ${PROLOG_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/setup.py ${SWIG_MODULE_Py2YAP_REAL_NAME} ) + DEPENDS ${YAP_DLLS} STARTUP yap4py/prolog/pl/boot.yap yapi.cpp yap4py/include/yapi.hh yap4py/include/YapInterface.h yap4py/prolog/os/yio.yap yap4py/prolog/lists.yap yap.i +) + function(f_copy filename output ) get_filename_component(base ${filename} NAME_WE) diff --git a/packages/python/swig/MANIFEST.in b/packages/python/swig/MANIFEST.in index 93cc597b6..87d5b4aea 100644 --- a/packages/python/swig/MANIFEST.in +++ b/packages/python/swig/MANIFEST.in @@ -4,6 +4,9 @@ include README.md recursive-include yap4py/prolog *.* recursive-include html *.* recursive-include docs *.* +recursive-include so *.* +recursive-include dll *.* +recursive-include dylib *.* # Documentation graft docs diff --git a/packages/python/swig/__init__.py b/packages/python/swig/__init__.py index d4f2aa12d..077b47d22 100644 --- a/packages/python/swig/__init__.py +++ b/packages/python/swig/__init__.py @@ -17,10 +17,9 @@ if platform.system() == 'Windows': load('libYap*') else: def load( dll ): - dll = glob.glob(os.path.join(yap_lib_path,dll))[0] + dll = os.path.join(yap_lib_path,dll) dll = os.path.abspath(dll) ctypes.CDLL(dll, mode=ctypes.RTLD_GLOBAL) - if platform.system() == 'Apple':: - load('libYap*') - load('libYAP+*') - load('libPy4YAP*') + if platform.system() == 'Apple': + load('libYap.dylib') + load('libPy4YAP.dylib' ) diff --git a/packages/python/swig/setup.py.cmake b/packages/python/swig/setup.py.cmake index 1a585c489..58b803cd9 100644 --- a/packages/python/swig/setup.py.cmake +++ b/packages/python/swig/setup.py.cmake @@ -57,7 +57,9 @@ if platform.system() == 'Darwin': so = 'dylib' #or dll in glob('yap/dlls/*'): # move( dll ,'lib' ) - +libs = glob('../../../*.{dylib;dll;so}'+'../../../*/*.{dylib;dll;so}'+'../../../*/*/*.{dylib;dll;so}') +for l in libs: + copy2(l, 'yap4py', follow_symlinks=False) cplus=['${RELATIVE_SOURCE}CXX/yapi.cpp'] diff --git a/packages/python/swig/setup.py.in b/packages/python/swig/setup.py.in index 04f4b900d..a73cf00d1 100644 --- a/packages/python/swig/setup.py.in +++ b/packages/python/swig/setup.py.in @@ -50,37 +50,29 @@ import shutil from distutils.core import setup here = abspath(dirname(__file__)) -libpydir = abspath(dirname(os.path.dirname('stdlib'))) -libpyauxdir = abspath(os.path.dirname('stdlib')) +libpydir = abspath(sysconfig.get_path('platlib')) +libpyauxdir = abspath(os.path.dirname('std lib')) #pkg_root = join(here, name) +here = path.abspath(path.dirname(__file__)) + sys.path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}") -if 'conda' in sys.version or 'Continuum' in sys.version:\ -my_extra_link_args = [] + if platform.system() == 'Windows': local_libs = [] win_libs = ['wsock32','ws2_32'] my_extra_link_args = ['-Wl,-export-all-symbols'] else: - # if platform.system() == 'Darwin': - my_extra_link_args = [] + #if platform.system() == 'Darwin': + my_extra_link_args = ['-Wl,-rpath','-Wl,@loader_path/../../..'] win_libs = [] local_libs = ['Py4YAP'] # or dll in glob('yap/dlls/*'): # move( dll ,'lib' ) -native_sources = ["yap.i",'yapi.cpp'] +native_sources = ["yapPYTHON_wrap.cxx",'yapi.cpp'] -for i in '${PYTHON_SOURCES}'.split(";"): - copy2(i, 'yap4py') -my_libs0 = '${YAP_DLLS}'.split(";") -my_libs = [] -for i in my_libs0: - my_libs = glob(i) + my_libs -for i in my_libs: - copy2(i, 'yap4py') -here = path.abspath(path.dirname(__file__)) #gmp_dir = path.abspath(path.dirname("${GMP_LIBRARIES}")) #python_libdir = path.abspath(path.dirname("${PYTHON_LIBRARIES}") # Get the long description from the README file @@ -93,10 +85,11 @@ extensions = [Extension('_yap', native_sources, ('_YAP_NOT_INSTALLED_', '1'), ('YAP_PYTHON', '1'), ('_GNU_SOURCE', '1')], - runtime_library_dirs=['yap4py'], + runtime_library_dirs=[abspath(sysconfig.get_path('platlib')), + abspath(sysconfig.get_path('platlib'))], swig_opts=['-modern', '-c++', '-py3', '-DX_API', '-Iyap4py/include' ], - library_dirs=["yap4py"], + library_dirs=[".",'../../..'], extra_link_args=my_extra_link_args, libraries=['Yap','Py4YAP','gmp']+win_libs+local_libs, include_dirs=['yap4py/include'] @@ -111,6 +104,8 @@ package_data = { '': '*.*' } +data_files=[('../..', glob('lib*.*'))] + version_ns = {'__version__': '6.3.5', 'minor-version': '6', 'minor-version': '3', 'patch': '5'} setup_args = dict( @@ -118,9 +113,11 @@ setup_args = dict( version=version_ns['__version__'], scripts=glob(join('scripts', '*')), packages=packages, - py_modules=['yap','yap4py'], + ext_modules=extensions, + py_modules=['yap','yap4py.yapi'], package_data=package_data, include_package_data=True, + data_files = data_files, # requirements=[ # 'm2w64-gmp', # 'm2-msys2-keyring', @@ -132,7 +129,6 @@ setup_args = dict( author_email='vsc@dcc.fc.up.pt', url='http://www.dcc.fc.up/~vsc/yap', license='BSD', - ext_modules=extensions, platforms="Linux, Mac OS X, Windows", keywords=['Interactive', 'Interpreter', 'Shell', 'Web'], classifiers=[ diff --git a/packages/python/swig/yap4py/__init__.py b/packages/python/swig/yap4py/__init__.py index 2db17e987..087560a92 100644 --- a/packages/python/swig/yap4py/__init__.py +++ b/packages/python/swig/yap4py/__init__.py @@ -20,5 +20,5 @@ else: dll = glob.glob(os.path.join(yap_lib_path,dll))[0] dll = os.path.abspath(dll) ctypes.CDLL(dll, mode=ctypes.RTLD_GLOBAL) - load('libYap*') - load('libPy4YAP*') + # load('libYap*') + # load('libPy4YAP*') diff --git a/packages/python/swig/yap4py/__main__.py b/packages/python/swig/yap4py/__main__.py index 3940615a3..5aeb4f9c7 100644 --- a/packages/python/swig/yap4py/__main__.py +++ b/packages/python/swig/yap4py/__main__.py @@ -1,4 +1,4 @@ - """The main routine of the yap python project.""" +"""The main routine of the yap python project.""" import sys import yap4py.yapi diff --git a/packages/real/CMakeLists.txt b/packages/real/CMakeLists.txt index 7be33e8b9..15b1fcac7 100644 --- a/packages/real/CMakeLists.txt +++ b/packages/real/CMakeLists.txt @@ -20,7 +20,7 @@ set (REAL_PL real.pl ) -add_to_group( pl_library REAL_PL ) +add_to_group( REAL_PL pl_library) include_directories ( ${CMAKE_CURRENT_BINARY_DIR} diff --git a/pl/CMakeLists.txt b/pl/CMakeLists.txt index 0cbc83513..0993fe19e 100644 --- a/pl/CMakeLists.txt +++ b/pl/CMakeLists.txt @@ -1,4 +1,4 @@ - set(PL_SOURCES + set(PL_BOOT_SOURCES absf.yap arith.yap arithpreds.yap @@ -20,10 +20,6 @@ directives.yap eam.yap error.yap errors.yap - - - - eval.yap flags.yap grammar.yap @@ -58,10 +54,9 @@ udi.yap undefined.yap utils.yap yapor.yap -yio.yap ) - add_to_group( pl_boot_library PL_SOURCES ) + add_to_group( PL_BOOT_SOURCES pl_boot_library ) add_custom_target (STARTUP ALL SOURCES DEPENDS ${CMAKE_BINARY_DIR}/startup.yss diff --git a/pl/init.yap b/pl/init.yap index eb5819891..8f744b173 100644 --- a/pl/init.yap +++ b/pl/init.yap @@ -155,7 +155,7 @@ otherwise. :- [ % lists is often used. - 'yio.yap', + '../os/yio.yap', 'debug.yap', 'checker.yap', 'depth_bound.yap', diff --git a/swi/library/CMakeLists.txt b/swi/library/CMakeLists.txt index 8f75d89bd..be282d6bf 100644 --- a/swi/library/CMakeLists.txt +++ b/swi/library/CMakeLists.txt @@ -45,4 +45,4 @@ install(FILES ${LIBRARY_PL} DESTINATION ${libpl} ) - add_to_group( pl_swi_library LIBRARY_PL ) + add_to_group( LIBRARY_PL pl_library )