Skip to content

Commit

Permalink
feat: add CMake support for OpenNURBS
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Nov 16, 2021
1 parent eaefb63 commit 7540aaf
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
97 changes: 97 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
cmake_minimum_required(VERSION 3.15)

project(OpenNURBS CXX C)

# OpenNURBS source
file(GLOB OpenNURBS_SOURCE "${CMAKE_SOURCE_DIR}/*.h"
"${CMAKE_SOURCE_DIR}/*.cpp")

# Build the opennurbs library
if(RW3DM_BUILD_ON_DLL)
# if dynamic

# Cannot build as shared library on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(
FATAL_ERROR
"Building OpenNURBS as a shared library is not supported on Linux")
endif()

# Generate a shared library
add_library(opennurbs SHARED ${OpenNURBS_SOURCE})
set_target_properties(opennurbs PROPERTIES DEBUG_POSTFIX "d")

# define opennurbs_EXPORTS
target_compile_definitions(opennurbs PRIVATE opennurbs_EXPORTS)

# Install opennurbs DLL
install(TARGETS opennurbs DESTINATION ${RW3DM_INSTALL_DIR})
else()
# if static

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_library(opennurbs STATIC ${OpenNURBS_SOURCE})
else()
# Include UUID source (bundled with opennurbs)
file(GLOB UUID_SRC "${CMAKE_SOURCE_DIR}/android_uuid/*.h"
"${CMAKE_SOURCE_DIR}/android_uuid/*.c")
list(REMOVE_ITEM UUID_SRC "${CMAKE_SOURCE_DIR}/android_uuid/gen_uuid_nt.c")

# Need to combine all source files for static linking on non-windows
add_library(opennurbs STATIC ${UUID_SRC} ${OpenNURBS_SOURCE})
endif()
endif()

# compile definitions
target_compile_definitions(
opennurbs
PRIVATE
ON_COMPILING_OPENNURBS _GNU_SOURCE
OPENNURBS_INPUT_LIBS_DIR="${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>"
UNICODE)

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# Windows specific

# Fix "WIN32" preprocessor definitions on x64
if(${CMAKE_SIZEOF_VOID_P} EQUAL "8")
string(REPLACE "/DWIN32" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
target_compile_definitions(opennurbs PRIVATE WIN64)
endif()

elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# Linux specific

# Linux compiler definitions
target_compile_definitions(opennurbs PRIVATE ON_RUNTIME_LINUX
ON_CLANG_CONSTRUCTOR_BUG)
endif()

# Dependencies

# zlib
if(NOT ${opennurbs_ZLIB_LIB_DIR})
# build zlib as static library (bundled with OpenNURBS)
file(GLOB ZLIB_SOURCE "${CMAKE_SOURCE_DIR}/zlib/*.h"
"${CMAKE_SOURCE_DIR}/zlib/*.c")
add_library(zlib STATIC ${ZLIB_SOURCE})
target_compile_definitions(zlib PRIVATE MY_ZCALLOC Z_PREFIX)
endif()
# zlib-specific flags for opennurbs
target_compile_definitions(
opennurbs
PRIVATE MY_ZCALLOC Z_PREFIX
opennurbs_ZLIB_LIB_DIR="${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>")
target_link_libraries(opennurbs PRIVATE zlib)

# shlwapi on windows
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(opennurbs PRIVATE shlwapi)
endif()

# cross_dirent
target_include_directories(opennurbs PRIVATE "${CMAKE_SOURCE_DIR}/cross_dirent")

# Set the outputs of OpenNURBS CMake
set(OpenNURBS_LIBRARY ${opennurbs})
set(OpenNURBS_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/opennurbs")
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ Please see ["Getting started"](https://developer.rhino3d.com/guides/opennurbs/ge

There's also a collection of [example 3dm files](example_files/) available for testing.
# Building Using CMake:
1. Clone the repository
2. `cd` to the root directory of the repository.
3. Run `cmake -S ./ -B ./build` to configure the CMake files
4. Run `cmake --build ./build --config Release` to build the library.
## Questions?
For technical support, please head over to [Discourse](https://discourse.mcneel.com/category/opennurbs).

0 comments on commit 7540aaf

Please sign in to comment.