Skip to content

Commit

Permalink
Update cmake for lib3mf, add environment variables to search hints.
Browse files Browse the repository at this point in the history
  • Loading branch information
t-paul committed Sep 20, 2021
1 parent d06efd5 commit 531d537
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Expand Up @@ -12,8 +12,8 @@ jobs:
command: |
export NUMCPU=2
export MXEDIR=/mxe
export LIB3MF_INCLUDEPATH=/mxe/usr/i686-w64-mingw32.static.posix/include/lib3mf
export LIB3MF_LIBPATH=/mxe/usr/i686-w64-mingw32.static.posix/include/lib3mf
export LIB3MF_INCLUDEDIR=/mxe/usr/i686-w64-mingw32.static.posix/include/lib3mf
export LIB3MF_LIBDIR=/mxe/usr/i686-w64-mingw32.static.posix/lib
if [ x"${CIRCLE_BRANCH}" = xmaster ]; then export SUFFIX=""; else export SUFFIX="_$(echo ${CIRCLE_BRANCH} | sed -e 's,pull/,PR,')"; fi
export OPENSCAD_VERSION="$(date +%Y.%m.%d).ci${CIRCLE_BUILD_NUM}"
./scripts/release-common.sh -snapshot -mingw32 -v "$OPENSCAD_VERSION"
Expand Down Expand Up @@ -43,8 +43,8 @@ jobs:
command: |
export NUMCPU=2
export MXEDIR=/mxe
export LIB3MF_INCLUDEPATH=/mxe/usr/x86_64-w64-mingw32.static.posix/include/lib3mf
export LIB3MF_LIBPATH=/mxe/usr/x86_64-w64-mingw32.static.posix/include/lib3mf
export LIB3MF_INCLUDEDIR=/mxe/usr/x86_64-w64-mingw32.static.posix/include/lib3mf
export LIB3MF_LIBDIR=/mxe/usr/x86_64-w64-mingw32.static.posix/lib
if [ x"${CIRCLE_BRANCH}" = xmaster ]; then export SUFFIX=""; else export SUFFIX="_$(echo ${CIRCLE_BRANCH} | sed -e 's,pull/,PR,')"; fi
export OPENSCAD_VERSION="$(date +%Y.%m.%d).ci${CIRCLE_BUILD_NUM}"
./scripts/release-common.sh -snapshot -mingw64 -v "$OPENSCAD_VERSION"
Expand Down
10 changes: 6 additions & 4 deletions CMakeLists.txt
Expand Up @@ -312,10 +312,12 @@ message(STATUS "Bison: ${BISON_VERSION}")

if(NOT MSVC)
find_package(Lib3MF REQUIRED QUIET)
message(STATUS "lib3mf: ${LIB3MF_VERSION}")
add_definitions(${LIB3MF_CFLAGS})
include_directories(${LIB3MF_INCLUDE_DIRS})
list(APPEND COMMON_LIBRARIES ${LIB3MF_LIBRARIES})
if (LIB3MF_FOUND)
message(STATUS "lib3mf: ${LIB3MF_VERSION}")
add_definitions(${LIB3MF_CFLAGS})
include_directories(${LIB3MF_INCLUDE_DIRS})
list(APPEND COMMON_LIBRARIES ${LIB3MF_LIBRARIES})
endif()
endif()

# Use clang-tidy if run with -DCLANG_TIDY=1
Expand Down
30 changes: 22 additions & 8 deletions cmake/Modules/FindLib3MF.cmake
Expand Up @@ -13,10 +13,28 @@
# We still fall back to the rest of detection code here.
# Travis CI Ubuntu Trusty environment has some issue with pkg-config
# not finding the version.
pkg_check_modules(LIB3MF lib3MF)
find_package(PkgConfig REQUIRED QUIET)
pkg_check_modules(PC_LIB3MF lib3MF)
set(LIB3MF_VERSION ${PC_LIB3MF_VERSION})

find_path(LIB3MF_INCLUDE_DIRS
NAMES Model/COM/NMR_DLLInterfaces.h
HINTS $ENV{LIB3MF_INCLUDEDIR}
${PC_LIB3MF_INCLUDEDIR}
${PC_LIB3MF_INCLUDE_DIRS}
PATH_SUFFIXES lib3mf
)

find_library(LIB3MF_LIBRARIES
NAMES 3mf 3MF
HINTS $ENV{LIB3MF_LIBDIR}
${PC_LIB3MF_LIBDIR}
${PC_LIB3MF_LIBRARY_DIRS}
)

# default to uppercase for 1.0 library name
set(LIB3MF_LIB "3MF")
set(LIB3MF_API "API 1.x")

# some distribution packages are missing version information for 2.0
if (LIB3MF_VERSION STREQUAL "" AND LIB3MF_FOUND)
Expand All @@ -25,10 +43,6 @@ if (LIB3MF_VERSION STREQUAL "" AND LIB3MF_FOUND)
endif()
endif()

if (LIB3MF_VERSION VERSION_EQUAL 1.8.1 OR LIB3MF_VERSION VERSION_GREATER 1.8.1)
set(LIB3MF_API "API 1.x")
endif()

if (LIB3MF_VERSION VERSION_EQUAL 2.0.0 OR LIB3MF_VERSION VERSION_GREATER 2.0.0)
set(LIB3MF_API "API 2.x")
set(LIB3MF_LIB "3mf")
Expand All @@ -43,7 +57,7 @@ if (NOT $ENV{OPENSCAD_LIBRARIES} STREQUAL "")
endif()
endif()

if ("${LIB3MF_LIBDIR}" STREQUAL "")
if ("${LIB3MF_LIBRARIES}" STREQUAL "")
if (EXISTS "/opt/include/lib3mf/Model/COM/NMR_DLLInterfaces.h")
set(LIB3MF_INCLUDE_DIRS "/opt/include/lib3mf" "/opt/include/lib3mf/Model/COM")
set(LIB3MF_LIBDIR "/opt/lib")
Expand All @@ -60,10 +74,10 @@ if ("${LIB3MF_LIBDIR}" STREQUAL "")
endif()
endif()

if (NOT ${LIB3MF_LIBDIR} STREQUAL "")
if (NOT "${LIB3MF_LIBRARIES}" STREQUAL "")
find_library(LIBZ_LIBRARY NAMES z)
find_library(LIBZIP_LIBRARY NAMES zip)
set(LIB3MF_LIBRARIES "-L${LIB3MF_LIBDIR}" "-l${LIB3MF_LIB} ${LIBZIP_LIBRARY} ${LIBZ_LIBRARY}")
set(LIB3MF_LIBRARIES "${LIB3MF_LIBRARIES}" "${LIBZIP_LIBRARY}" "${LIBZ_LIBRARY}")
set(LIB3MF_CFLAGS "-D__GCC -DENABLE_LIB3MF")
set(LIB3MF_FOUND TRUE)
else()
Expand Down

0 comments on commit 531d537

Please sign in to comment.