11cmake_minimum_required (VERSION 3.16.)
22project (diffCheck VERSION 1.3.0 LANGUAGES CXX C)
33set (CMAKE_CXX_STANDARD 17)
4- # set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
54
65# Force usage of libc++ and proper visibility on macOS
76# For some reason, without this, there will be a segfault in test
@@ -10,9 +9,6 @@ if(APPLE)
109 add_link_options (-stdlib=libc++)
1110endif ()
1211
13- # # Set rpath for Python extension loading on macOS
14- # set(CMAKE_MACOSX_RPATH ON)
15-
1612list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} /cmake)
1713
1814include (external_tools)
@@ -53,17 +49,22 @@ set(SHARED_LIB_NAME diffCheck)
5349file (GLOB_RECURSE SOURCES_LIB
5450 src/diffCheck.hh # diffCheck interface
5551 src/diffCheck/*.cc src/diffCheck/*.hh # diffCheck src
56- src/diffCheck/*/*.cc src/diffCheck/*/*.hh # diffCheck submodules
5752)
5853
59- # print the sources founded
54+ # For some reason, on macOS, we need to compile the library as static
55+ # I wonder if it's a good idea to also compile the library as static on Windows
56+ # if (APPLE)
57+ # add_library(${SHARED_LIB_NAME} STATIC ${SOURCES_LIB})
58+ # else()
6059add_library (${SHARED_LIB_NAME} STATIC ${SOURCES_LIB} )
61-
62- # if (WIN32)
63- # set_target_properties(${SHARED_LIB_NAME} PROPERTIES
64- # WINDOWS_EXPORT_ALL_SYMBOLS TRUE
65- # )
6660# endif()
61+
62+ if (WIN32 )
63+ set_target_properties (${SHARED_LIB_NAME} PROPERTIES
64+ WINDOWS_EXPORT_ALL_SYMBOLS TRUE
65+ )
66+ endif ()
67+
6768set_target_properties (${SHARED_LIB_NAME} PROPERTIES
6869 ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib
6970 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
@@ -74,9 +75,10 @@ target_include_directories(${SHARED_LIB_NAME}
7475 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /src
7576)
7677
77- #set the MD_DynamicRelease flag for MSVC since we are compiling with /MD for py wrap
78- # set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
79-
78+ # set the MD_DynamicRelease flag for MSVC since we are compiling with /MD for py wrap
79+ if (WIN32 )
80+ set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" )
81+ endif ()
8082
8183#--------------------------------------------------------------------------
8284# 3rd party
@@ -89,30 +91,32 @@ target_link_libraries(${SHARED_LIB_NAME} PUBLIC Eigen3::Eigen)
8991
9092# Open3D (pre-built binaries) ---------------------------------------------
9193# download_submodule_project(open3d)
92- # set(Open3D_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/open3d/win/0_18/CMake)
93- # find_package(Open3D 0.18.0 REQUIRED)
94-
95- # # print the version debug or release of the package
96- # message(STATUS "Open3D version: ${Open3D_VERSION}"
97- # "Open3D include dir: ${Open3D_INCLUDE_DIRS}"
98- # "Open3D library dir: ${Open3D_LIBRARIES}")
94+ if (WIN32 )
95+ set (Open3D_DIR ${CMAKE_CURRENT_SOURCE_DIR} /deps/open3d/win/0_18/CMake)
96+ elseif (APPLE )
97+ set (Open3D_DIR ${CMAKE_CURRENT_SOURCE_DIR} /deps/open3d/mac/open3d-devel-darwin-arm64-0.18.0/lib/cmake/Open3D)
98+ endif ()
99+ find_package (Open3D 0.18.0 REQUIRED)
99100
101+ # find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/lib/cmake)
100102
101- find_package (Open3D HINTS ${CMAKE_INSTALL_PREFIX} /lib/cmake)
102103# link the release version of the open3d library
103104target_link_libraries (${SHARED_LIB_NAME} PUBLIC Open3D::Open3D)
104105
105106# On Windows if BUILD_SHARED_LIBS is enabled, copy .dll files to the executable directory
106- # if(WIN32)
107- # get_target_property(open3d_type Open3D::Open3D TYPE)
108- # if(open3d_type STREQUAL "SHARED_LIBRARY")
109- # message(STATUS "Copying Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
110- # add_custom_command(TARGET ${SHARED_LIB_NAME} POST_BUILD
111- # COMMAND ${CMAKE_COMMAND} -E copy
112- # $<TARGET_FILE:Open3D::Open3D>
113- # $<TARGET_FILE_DIR:${SHARED_LIB_NAME}>)
114- # endif()
115- # endif()
107+ if (WIN32 )
108+ get_target_property (open3d_type Open3D::Open3D TYPE )
109+ if (open3d_type STREQUAL "SHARED_LIBRARY" )
110+ message (STATUS "Copying Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR} /${CMAKE_BUILD_TYPE} " )
111+ add_custom_command (TARGET ${SHARED_LIB_NAME} POST_BUILD
112+ COMMAND ${CMAKE_COMMAND} -E copy
113+ $<TARGET_FILE:Open3D::Open3D>
114+ $<TARGET_FILE_DIR:${SHARED_LIB_NAME} >)
115+ endif ()
116+ endif ()
117+
118+
119+
116120
117121# Boost (header only) -----------------------------------------------------
118122download_submodule_project(boost)
@@ -133,19 +137,19 @@ target_link_libraries(${SHARED_LIB_NAME} PUBLIC loguru::loguru)
133137#--------------------------------------------------------------------------
134138# executable for prototyping
135139#--------------------------------------------------------------------------
136- # set(APP_NAME_EXE diffCheckApp)
140+ set (APP_NAME_EXE diffCheckApp)
137141
138- # add_executable(${APP_NAME_EXE} src/diffCheckApp.cc)
142+ add_executable (${APP_NAME_EXE} src/diffCheckApp.cc)
139143
140- # set_target_properties(${APP_NAME_EXE} PROPERTIES
141- # RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
142- # )
144+ set_target_properties (${APP_NAME_EXE} PROPERTIES
145+ RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin
146+ )
143147
144- # target_link_libraries(${APP_NAME_EXE} ${SHARED_LIB_NAME})
148+ target_link_libraries (${APP_NAME_EXE} ${SHARED_LIB_NAME} )
145149
146- # target_include_directories(${APP_NAME_EXE}
147- # PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
148- # )
150+ target_include_directories (${APP_NAME_EXE}
151+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /src
152+ )
149153
150154#--------------------------------------------------------------------------
151155# pybind11
@@ -154,9 +158,10 @@ add_definitions(-D_GLIBCXX_DEBUG)
154158
155159if (BUILD_PYTHON_MODULE)
156160 set (PYBINDMODULE_NAME diffcheck_bindings)
157- # set(PYPI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/gh/diffCheck/diffCheck)
158- # set(TARGET_DLL_PYPI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/gh/diffCheck/diffCheck/dlls)
159- # set(SPHINX_DOC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/doc)
161+ set (PYPI_DIR ${CMAKE_CURRENT_SOURCE_DIR} /src/gh/diffCheck/diffCheck)
162+ set (TARGET_DLL_PYPI_DIR ${CMAKE_CURRENT_SOURCE_DIR} /src/gh/diffCheck/diffCheck/dlls)
163+ set (TARGET_SO_PYPI_DIR ${CMAKE_CURRENT_SOURCE_DIR} /src/gh/diffCheck/diffCheck)
164+ set (SPHINX_DOC_DIR ${CMAKE_CURRENT_SOURCE_DIR} /doc )
160165
161166 download_submodule_project(pybind11)
162167 add_subdirectory (deps/pybind11)
@@ -179,19 +184,25 @@ if (BUILD_PYTHON_MODULE)
179184 target_link_libraries (${PYBINDMODULE_NAME} PUBLIC ${SHARED_LIB_NAME} )
180185
181186 # copy the pyd file to the pypi directory
182- # add_custom_command(TARGET ${PYBINDMODULE_NAME} POST_BUILD
183- # COMMAND ${CMAKE_COMMAND} -E copy
184- # $<TARGET_FILE:${PYBINDMODULE_NAME}>
185- # ${PYPI_DIR}
186- # )
187- # copy_dlls(${TARGET_DLL_PYPI_DIR} ${PYBINDMODULE_NAME})
188- # # copy the pyd/dlls for the sphinx documentation
189- # add_custom_command(TARGET ${PYBINDMODULE_NAME} POST_BUILD
190- # COMMAND ${CMAKE_COMMAND} -E copy
191- # $<TARGET_FILE:${PYBINDMODULE_NAME}>
192- # ${SPHINX_DOC_DIR}
193- # )
194- # copy_dlls(${SPHINX_DOC_DIR} ${PYBINDMODULE_NAME})
187+ add_custom_command (TARGET ${PYBINDMODULE_NAME} POST_BUILD
188+ COMMAND ${CMAKE_COMMAND} -E copy
189+ $<TARGET_FILE:${PYBINDMODULE_NAME} >
190+ ${PYPI_DIR}
191+ )
192+ # copy the pyd/dlls for the sphinx documentation
193+ add_custom_command (TARGET ${PYBINDMODULE_NAME} POST_BUILD
194+ COMMAND ${CMAKE_COMMAND} -E copy
195+ $<TARGET_FILE:${PYBINDMODULE_NAME} >
196+ ${SPHINX_DOC_DIR}
197+ )
198+
199+ if (WIN32 )
200+ copy_dlls(${TARGET_DLL_PYPI_DIR} ${PYBINDMODULE_NAME} )
201+ copy_dlls(${SPHINX_DOC_DIR} ${PYBINDMODULE_NAME} )
202+ elseif (APPLE )
203+ copy_so_files(${TARGET_SO_PYPI_DIR} ${PYBINDMODULE_NAME} )
204+ copy_so_files(${SPHINX_DOC_DIR} ${PYBINDMODULE_NAME} )
205+ endif ()
195206endif ()
196207
197208# install the diffCheck shared library to the system path
@@ -201,9 +212,6 @@ install(TARGETS ${SHARED_LIB_NAME}
201212 RUNTIME DESTINATION bin
202213)
203214
204-
205-
206-
207215#--------------------------------------------------------------------------
208216# Tests
209217#--------------------------------------------------------------------------
0 commit comments