diff options
Diffstat (limited to 'contrib/cmake/FindSWI.cmake')
-rw-r--r-- | contrib/cmake/FindSWI.cmake | 119 |
1 files changed, 70 insertions, 49 deletions
diff --git a/contrib/cmake/FindSWI.cmake b/contrib/cmake/FindSWI.cmake index fb30be4..1106633 100644 --- a/contrib/cmake/FindSWI.cmake +++ b/contrib/cmake/FindSWI.cmake @@ -1,5 +1,28 @@ -set (SWI_SEARCH_PATHS $ENV{SWI_DIR}) +set(64BIT_HOST OFF) +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(64BIT_HOST ON) +endif() + +set(SWI_PLATFORM_ID) +if (UNIX) + if (APPLE AND 64BIT_HOST) + set(SWI_PLATFORM_ID "x86_64-${CMAKE_SYSTEM_NAME}${CMAKE_SYSTEM_VERSION}") + else() + set(SWI_PLATFORM_ID "${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}${CMAKE_SYSTEM_VERSION}") + endif() +else() + set(SWI_PLATFORM_ID "${CMAKE_SYSTEM_PROCESSOR}-windows") +endif() + +if (SWI_PLATFORM_ID) + string(TOLOWER ${SWI_PLATFORM_ID} SWI_PLATFORM_ID) +endif() + +#message("SWI_PLATFORM_ID: ${SWI_PLATFORM_ID}") + +set (SWI_SEARCH_PATHS) list (APPEND SWI_SEARCH_PATHS + $ENV{SWI_DIR} ${CMAKE_FIND_ROOT_PATH} "/usr/lib/swi-prolog/" "/opt/local/" @@ -7,12 +30,9 @@ list (APPEND SWI_SEARCH_PATHS "C:/Program Files/swipl" ) -set(64BIT_HOST OFF) -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(64BIT_HOST ON) -endif() +#message("SWI_SEARCH_PATHS: ${SWI_SEARCH_PATHS}") -set (SWI_HOME) +set (SWI_VERSION) set (LOOP_DONE 0) foreach(SWI_SEARCH_PATH ${SWI_SEARCH_PATHS}) if(NOT LOOP_DONE) @@ -21,59 +41,58 @@ foreach(SWI_SEARCH_PATH ${SWI_SEARCH_PATHS}) set(LOOP_DONE 1) list(SORT SWI_VERSIONS) list(REVERSE SWI_VERSIONS) - list(GET SWI_VERSIONS 0 SWI_HOME) + list(GET SWI_VERSIONS 0 SWI_VERSION) + STRING(REGEX REPLACE ".*(([0-9]+).([0-9]+).([0-9]+))$" "\\1" SWI_VERSION "${SWI_VERSION}") endif() endif() endforeach() -set (SWI_PLATFORM_PATH) -set (LOOP_DONE 0) -if (SWI_HOME) +# -- find prolog headers +FIND_PATH(SWI_INCLUDE_DIR SWI-Prolog.h + PATH_SUFFIXES + include + lib/swipl-${SWI_VERSION}/include + PATHS ${SWI_SEARCH_PATHS} +) - set(SWI_CPU_SUFFIX ${CMAKE_SYSTEM_PROCESSOR}) - if (APPLE) - if (64BIT_HOST) - set(SWI_CPU_SUFFIX "x86_64") - endif() - endif() +FIND_PATH(SWI_CPP_INCLUDE_DIR SWI-cpp.h + PATH_SUFFIXES + packages/cpp + lib/swipl-${SWI_VERSION}/include + PATHS ${SWI_SEARCH_PATHS} +) - file(GLOB SWI_PLATFORMS ${SWI_HOME}/lib/*) - foreach(SWI_PLATFORM ${SWI_PLATFORMS}) - STRING(REGEX REPLACE "${SWI_HOME}/lib/" "" REL_SWI_PLATFORM ${SWI_PLATFORM}) - if(NOT LOOP_DONE) - if (REL_SWI_PLATFORM MATCHES ".*${SWI_CPU_SUFFIX}.*") - set (SWI_PLATFORM_PATH ${SWI_PLATFORM}) - set(LOOP_DONE 1) - endif() - endif() - endforeach() -endif() +FIND_PROGRAM(SWI_BINARY swipl + PATH_SUFFIXES + src + lib/swipl-${SWI_VERSION}/bin/${SWI_PLATFORM_ID} + PATHS ${SWI_SEARCH_PATHS} +) -#message(STATUS "SWI_PLATFORM_PATH: ${SWI_PLATFORM_PATH}, SWI_HOME: ${SWI_HOME}") +FIND_LIBRARY(SWI_LIBRARY_RELEASE + NAMES libswipl swipl + PATH_SUFFIXES + lib/${SWI_PLATFORM_ID} # still in source directory + lib/swipl-${SWI_VERSION}/lib/${SWI_PLATFORM_ID} # after make install + PATHS ${SWI_SEARCH_PATHS} +) -if (SWI_PLATFORM_PATH OR SWI_INCLUDE_HINT) - FIND_PATH(SWI_INCLUDE_DIR SWI-Prolog.h - PATH_SUFFIXES include - PATHS ${SWI_HOME} - HINTS ${SWI_INCLUDE_HINT} - ) - - FIND_LIBRARY(SWI_LIBRARY_RELEASE - NAMES libswipl swipl - PATHS ${SWI_PLATFORM_PATH} - HINTS ${SWI_LIBRARY_HINT} - ) +FIND_LIBRARY(SWI_LIBRARY_DEBUG + NAMES libswipl_d swipl_d + PATH_SUFFIXES + lib/${SWI_PLATFORM_ID} # still in source directory + lib/swipl-${SWI_VERSION}/lib/${SWI_PLATFORM_ID} # after make install + PATHS ${SWI_SEARCH_PATHS} +) - if (SWI_LIBRARY_RELEASE) - list(APPEND SWI_LIBRARY optimized ${SWI_LIBRARY_RELEASE}) - set(SWI_BINARY ${SWI_PLATFORM_PATH}) +if (NOT SWI_LIBRARY_DEBUG)# no explicit debug build, just reuse release + if (UNIX) + set(SWI_LIBRARY_DEBUG ${SWI_LIBRARY_RELEASE}) endif() +endif() - - FIND_LIBRARY(SWI_LIBRARY_DEBUG - NAMES libswipl_d swipl_d - PATHS ${SWI_PLATFORM_PATH} - ) +if (SWI_LIBRARY_RELEASE) + list(APPEND SWI_LIBRARY optimized ${SWI_LIBRARY_RELEASE}) if (SWI_LIBRARY_DEBUG) list(APPEND SWI_LIBRARY debug ${SWI_LIBRARY_DEBUG}) elseif(UNIX) @@ -83,6 +102,8 @@ if (SWI_PLATFORM_PATH OR SWI_INCLUDE_HINT) endif() endif() +#message(FATAL_ERROR "SWI_BINARY: ${SWI_BINARY} / SWI_LIBRARY_RELEASE: ${SWI_LIBRARY_RELEASE} / SWI_LIBRARY_DEBUG: ${SWI_LIBRARY_DEBUG} / SWI_INCLUDE_DIR: ${SWI_INCLUDE_DIR} / SWI_CPP_INCLUDE_DIR: ${SWI_CPP_INCLUDE_DIR}") + INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SWI DEFAULT_MSG SWI_LIBRARY SWI_INCLUDE_DIR SWI_BINARY) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SWI DEFAULT_MSG SWI_LIBRARY SWI_BINARY SWI_INCLUDE_DIR SWI_CPP_INCLUDE_DIR) MARK_AS_ADVANCED(SWI_LIBRARY SWI_INCLUDE_DIR) |