Skip to content

Commit

Permalink
Do not link to python in conda (#4068) (#4073)
Browse files Browse the repository at this point in the history
* Do not link to python in conda (closes #4068)
* Update FindOctave
  • Loading branch information
lisitsyn committed Jan 8, 2018
1 parent 6f1fd16 commit ff8840c
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 122 deletions.
320 changes: 205 additions & 115 deletions cmake/FindOctave.cmake
@@ -1,117 +1,207 @@
# Try to find the build flags to compile octave shared objects (oct and mex files)
# Once done this will define
# - Find Octave
# GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
# available at http://www.gnu.org/software/octave/
#
# MKOCTFILE_EXECUTABLE - mkoctfile executable
# OCTAVE_API_VERSION - octave api version
# OCTAVE_CONFIG_EXECUTABLE - octave-config executable
# OCTAVE_EXECUTABLE - octave interpreter
# OCTAVE_FOUND - if Octave is found
# OCTAVE_CXXFLAGS - extra flags
# OCTAVE_INCLUDE_DIRS - include directories
# OCTAVE_LINK_DIRS - link directories
# OCTAVE_LIBRARY_RELEASE - the release version
# OCTAVE_LIBRARY_DEBUG - the debug version
# OCTAVE_LIBRARY - a default library, with priority debug.
# OCTAVE_OCT_LOCAL_API_FILE_DIR - installation directory

# find octave-config-executable
set(OCTAVE_CONFIG_EXECUTABLE OCTAVE_CONFIG_EXECUTABLE-NOTFOUND)
find_program(OCTAVE_CONFIG_EXECUTABLE NAMES octave-config octave-config-3.2.4)

# use mkoctfile
set(MKOCTFILE_EXECUTABLE MKOCTFILE_EXECUTABLE-NOTFOUND)
find_program(MKOCTFILE_EXECUTABLE NAME mkoctfile PATHS)

if(OCTAVE_CONFIG_EXECUTABLE AND MKOCTFILE_EXECUTABLE)
set(OCTAVE_FOUND 1)

execute_process ( COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p LOCALAPIOCTFILEDIR
OUTPUT_VARIABLE OCTAVE_OCT_LOCAL_API_FILE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE )

execute_process ( COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p API_VERSION
OUTPUT_VARIABLE OCTAVE_API_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE )
STRING(REGEX REPLACE "[a-z\\+-]" "" OCTAVE_API_VERSION ${OCTAVE_API_VERSION})

execute_process ( COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -v
OUTPUT_VARIABLE OCTAVE_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE )

find_program(OCTAVE_EXECUTABLE NAMES octave octave-3.2.4)

message(STATUS "Found Octave: ${OCTAVE_EXECUTABLE}")
message(STATUS "Octave-version: ${OCTAVE_VERSION_STRING}")
message(STATUS "Octave-API: ${OCTAVE_API_VERSION}")
message(STATUS "Octave-installdir: ${OCTAVE_OCT_LOCAL_API_FILE_DIR}")

execute_process(
COMMAND ${MKOCTFILE_EXECUTABLE} -p ALL_CXXFLAGS
OUTPUT_VARIABLE _mkoctfile_cppflags
RESULT_VARIABLE _mkoctfile_failed)
string(REGEX REPLACE "[\r\n]" " " _mkoctfile_cppflags "${_mkoctfile_cppflags}")
execute_process(
COMMAND ${MKOCTFILE_EXECUTABLE} -p INCFLAGS
OUTPUT_VARIABLE _mkoctfile_includedir
RESULT_VARIABLE _mkoctfile_failed)
string(REGEX REPLACE "[\r\n]" " " _mkoctfile_includedir "${_mkoctfile_includedir}")
execute_process(
COMMAND ${MKOCTFILE_EXECUTABLE} -p ALL_LDFLAGS
OUTPUT_VARIABLE _mkoctfile_ldflags
RESULT_VARIABLE _mkoctfile_failed)
string(REGEX REPLACE "[\r\n]" " " _mkoctfile_ldflags "${_mkoctfile_ldflags}")
execute_process(
COMMAND ${MKOCTFILE_EXECUTABLE} -p LFLAGS
OUTPUT_VARIABLE _mkoctfile_lflags
RESULT_VARIABLE _mkoctfile_failed)
string(REGEX REPLACE "[\r\n]" " " _mkoctfile_lflags "${_mkoctfile_lflags}")
execute_process(
COMMAND ${MKOCTFILE_EXECUTABLE} -p LIBS
OUTPUT_VARIABLE _mkoctfile_libs
RESULT_VARIABLE _mkoctfile_failed)
string(REGEX REPLACE "[\r\n]" " " _mkoctfile_libs "${_mkoctfile_libs}")
execute_process(
COMMAND ${MKOCTFILE_EXECUTABLE} -p OCTAVE_LIBS
OUTPUT_VARIABLE _mkoctfile_octlibs
RESULT_VARIABLE _mkoctfile_failed)
string(REGEX REPLACE "[\r\n]" " " _mkoctfile_octlibs "${_mkoctfile_octlibs}")
set(_mkoctfile_libs "${_mkoctfile_libs} ${_mkoctfile_octlibs}")

string(REGEX MATCHALL "(^| )-l([./+-_\\a-zA-Z]*)" _mkoctfile_libs "${_mkoctfile_libs}")
string(REGEX REPLACE "(^| )-l" "" _mkoctfile_libs "${_mkoctfile_libs}")

string(REGEX MATCHALL "(^| )-L([./+-_\\a-zA-Z]*)" _mkoctfile_ldirs "${_mkoctfile_lflags}")
string(REGEX REPLACE "(^| )-L" "" _mkoctfile_ldirs "${_mkoctfile_ldirs}")

string(REGEX REPLACE "(^| )-l([./+-_\\a-zA-Z]*)" " " _mkoctfile_ldflags "${_mkoctfile_ldflags}")
string(REGEX REPLACE "(^| )-L([./+-_\\a-zA-Z]*)" " " _mkoctfile_ldflags "${_mkoctfile_ldflags}")

string(REGEX REPLACE "(^| )-I" " " _mkoctfile_includedir "${_mkoctfile_includedir}")

separate_arguments(_mkoctfile_includedir)

set( OCTAVE_CXXFLAGS "${_mkoctfile_cppflags}" )
set( OCTAVE_LINK_FLAGS "${_mkoctfile_ldflags}" )
set( OCTAVE_INCLUDE_DIRS ${_mkoctfile_includedir})
set( OCTAVE_LINK_DIRS ${_mkoctfile_ldirs})
set( OCTAVE_LIBRARY ${_mkoctfile_libs})
set( OCTAVE_LIBRARY_RELEASE ${OCTAVE_LIBRARY})
set( OCTAVE_LIBRARY_DEBUG ${OCTAVE_LIBRARY})
endif(OCTAVE_CONFIG_EXECUTABLE AND MKOCTFILE_EXECUTABLE)

MARK_AS_ADVANCED(
MKOCTFILE_EXECUTABLE
OCTAVE_API_VERSION
OCTAVE_CONFIG_EXECUTABLE
OCTAVE_EXECUTABLE
OCTAVE_LIBRARY_FOUND
OCTAVE_CXXFLAGS
OCTAVE_LINK_FLAGS
OCTAVE_INCLUDE_DIRS
OCTAVE_LINK_DIRS
OCTAVE_LIBRARY
OCTAVE_LIBRARY_RELEASE
OCTAVE_LIBRARY_DEBUG
OCTAVE_OCT_LOCAL_API_FILE_DIR
OCTAVE_VERSION_STRING
# This module defines:
# OCTAVE_EXECUTABLE - octave interpreter
# OCTAVE_INCLUDE_DIRS - include path for mex.h, mexproto.h
# OCTAVE_LIBRARIES - required libraries: octinterp, octave, cruft
# OCTAVE_OCTINTERP_LIBRARY - path to the library octinterp
# OCTAVE_OCTAVE_LIBRARY - path to the library octave
# OCTAVE_CRUFT_LIBRARY - path to the library cruft
# OCTAVE_VERSION_STRING - octave version string
# OCTAVE_MAJOR_VERSION - major version
# OCTAVE_MINOR_VERSION - minor version
# OCTAVE_PATCH_VERSION - patch version
# OCTAVE_OCT_FILE_DIR - object files that will be dynamically loaded
# OCTAVE_OCT_LIB_DIR - oct libraries
# OCTAVE_ROOT_DIR - octave prefix
# OCTAVE_M_SITE_DIR - .m files site dir
# OCTAVE_OCT_SITE_DIR - .oct files site dir
#
# The macro octave_add_oct allows to create compiled modules.
# octave_add_oct (target_name
# [SOURCES] source1 [source2 ...]
# [LINK_LIBRARIES lib1 [lib2 ...]]
# [EXTENSION ext]
#)
#
# To install it, you can the use the variable OCTAVE_OCT_FILE_DIR as follow:
# file (RELATIVE_PATH PKG_OCTAVE_OCT_SITE_DIR ${OCTAVE_ROOT_DIR} ${OCTAVE_OCT_SITE_DIR})
# install (
# TARGETS target_name
# DESTINATION ${PKG_OCTAVE_OCT_SITE_DIR}
#)


#=============================================================================
# Copyright 2013, Julien Schueller
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# The views and conclusions contained in the software and documentation are those
# of the authors and should not be interpreted as representing official policies,
# either expressed or implied, of the FreeBSD Project.
#=============================================================================

find_program(OCTAVE_CONFIG_EXECUTABLE
NAMES octave-config
)


if (OCTAVE_CONFIG_EXECUTABLE)
execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p PREFIX
OUTPUT_VARIABLE OCTAVE_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} --m-site-dir
OUTPUT_VARIABLE OCTAVE_M_SITE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} --oct-site-dir
OUTPUT_VARIABLE OCTAVE_OCT_SITE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p BINDIR
OUTPUT_VARIABLE OCTAVE_BIN_PATHS
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTINCLUDEDIR
OUTPUT_VARIABLE OCTAVE_INCLUDE_PATHS
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR
OUTPUT_VARIABLE OCTAVE_LIBRARIES_PATHS
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTFILEDIR
OUTPUT_VARIABLE OCTAVE_OCT_FILE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR
OUTPUT_VARIABLE OCTAVE_OCT_LIB_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -v
OUTPUT_VARIABLE OCTAVE_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (OCTAVE_VERSION_STRING)
string (REGEX REPLACE "([0-9]+)\\..*" "\\1" OCTAVE_MAJOR_VERSION ${OCTAVE_VERSION_STRING})
string (REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" OCTAVE_MINOR_VERSION ${OCTAVE_VERSION_STRING})
string (REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" OCTAVE_PATCH_VERSION ${OCTAVE_VERSION_STRING})
endif ()
endif ()


find_program(OCTAVE_EXECUTABLE
HINTS ${OCTAVE_BIN_PATHS}
NAMES octave
)

find_program(OCTAVE_MKOCTFILE
HINTS ${OCTAVE_BIN_PATHS}
NAMES mkoctfile
)

find_library(OCTAVE_OCTINTERP_LIBRARY
NAMES octinterp liboctinterp
HINTS ${OCTAVE_LIBRARIES_PATHS}
)
find_library(OCTAVE_OCTAVE_LIBRARY
NAMES octave liboctave
HINTS ${OCTAVE_LIBRARIES_PATHS}
)
find_library(OCTAVE_CRUFT_LIBRARY
NAMES cruft libcruft
HINTS ${OCTAVE_LIBRARIES_PATHS}
)

set (OCTAVE_LIBRARIES ${OCTAVE_OCTINTERP_LIBRARY})
list (APPEND OCTAVE_LIBRARIES ${OCTAVE_OCTAVE_LIBRARY})
if (OCTAVE_CRUFT_LIBRARY)
list (APPEND OCTAVE_LIBRARIES ${OCTAVE_CRUFT_LIBRARY})
endif ()

find_path (OCTAVE_INCLUDE_DIR
NAMES octave/oct.h
PATHS "${OCTAVE_INCLUDE_PATHS}/.."
)

set (OCTAVE_INCLUDE_DIRS ${OCTAVE_INCLUDE_DIR} ${OCTAVE_INCLUDE_DIR}/octave)


macro (octave_add_oct FUNCTIONNAME)
set (_CMD SOURCES)
set (_SOURCES)
set (_LINK_LIBRARIES)
set (_EXTENSION)
set (_OCT_EXTENSION oct)
foreach (_ARG ${ARGN})
if (${_ARG} MATCHES SOURCES)
set (_CMD SOURCES)
elseif (${_ARG} MATCHES LINK_LIBRARIES)
set (_CMD LINK_LIBRARIES)
elseif (${_ARG} MATCHES EXTENSION)
set (_CMD EXTENSION)
else ()
if (${_CMD} MATCHES SOURCES)
list (APPEND _SOURCES "${_ARG}")
elseif (${_CMD} MATCHES LINK_LIBRARIES)
list (APPEND _LINK_LIBRARIES "${_ARG}")
elseif (${_CMD} MATCHES EXTENSION)
set (_OCT_EXTENSION ${_ARG})
endif ()
endif ()
endforeach ()
add_library (${FUNCTIONNAME} SHARED ${_SOURCES})
target_link_libraries (${FUNCTIONNAME} ${OCTAVE_LIBRARIES} ${_LINK_LIBRARIES})
set_target_properties (${FUNCTIONNAME} PROPERTIES
PREFIX ""
SUFFIX ".${_OCT_EXTENSION}"
)
endmacro ()


# handle REQUIRED and QUIET options
include (FindPackageHandleStandardArgs)
if (CMAKE_VERSION LESS 2.8.3)
find_package_handle_standard_args (Octave DEFAULT_MSG OCTAVE_EXECUTABLE OCTAVE_ROOT_DIR OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES OCTAVE_VERSION_STRING)
else ()
find_package_handle_standard_args (Octave REQUIRED_VARS OCTAVE_EXECUTABLE OCTAVE_ROOT_DIR OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES VERSION_VAR OCTAVE_VERSION_STRING)
endif ()


mark_as_advanced (
OCTAVE_OCT_FILE_DIR
OCTAVE_OCT_LIB_DIR
OCTAVE_OCTINTERP_LIBRARY
OCTAVE_OCTAVE_LIBRARY
OCTAVE_CRUFT_LIBRARY
OCTAVE_LIBRARIES
OCTAVE_INCLUDE_DIR
OCTAVE_INCLUDE_DIRS
OCTAVE_ROOT_DIR
OCTAVE_VERSION_STRING
OCTAVE_MAJOR_VERSION
OCTAVE_MINOR_VERSION
OCTAVE_PATCH_VERSION
)
10 changes: 7 additions & 3 deletions cmake/ShogunInterfaces.cmake
Expand Up @@ -43,18 +43,22 @@ IF(DEFINED TARGET_SWIGFLAGS)
ENDIF()
SET(SWIG_MODULE_${INTERFACE_NAME}_EXTRA_DEPS ${INTERFACE_FILES})
SWIG_ADD_MODULE(${INTERFACE_TARGET} ${INTERFACE_NAME} shogun.i sg_print_functions.cpp)
SET(INTERFACE_REAL_NAME ${SWIG_MODULE_interface_${INTERFACE_NAME}_REAL_NAME})

IF (WIN32)
SWIG_LINK_LIBRARIES(${INTERFACE_TARGET} shogun::shogun-static ${INTERFACE_LIBRARIES})
SWIG_LINK_LIBRARIES(${INTERFACE_TARGET} shogun::shogun-static)
ELSE ()
SWIG_LINK_LIBRARIES(${INTERFACE_TARGET} shogun::shogun ${INTERFACE_LIBRARIES})
SWIG_LINK_LIBRARIES(${INTERFACE_TARGET} shogun::shogun)
ENDIF ()
IF (NOT "${INTERFACE_LIBRARIES}" STREQUAL "NO")

This comment has been minimized.

Copy link
@vigsterkr

vigsterkr Jan 30, 2018

Member

@lisitsyn i think this doesn't work as i've just seen this add a -lNO linking flag :)

This comment has been minimized.

Copy link
@vigsterkr

vigsterkr Jan 30, 2018

Member

see: https://jenkins.brew.sh/job/Homebrew%20Core%20Pull%20Requests/17547/version=sierra/console

20:15:05 ld: library not found for -lNO
20:15:05 clang: error: linker command failed with exit code 1 (use -v to see invocation)

This comment has been minimized.

Copy link
@lisitsyn

lisitsyn Jan 31, 2018

Author Member

Argh I was sure it works. Sorry about that

This comment has been minimized.

Copy link
@vigsterkr

vigsterkr Jan 31, 2018

Member

noup it's actually my fault... missed one part of this pathc... it works, confirmed.
(OK) stamp by me

SWIG_LINK_LIBRARIES(${INTERFACE_TARGET} ${INTERFACE_LIBRARIES})
ENDIF()

#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
# endforeach()

SET(INTERFACE_REAL_NAME ${SWIG_MODULE_interface_${INTERFACE_NAME}_REAL_NAME})
SET_TARGET_PROPERTIES(${INTERFACE_REAL_NAME} PROPERTIES OUTPUT_NAME ${PREPEND_TARGET}shogun)
ADD_DEPENDENCIES(${INTERFACE_REAL_NAME} ${INTERFACE_TARGET_SRC})

Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/octave/CMakeLists.txt
@@ -1,16 +1,16 @@
FIND_PACKAGE(Octave 3.6 REQUIRED)
SET(OCTAVE_APIVERSION ${OCTAVE_API_VERSION})
SET(OCTAVE_APIVERSION ${OCTAVE_MAJOR_VERSION})
UNSET(TARGET_SWIGFLAGS)

include(ShogunInterfaces)
include_directories(${OCTAVE_INCLUDE_DIRS})

GENERATE_INTERFACE_TARGET(octave ${CMAKE_CURRENT_SOURCE_DIR} ${OCTAVE_LIBRARY})
GENERATE_INTERFACE_TARGET(octave ${CMAKE_CURRENT_SOURCE_DIR} "${OCTAVE_LIBRARIES}")
set_target_properties(interface_octave PROPERTIES PREFIX "")
set_target_properties(interface_octave PROPERTIES SUFFIX ".oct")
target_compile_definitions(interface_octave PRIVATE "OCTAVE_APIVERSION=${OCTAVE_API_VERSION}")

SET(INTERFACE_OCTAVE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
install (TARGETS interface_octave
DESTINATION ${OCTAVE_OCT_LOCAL_API_FILE_DIR}/shogun
DESTINATION ${OCTAVE_OCT_SITE_DIR}/shogun
COMPONENT octave)

0 comments on commit ff8840c

Please sign in to comment.