From ea05f5183ec0134d6d9af9db59c7fc0aea08a4bb Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 9 Apr 2015 12:39:41 +0200 Subject: [PATCH] cmake OpenCascade support --- CMakeLists.txt | 9 ++ cmake_modules/FindOpenCasCade.cmake | 140 ++++++++++++++++++++++++++++ libsrc/interface/CMakeLists.txt | 2 +- libsrc/occ/CMakeLists.txt | 2 +- ng/CMakeLists.txt | 4 +- nglib/CMakeLists.txt | 26 +++--- 6 files changed, 166 insertions(+), 17 deletions(-) create mode 100644 cmake_modules/FindOpenCasCade.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a8ca7e0b..14e74752 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,6 +203,15 @@ if (USE_MPI) include_directories(${METIS_INCLUDE_DIR}) endif (USE_MPI) +####################################################################### +if (USE_OCC) + find_package(OpenCasCade REQUIRED) + add_definitions(-DOCCGEOMETRY -D_OCC64) + + add_definitions(-DHAVE_IOSTREAM -DHAVE_IOSTREAM_H -DHAVE_LIMITS -DHAVE_LIMITS_H -DHAVE_IOMANIP -DHAVE_IOMANIP_H) + include_directories(${OCC_INCLUDE_DIR}) +endif (USE_OCC) + ####################################################################### if (USE_JPEG) find_package(JPEG REQUIRED) diff --git a/cmake_modules/FindOpenCasCade.cmake b/cmake_modules/FindOpenCasCade.cmake new file mode 100644 index 00000000..c2787084 --- /dev/null +++ b/cmake_modules/FindOpenCasCade.cmake @@ -0,0 +1,140 @@ +# Try to find OCE / OCC +# Once done this will define +# +# OCC_FOUND - system has OCC - OpenCASCADE +# OCC_INCLUDE_DIR - where the OCC include directory can be found +# OCC_LIBRARY_DIR - where the OCC library directory can be found +# OCC_LIBRARIES - Link this to use OCC +# OCC_OCAF_LIBRARIES - Link this to use OCC OCAF framework + +# First try to find OpenCASCADE Community Edition +if(NOT DEFINED OCE_DIR) + if(UNIX) + set(OCE_DIR "/usr/local/share/cmake/") + elseif(WIN32) + set(OCE_DIR "c:/OCE-0.4.0/share/cmake") + endif() +endif() + +find_package(OCE QUIET) +if(0 AND OCE_FOUND) + message(STATUS "-- OpenCASCADE Community Edition has been found.") + # Disable this define. For more details see bug #0001872 + #add_definitions (-DHAVE_CONFIG_H) + set(OCC_INCLUDE_DIR ${OCE_INCLUDE_DIRS}) + #set(OCC_LIBRARY_DIR ${OCE_LIBRARY_DIR}) +else(0 AND OCE_FOUND) #look for OpenCASCADE + if(WIN32) + if(CYGWIN OR MINGW) + FIND_PATH(OCC_INCLUDE_DIR Standard_Version.hxx + /usr/include/oce + /usr/include/opencascade + /usr/local/include/opencascade + /opt/opencascade/include + /opt/opencascade/inc + ) + FIND_LIBRARY(OCC_LIBRARY TKernel + /usr/lib + /usr/local/lib + /opt/opencascade/lib + ) + else(CYGWIN OR MINGW) + FIND_PATH(OCC_INCLUDE_DIR Standard_Version.hxx + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\SIM\\OCC\\2;Installation Path]/include" + ) + FIND_LIBRARY(OCC_LIBRARY TKernel + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\SIM\\OCC\\2;Installation Path]/lib" + ) + endif(CYGWIN OR MINGW) + else(WIN32) + FIND_PATH(OCC_INCLUDE_DIR Standard_Version.hxx + /usr/include/oce + /usr/include/opencascade + /usr/local/include/opencascade + /opt/opencascade/include + /opt/opencascade/inc + ) + FIND_LIBRARY(OCC_LIBRARY TKernel + /usr/lib + /usr/local/lib + /opt/opencascade/lib + ) + endif(WIN32) + if(OCC_LIBRARY) + GET_FILENAME_COMPONENT(OCC_LIBRARY_DIR ${OCC_LIBRARY} PATH) + endif(OCC_LIBRARY) +endif(0 AND OCE_FOUND) + +if(OCC_INCLUDE_DIR) + file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MAJOR + REGEX "#define OCC_VERSION_MAJOR.*" + ) + string(REGEX MATCH "[0-9]+" OCC_MAJOR ${OCC_MAJOR}) + file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MINOR + REGEX "#define OCC_VERSION_MINOR.*" + ) + string(REGEX MATCH "[0-9]+" OCC_MINOR ${OCC_MINOR}) + file(STRINGS ${OCC_INCLUDE_DIR}/Standard_Version.hxx OCC_MAINT + REGEX "#define OCC_VERSION_MAINTENANCE.*" + ) + string(REGEX MATCH "[0-9]+" OCC_MAINT ${OCC_MAINT}) + + set(OCC_VERSION_STRING "${OCC_MAJOR}.${OCC_MINOR}.${OCC_MAINT}") +endif(OCC_INCLUDE_DIR) + +# handle the QUIETLY and REQUIRED arguments and set OCC_FOUND to TRUE if +# all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(OCC REQUIRED_VARS OCC_INCLUDE_DIR VERSION_VAR OCC_VERSION_STRING) + +if(OCC_FOUND) + set(OCC_LIBRARIES + FWOSPlugin + TKFillet + TKMesh + TKernel + TKG2d + TKG3d + TKMath + TKIGES + TKSTL + TKShHealing + TKXSBase + TKBool + TKBO + TKBRep + TKTopAlgo + TKGeomAlgo + TKGeomBase + TKOffset + TKPrim + TKSTEP + TKSTEPBase + TKSTEPAttr + TKHLR + TKFeat + TKCAF + TKXCAF + TKLCAF + TKXDESTEP + TKXDEIGES + TKMeshVS + ) + set(OCC_OCAF_LIBRARIES + TKCAF + TKXCAF + TKLCAF + TKXDESTEP + TKXDEIGES + TKMeshVS + ) + if(OCC_VERSION_STRING VERSION_LESS 6.7.3) + list(APPEND OCC_OCAF_LIBRARIES TKAdvTools) + endif(OCC_VERSION_STRING VERSION_LESS 6.7.3) + message(STATUS "-- Found OCE/OpenCASCADE version: ${OCC_VERSION_STRING}") + message(STATUS "-- OCE/OpenCASCADE include directory: ${OCC_INCLUDE_DIR}") + message(STATUS "-- OCE/OpenCASCADE shared libraries directory: ${OCC_LIBRARY_DIR}") + message(STATUS "-- OCE/OpenCASCADE shared libraries :\n ${OCC_LIBRARIES}") +else(OCC_FOUND) + message("Neither OpenCASCADE Community Edition nor OpenCasCade were found: will not build CAD modules!") +endif(OCC_FOUND) diff --git a/libsrc/interface/CMakeLists.txt b/libsrc/interface/CMakeLists.txt index 773749fd..326084bb 100644 --- a/libsrc/interface/CMakeLists.txt +++ b/libsrc/interface/CMakeLists.txt @@ -14,7 +14,7 @@ add_library(interface ${NG_LIB_TYPE} ) # TARGET_LINK_LIBRARIES(interface ${MPI_CXX_LIBRARIES} ${PYTHON_LIBS}) -# TARGET_LINK_LIBRARIES( interface ${LIBPTHREAD} ${OCCLIBS} ${LIBTOGL} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ) +# TARGET_LINK_LIBRARIES( interface ${LIBPTHREAD} ${OCC_LIBRARIES} ${LIBTOGL} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ) if(NOT WIN32) target_link_libraries(interface mesh csg geom2d) if(USE_GUI) diff --git a/libsrc/occ/CMakeLists.txt b/libsrc/occ/CMakeLists.txt index 177d2650..4f563090 100644 --- a/libsrc/occ/CMakeLists.txt +++ b/libsrc/occ/CMakeLists.txt @@ -7,7 +7,7 @@ add_library(occ ${NG_LIB_TYPE} add_library(occvis ${NG_LIB_TYPE} occpkg.cpp vsocc.cpp) if(NOT WIN32) - target_link_libraries( occ ${OCCLIBS} ${PYTHON_LIBS}) + target_link_libraries( occ ${OCC_LIBRARIES} ${PYTHON_LIBS}) target_link_libraries( occvis occ ) install( TARGETS occ occvis DESTINATION lib COMPONENT netgen ) endif(NOT WIN32) diff --git a/ng/CMakeLists.txt b/ng/CMakeLists.txt index 224b94b0..338d3589 100644 --- a/ng/CMakeLists.txt +++ b/ng/CMakeLists.txt @@ -32,10 +32,10 @@ if(USE_GUI) if(WIN32) set_target_properties( netgenlib PROPERTIES OUTPUT_NAME interface ) else(WIN32) - target_link_libraries( netgenlib visual csgvis csg interface mesh togl) + target_link_libraries( netgenlib visual csgvis csg interface mesh occ occvis togl) endif(WIN32) - target_link_libraries( netgenlib ${LIBPTHREAD} ${OCCLIBS} ${LIBTOGL} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ${PYTHON_LIBS} ${FFMPEG_LIBRARIES}) + target_link_libraries( netgenlib ${LIBPTHREAD} ${OCC_LIBRARIES} ${LIBTOGL} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ${PYTHON_LIBS} ${FFMPEG_LIBRARIES}) target_link_libraries( netgen netgenlib ) install(TARGETS netgenlib ${ng_install_dir}) diff --git a/nglib/CMakeLists.txt b/nglib/CMakeLists.txt index 76ac1dce..e10fd871 100644 --- a/nglib/CMakeLists.txt +++ b/nglib/CMakeLists.txt @@ -2,7 +2,7 @@ add_definitions(-DNGLIB_EXPORTS) # ADD_LIBRARY(nglib SHARED nglib.cpp) -# TARGET_LINK_LIBRARIES( nglib interface geom2d csg stl occ mesh ${OCCLIBS} ${MPI_CXX_LIBRARIES} ) +# TARGET_LINK_LIBRARIES( nglib interface geom2d csg stl occ mesh ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ) set(nglib_sources nglib.cpp) if(WIN32) @@ -27,22 +27,22 @@ endif(WIN32) add_library(nglib SHARED ${nglib_sources} ${nglib_objects}) -target_link_libraries( nglib ${LIBPTHREAD} ${OCCLIBS} ${LIBTOGL} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ) +target_link_libraries( nglib ${LIBPTHREAD} ${OCC_LIBRARIES} ${LIBTOGL} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ) if(USE_PYTHON) target_link_libraries(nglib ${PYTHON_LIBS}) endif(USE_PYTHON) -if(NOT WIN32) - add_executable(ng_vol ng_vol.cpp ${nglib_objects}) - target_link_libraries( ng_vol nglib ${OCCLIBS} ${MPI_CXX_LIBRARIES} ) - target_link_libraries( ng_vol nglib interface geom2d csg stl occ mesh ) - - add_executable(ng_stl ng_stl.cpp ${nglib_objects}) - target_link_libraries( ng_stl nglib ${OCCLIBS} ${MPI_CXX_LIBRARIES} ) - target_link_libraries( ng_stl nglib interface geom2d csg stl occ mesh ) - - install(TARGETS nglib ng_vol ng_stl ${ng_install_dir}) -endif(NOT WIN32) +# if(NOT WIN32) +# add_executable(ng_vol ng_vol.cpp ${nglib_objects}) +# target_link_libraries( ng_vol nglib ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ) +# target_link_libraries( ng_vol nglib interface geom2d csg stl occ mesh ) +# +# add_executable(ng_stl ng_stl.cpp ${nglib_objects}) +# target_link_libraries( ng_stl nglib ${OCC_LIBRARIES} ${OCC_OCAF_LIBRARIES} ${MPI_CXX_LIBRARIES} ) +# target_link_libraries( ng_stl nglib interface geom2d csg stl occ mesh ) +# +# install(TARGETS nglib ng_vol ng_stl ${ng_install_dir}) +# endif(NOT WIN32) install(TARGETS nglib COMPONENT netgen ${ng_install_dir})