diff --git a/.gitignore b/.gitignore index be63e7d..45a9f32 100644 --- a/.gitignore +++ b/.gitignore @@ -364,3 +364,5 @@ FodyWeavers.xsd out/ build/ +/oct2 +/oct diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b918c1..12e3b2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,10 @@ set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules" ${CMAKE_MODULE_PATH}) project ("MEXlibCZI") +option(MEXLIBCZI_BUILD_MATLABMEX "Build mex-file for MATLAB" ON) +option(MEXLIBCZI_BUILD_OCTAVEOCT "Build oct-file for Octave" OFF) + + # include RapidJSON -> https://www.jibbow.com/posts/rapidjson-cmake/ include("${CMAKE_SOURCE_DIR}/modules/rapidJSON.cmake") @@ -28,26 +32,40 @@ FetchContent_GetProperties(libCZI) set(LIBCZI_INCLUDE_DIR "${libczi_SOURCE_DIR}/Src/libCZI") message(STATUS ${LIBCZI_INCLUDE_DIR}) -if(MEXLIBCZI_HEADERS) - set(Matlab_INCLUDE_DIRS ${MEXLIBCZI_HEADERS}) - if(UNIX) - set(Matlab_MEX_LIBRARY ${MEXLIBCZI_LIBS}/libmex.so) - set(Matlab_MX_LIBRARY ${MEXLIBCZI_LIBS}/libmx.so) - else() - set(Matlab_MEX_LIBRARY ${MEXLIBCZI_LIBS}/libmex.lib) - set(Matlab_MX_LIBRARY ${MEXLIBCZI_LIBS}/libmx.lib) - endif() -else() - find_package(Matlab REQUIRED) +if(MEXLIBCZI_BUILD_MATLABMEX) + if(MEXLIBCZI_HEADERS) + set(Matlab_INCLUDE_DIRS ${MEXLIBCZI_HEADERS}) + if(UNIX) + set(Matlab_MEX_LIBRARY ${MEXLIBCZI_LIBS}/libmex.so) + set(Matlab_MX_LIBRARY ${MEXLIBCZI_LIBS}/libmx.so) + else() + set(Matlab_MEX_LIBRARY ${MEXLIBCZI_LIBS}/libmex.lib) + set(Matlab_MX_LIBRARY ${MEXLIBCZI_LIBS}/libmx.lib) + endif() + else() + find_package(Matlab REQUIRED) + endif() + + message("########################################") + message(STATUS "Matlab_ROOT_DIR: " ${Matlab_ROOT_DIR}) + message(STATUS "Matlab_INCLUDE_DIR: " ${Matlab_INCLUDE_DIRS}) + message(STATUS "Matlab_MEX_LIBRARY: " ${Matlab_MEX_LIBRARY}) + message(STATUS "Matlab_MX_LIBRARY: " ${Matlab_MX_LIBRARY}) + message(STATUS "Matlab_LIBRARIES: " ${Matlab_LIBRARIES}) + message("########################################") endif() -message("########################################") -message(STATUS "Matlab_ROOT_DIR: " ${Matlab_ROOT_DIR}) -message(STATUS "Matlab_INCLUDE_DIR: " ${Matlab_INCLUDE_DIRS}) -message(STATUS "Matlab_MEX_LIBRARY: " ${Matlab_MEX_LIBRARY}) -message(STATUS "Matlab_MX_LIBRARY: " ${Matlab_MX_LIBRARY}) -message(STATUS "Matlab_LIBRARIES: " ${Matlab_LIBRARIES}) -message("########################################") +if(MEXLIBCZI_BUILD_OCTAVEOCT) + set(OCTAVE_ROOT_DIR "D:/SW/octave-9.2.0-w64") + set(OCTAVE_CONFIGEXECUTABLE_PATHHINT "D:/SW/octave-9.2.0-w64/mingw64/bin/") + find_package(Octave REQUIRED) + message("########################################") + message(STATUS "Octave_INCLUDE_DIRS: " ${OCTAVE_INCLUDE_DIRS}) + message(STATUS "Octave_LIBRARIES: " ${OCTAVE_LIBRARIES}) + message("########################################") +endif() + + #[[ diff --git a/CMakeSettings.json b/CMakeSettings.json index ee45e82..af99d3d 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -10,7 +10,18 @@ "cmakeCommandArgs": "", "buildCommandArgs": "", "ctestCommandArgs": "", - "variables": [] + "variables": [ + { + "name": "MEXLIBCZI_BUILD_MATLABMEX", + "value": "False", + "type": "BOOL" + }, + { + "name": "MEXLIBCZI_BUILD_OCTAVEOCT", + "value": "True", + "type": "BOOL" + } + ] }, { "name": "x64-Release", @@ -21,8 +32,47 @@ "cmakeCommandArgs": "", "buildCommandArgs": "", "ctestCommandArgs": "", - "inheritEnvironments": [ "msvc_x64_x64" ], - "variables": [] + "inheritEnvironments": [ "msvc_x64_x64" ] + }, + { + "name": "Mingw64-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "buildCommandArgs": "-v", + "ctestCommandArgs": "", + "inheritEnvironments": [ "mingw_64" ], + "environments": [ + { + "MINGW64_ROOT": "D:\\SW\\msys64\\ucrt64", + "BIN_ROOT": "${env.MINGW64_ROOT}/bin", + "FLAVOR": "x86_64-w64-ucrt64", + "TOOLSET_VERSION": "9.1.0", + "PATH": "${env.MINGW64_ROOT}/bin;${env.MINGW64_ROOT}/../usr/local/bin;${env.MINGW64_ROOT}/../usr/bin;${env.MINGW64_ROOT}/../bin;${env.PATH}", + "INCLUDE": "${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION};${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION}/tr1;${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION}/${env.FLAVOR}", + "environment": "mingw_64" + } + ], + "variables": [ + { + "name": "CMAKE_C_COMPILER", + "value": "${env.BIN_ROOT}/gcc.exe", + "type": "STRING" + }, + { + "name": "CMAKE_CXX_COMPILER", + "value": "${env.BIN_ROOT}/g++.exe", + "type": "STRING" + }, + { + "name": "MEXLIBCZI_BUILD_MATLABMEX", + "value": "False", + "type": "BOOL" + } + ], + "intelliSenseMode": "linux-gcc-x64", + "cmakeCommandArgs": "-DMEXLIBCZI_BUILD_MATLABMEX=OFF -DMEXLIBCZI_BUILD_OCTAVEOCT=ON" } ] } \ No newline at end of file diff --git a/MEXlibCZI/CMakeLists.txt b/MEXlibCZI/CMakeLists.txt index 9c8a096..d7fd3d7 100644 --- a/MEXlibCZI/CMakeLists.txt +++ b/MEXlibCZI/CMakeLists.txt @@ -77,36 +77,65 @@ set(mexoctaveSourceFiles "src/include_rapidjson.h" ) -add_library (MEXlibCZI SHARED - ${mexoctaveSourceFiles}) +if(MEXLIBCZI_BUILD_MATLABMEX) + add_library (MEXlibCZI SHARED + ${mexoctaveSourceFiles}) -set_target_properties(MEXlibCZI PROPERTIES CXX_STANDARD 17) + set_target_properties(MEXlibCZI PROPERTIES CXX_STANDARD 17) -target_include_directories(MEXlibCZI PRIVATE ${Matlab_INCLUDE_DIRS} ${RAPIDJSON_INCLUDE_DIR}) + target_include_directories(MEXlibCZI PRIVATE ${Matlab_INCLUDE_DIRS} ${RAPIDJSON_INCLUDE_DIR}) -target_include_directories(MEXlibCZI PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # this is necessary so that we can find "wllczi_Config.h" which we created above -target_include_directories(MEXlibCZI PRIVATE ${LIBCZI_INCLUDE_DIR}) -target_link_libraries(MEXlibCZI PRIVATE ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY}) -target_link_libraries(MEXlibCZI PRIVATE libCZIStatic JxrDecodeStatic) + target_include_directories(MEXlibCZI PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # this is necessary so that we can find "wllczi_Config.h" which we created above + target_include_directories(MEXlibCZI PRIVATE ${LIBCZI_INCLUDE_DIR}) + target_link_libraries(MEXlibCZI PRIVATE ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY}) + target_link_libraries(MEXlibCZI PRIVATE libCZIStatic JxrDecodeStatic) -if(WIN32) - set_target_properties(MEXlibCZI PROPERTIES SUFFIX ".mexw64") -elseif(UNIX) - set_target_properties(MEXlibCZI PROPERTIES SUFFIX ".mexa64") - target_link_options(MEXlibCZI PRIVATE -static-libgcc -static-libstdc++ ) - set_target_properties(MEXlibCZI PROPERTIES PREFIX "") # otherwise "lib" is prepended -endif() + if(WIN32) + set_target_properties(MEXlibCZI PROPERTIES SUFFIX ".mexw64") + elseif(UNIX) + set_target_properties(MEXlibCZI PROPERTIES SUFFIX ".mexa64") + target_link_options(MEXlibCZI PRIVATE -static-libgcc -static-libstdc++ ) + set_target_properties(MEXlibCZI PROPERTIES PREFIX "") # otherwise "lib" is prepended + endif() -SET_TARGET_PROPERTIES (MEXlibCZI PROPERTIES DEFINE_SYMBOL "MATLABMEXBUILD") + SET_TARGET_PROPERTIES (MEXlibCZI PROPERTIES DEFINE_SYMBOL "MATLABMEXBUILD") -# this definition is necessary so that "mexFunction" is exported -target_compile_definitions(MEXlibCZI PRIVATE MW_NEEDS_VERSION_H=1) + # this definition is necessary so that "mexFunction" is exported + target_compile_definitions(MEXlibCZI PRIVATE MW_NEEDS_VERSION_H=1) -if(WIN32) - target_compile_definitions(MEXlibCZI PRIVATE _WIN32API=1) + if(WIN32) + target_compile_definitions(MEXlibCZI PRIVATE _WIN32API=1) + endif() endif() - #------------------------------------------------------------------------------------------ +if(MEXLIBCZI_BUILD_OCTAVEOCT) + add_library (OctlibCZI SHARED + ${mexoctaveSourceFiles}) + + set_target_properties(OctlibCZI PROPERTIES CXX_STANDARD 17) + target_include_directories(OctlibCZI PRIVATE ${OCTAVE_INCLUDE_DIRS} ${RAPIDJSON_INCLUDE_DIR}) + + target_include_directories(OctlibCZI PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # this is necessary so that we can find "wllczi_Config.h" which we created above + target_include_directories(OctlibCZI PRIVATE ${LIBCZI_INCLUDE_DIR}) + target_include_directories(OctlibCZI PRIVATE "D:/SW/octave-9.2.0-w64/mingw64/include/octave-9.2.0/octave") + target_include_directories(OctlibCZI PRIVATE "/d/SW/octave-9.2.0-w64/mingw64/include/octave-9.2.0/octave") + target_link_libraries(OctlibCZI PRIVATE libCZIStatic JxrDecodeStatic) + SET_TARGET_PROPERTIES(OctlibCZI PROPERTIES DEFINE_SYMBOL "OCTAVEBUILD") + #target_link_libraries(OctlibCZI PRIVATE ${OCTAVE_OCTINTERP_LIBRARY} ) + target_link_libraries(OctlibCZI PRIVATE "/d/SW/octave-9.2.0-w64/mingw64/lib/octave/9.2.0/liboctinterp.dll.a") + message(STATUS "OCTAVE_OCTINTERP_LIBRARY: " ${OCTAVE_OCTINTERP_LIBRARY}) + set_target_properties(OctlibCZI PROPERTIES PREFIX "") # otherwise "lib" is prepended + + if(WIN32) + target_compile_definitions(OctlibCZI PRIVATE _WIN32API=1) + endif() + + target_link_libraries(OctlibCZI PUBLIC pthread) + + set_target_properties(OctlibCZI PROPERTIES SUFFIX ".mex") +endif() + + #[[ add_library (OctlibCZI SHARED diff --git a/MEXlibCZI/mexFunction.cpp b/MEXlibCZI/mexFunction.cpp index c136c3f..1f80364 100644 --- a/MEXlibCZI/mexFunction.cpp +++ b/MEXlibCZI/mexFunction.cpp @@ -29,7 +29,7 @@ static void Initialize() therefore no cleanup happens here). - here it is stated that the same happens if pressing "Ctrl-C" -> https://www.mathworks.com/help/matlab/matlab_external/automatic-cleanup-of-temporary-arrays.html */ -void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) +extern "C" void __declspec(dllexport) mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { if (!gIsInitialized) { diff --git a/MEXlibCZI/src/CziReader.cpp b/MEXlibCZI/src/CziReader.cpp index f41a790..e81c740 100644 --- a/MEXlibCZI/src/CziReader.cpp +++ b/MEXlibCZI/src/CziReader.cpp @@ -32,7 +32,7 @@ MexArray* CziReader::GetScalingAsMatlabStruct() { static const char* fieldNames[] = { "scaleX", "scaleY", "scaleZ" }; - static const mwSize dims[2] = { 1, 1 }; + static const size_t dims[2] = { 1, 1 }; auto mexApi = MexApi::GetInstance(); auto* s = mexApi.MxCreateStructArray( 2, @@ -201,7 +201,7 @@ MexArray* CziReader::GetMultiChannelScalingTileComposite(const libCZI::IntRect& vecBm.data(), dsplHlp.GetChannelInfosArray()); - mwSize dims[3] = { bitmap->GetHeight(), bitmap->GetWidth(), 3 }; + size_t dims[3] = { bitmap->GetHeight(), bitmap->GetWidth(), 3 }; auto mexApi = MexApi::GetInstance(); //auto* arr = mxCreateNumericArray(3, dims, mxUINT8_CLASS, mxREAL); auto* arr = mexApi.MxCreateNumericArray(3, dims, mxUINT8_CLASS, mxREAL); @@ -219,7 +219,7 @@ MexArray* CziReader::GetMultiChannelScalingTileCompositeAllChannelsDisabled(cons const auto sizeResult = accessor->CalcSize(roi, zoom); RgbFloatColor color{ 0,0,0 }; - mwSize dims[3] = { sizeResult.h, sizeResult.w, 3 }; + size_t dims[3] = { sizeResult.h, sizeResult.w, 3 }; //auto* arr = mxCreateNumericArray(3, dims, mxUINT8_CLASS, mxREAL); auto* arr = MexApi::GetInstance().MxCreateNumericArray(3, dims, mxUINT8_CLASS, mxREAL); return arr; diff --git a/MEXlibCZI/src/mexapi.cpp b/MEXlibCZI/src/mexapi.cpp index 3e7d1bc..67b33c8 100644 --- a/MEXlibCZI/src/mexapi.cpp +++ b/MEXlibCZI/src/mexapi.cpp @@ -11,7 +11,6 @@ using namespace std; return MexApi::instance; } -#if defined(MATLABMEXBUILD) double* MexApi::MxGetDoubles(const MexArray* pArr) { @@ -50,7 +49,7 @@ std::int32_t* MexApi::MxGetInt32s(const MexArray* pArr) bool* MexApi::MxGetLogicals(const MexArray* pArr) { - return mxGetLogicals((const mxArray*)pArr); + return (bool*)mxGetLogicals((const mxArray*)pArr); } std::uint32_t* MexApi::MxGetUint32s(const MexArray* pArr) @@ -134,7 +133,7 @@ MexArray* MexApi::MxCreateNumericMatrix(size_t m, size_t n, mxClassID classid, m MexArray* MexApi::MxCreateNumericArray(size_t ndim, const size_t* dims, mxClassID classid, mxComplexity flag) { - return (MexArray*)mxCreateNumericArray(ndim, dims, classid, flag); + return (MexArray*)mxCreateNumericArray(ndim, (const mwSize*)dims, classid, flag); } void MexApi::MxSetFieldByNumber(MexArray* pa, size_t i, int fieldnum, MexArray* value) @@ -144,7 +143,7 @@ void MexApi::MxSetFieldByNumber(MexArray* pa, size_t i, int fieldnum, MexArray* MexArray* MexApi::MxCreateStructArray(size_t ndim, const size_t* dims, int nfields, const char** fieldnames) { - return (MexArray*)mxCreateStructArray(ndim, dims, nfields, fieldnames); + return (MexArray*)mxCreateStructArray(ndim, (const mwSize*)dims, nfields, fieldnames); } @@ -214,56 +213,3 @@ const MexArray* MexApi::MxGetField(const MexArray* pArr, const char* fieldname) return (const MexArray*)mxGetField((const mxArray*)pArr, 0, fieldname); } -#elif defined(OCTAVEMEXBUILD) - -double* MexApi::MxGetDoubles(const mxArray* pArr) -{ - return (double*)mxGetData(pArr); -} - -float* MexApi::MxGetSingles(const mxArray* pArr) -{ - return (float*)mxGetData(pArr); -} - -std::int8_t* MexApi::MxGetInt8s(const mxArray* pArr) -{ - return (int8_T*)mxGetData(pArr); -} - -std::uint8_t* MexApi::MxGetUint8s(const mxArray* pArr) -{ - return (uint8_T*)mxGetData(pArr); -} - -std::int16_t* MexApi::MxGetInt16s(const mxArray* pArr) -{ - return (int16_T*)mxGetData(pArr); -} - -std::uint16_t* MexApi::MxGetUint16s(const mxArray* pArr) -{ - return (uint16_T*)mxGetData(pArr); -} - -std::int32_t* MexApi::MxGetInt32s(const mxArray* pArr) -{ - return (int32_T*)mxGetData(pArr); -} - -std::uint32_t* MexApi::MxGetUint32s(const mxArray* pArr) -{ - return (uint32_T*)mxGetData(pArr); -} - -std::int64_t* MexApi::MxGetInt64s(const mxArray* pArr) -{ - return (int64_T*)mxGetData(pArr); -} - -std::uint64_t* MexApi::MxGetUint64s(const mxArray* pArr) -{ - return (uint64_T*)mxGetData(pArr); -} - -#endif \ No newline at end of file diff --git a/MEXlibCZI/src/mexapi.h b/MEXlibCZI/src/mexapi.h index d2c3d1b..845b975 100644 --- a/MEXlibCZI/src/mexapi.h +++ b/MEXlibCZI/src/mexapi.h @@ -1,10 +1,11 @@ #pragma once -#include "../include_matlabheaders.h" #include #include #include +#include "../include_matlabheaders.h" + class MexArray; class MexApi @@ -90,7 +91,10 @@ class MexApi ); }; -#if defined(HAVE_OCTAVE) + + + +#if defined(OCTAVEBUILD) inline double* mxGetDoubles(const mxArray* pArr) { @@ -146,4 +150,5 @@ inline char* mxArrayToUTF8String(const mxArray* pArr) return mxArrayToString(pArr); } + #endif \ No newline at end of file diff --git a/MEXlibCZI/src/utils.cpp b/MEXlibCZI/src/utils.cpp index fc42c65..69ec5ef 100644 --- a/MEXlibCZI/src/utils.cpp +++ b/MEXlibCZI/src/utils.cpp @@ -249,7 +249,7 @@ class Converters // ---------------------------------------------------------------------------- -/*static*/mwSize MexUtils::Dims_1_by_1[2] = { 1, 1 }; +/*static*/size_t MexUtils::Dims_1_by_1[2] = { 1, 1 }; /*static*/MexArray* MexUtils::FloatTo1x1Matrix(float v) { diff --git a/MEXlibCZI/src/utils.h b/MEXlibCZI/src/utils.h index 1cd4b7d..4a3a80c 100644 --- a/MEXlibCZI/src/utils.h +++ b/MEXlibCZI/src/utils.h @@ -25,7 +25,7 @@ class Utils class MexUtils { public: - static mwSize Dims_1_by_1[2]; + static size_t Dims_1_by_1[2]; static MexArray* FloatTo1x1Matrix(float v); static MexArray* DoubleTo1x1Matrix(double v); static MexArray* Int32To1x1Matrix(int v); diff --git a/modules/FindOctave.cmake b/modules/FindOctave.cmake index a210ef8..915b0cd 100644 --- a/modules/FindOctave.cmake +++ b/modules/FindOctave.cmake @@ -2,7 +2,7 @@ # GNU Octave is a high-level interpreted language, primarily intended for numerical computations. # available at http://www.gnu.org/software/octave/ # -# This module defines: +# This module defines: # OCTAVE_EXECUTABLE - octave interpreter # OCTAVE_INCLUDE_DIRS - include path for mex.h, mexproto.h # OCTAVE_LIBRARIES - required libraries: octinterp, octave, cruft @@ -16,32 +16,36 @@ # 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 +# 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_FILE_DIR ${OCTAVE_ROOT_DIR} ${OCTAVE_OCT_FILE_DIR} ) +# file (RELATIVE_PATH PKG_OCTAVE_OCT_SITE_DIR ${OCTAVE_ROOT_DIR} ${OCTAVE_OCT_SITE_DIR}) # install ( # TARGETS target_name -# DESTINATION ${PKG_OCTAVE_OCT_FILE_DIR} -# ) +# 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: -# +# 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. +# 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. +# 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 @@ -54,114 +58,137 @@ # (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, +# 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 + +find_program(OCTAVE_CONFIG_EXECUTABLE HINTS ${OCTAVE_CONFIGEXECUTABLE_PATHHINT} NAMES octave-config - ) -if ( OCTAVE_CONFIG_EXECUTABLE ) - execute_process ( COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p PREFIX + ) + + +if (OCTAVE_CONFIG_EXECUTABLE) + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTAVE_HOME OUTPUT_VARIABLE OCTAVE_ROOT_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE ) + OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process ( COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p BINDIR + 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 ) + OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process ( COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTINCLUDEDIR + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTINCLUDEDIR OUTPUT_VARIABLE OCTAVE_INCLUDE_PATHS - OUTPUT_STRIP_TRAILING_WHITESPACE ) + OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process ( COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR OUTPUT_VARIABLE OCTAVE_LIBRARIES_PATHS - OUTPUT_STRIP_TRAILING_WHITESPACE ) + OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process ( COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTFILEDIR + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTFILEDIR OUTPUT_VARIABLE OCTAVE_OCT_FILE_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE ) + OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process ( COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR OUTPUT_VARIABLE OCTAVE_OCT_LIB_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE ) + OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process ( COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -v + execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -v OUTPUT_VARIABLE OCTAVE_VERSION_STRING - OUTPUT_STRIP_TRAILING_WHITESPACE ) + 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} ) + 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 + + +find_program(OCTAVE_EXECUTABLE HINTS ${OCTAVE_BIN_PATHS} NAMES octave - ) -find_library( OCTAVE_OCTINTERP_LIBRARY + ) + +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 + ) +find_library(OCTAVE_OCTAVE_LIBRARY NAMES octave liboctave HINTS ${OCTAVE_LIBRARIES_PATHS} - ) -find_library( OCTAVE_CRUFT_LIBRARY + ) +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} ) +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}/.." + ) + +if (OCTAVE_INCLUDE_DIR) + set (OCTAVE_INCLUDE_DIRS ${OCTAVE_INCLUDE_DIR} ${OCTAVE_INCLUDE_DIR}/octave) endif () -find_path ( OCTAVE_INCLUDE_DIR - NAMES mex.h - HINTS ${OCTAVE_INCLUDE_PATHS} - ) -set ( OCTAVE_INCLUDE_DIRS ${OCTAVE_INCLUDE_DIR} ) -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 ) +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} ) + 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 + 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 () +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (Octave REQUIRED_VARS OCTAVE_EXECUTABLE OCTAVE_ROOT_DIR OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES VERSION_VAR OCTAVE_VERSION_STRING) + + mark_as_advanced ( OCTAVE_OCT_FILE_DIR OCTAVE_OCT_LIB_DIR @@ -176,4 +203,4 @@ mark_as_advanced ( OCTAVE_MAJOR_VERSION OCTAVE_MINOR_VERSION OCTAVE_PATCH_VERSION -) +) \ No newline at end of file