Commit 6c88aa2a authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[CMakeLists] improve OCC lib search

This enables the user to set a search path for OCC in case of custom
installation folders. Moreover, one has the possibility to link other
OCC libraries in case they are needed for an application.
parent 8b69061f
Pipeline #2421 passed with stage
in 5 minutes and 23 seconds
# minimum required cmake version
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.3)
# project name
project(frackit VERSION 1.1.0)
......@@ -33,72 +33,113 @@ else ()
endif ()
set(CMAKE_BUILD_TYPE Release)
# Find OpenCascade
find_path(OCC_INC "Standard_Version.hxx" PATH_SUFFIXES opencascade include/opencascade occt/)
if (OCC_INC)
include_directories( ${OCC_INC} )
# get OCC version
file(STRINGS ${OCC_INC}/Standard_Version.hxx
OCC_MAJOR REGEX "#define OCC_VERSION_MAJOR.*")
file(STRINGS ${OCC_INC}/Standard_Version.hxx
OCC_MINOR REGEX "#define OCC_VERSION_MINOR.*")
file(STRINGS ${OCC_INC}/Standard_Version.hxx
OCC_MAINT REGEX "#define OCC_VERSION_MAINTENANCE.*")
if (OCC_MAJOR AND OCC_MINOR AND OCC_MAINT)
string(REGEX MATCH "[0-9]+" OCC_MAJOR "${OCC_MAJOR}")
string(REGEX MATCH "[0-9]+" OCC_MINOR "${OCC_MINOR}")
string(REGEX MATCH "[0-9]+" OCC_MAINT "${OCC_MAINT}")
set(OCC_VERSION "${OCC_MAJOR}.${OCC_MINOR}.${OCC_MAINT}")
message(STATUS "Found OpenCASCADE version ${OCC_VERSION} in ${OCC_INC}")
endif ()
# link required libraries
set(OCC_LIBS_REQUIRED
# ModelingAlgorithms
TKBO TKTopAlgo TKBRep TKGeomAlgo TKPrim
# ModelingData
TKGeomBase TKG3d TKG2d
# FoundationClasses
TKMath TKernel)
list(LENGTH OCC_LIBS_REQUIRED NUM_OCC_LIBS_REQUIRED)
if (OCC_LIBS)
message(STATUS "OCC libraries specified explicitly: " ${OCC_LIBS})
list(LENGTH OCC_LIBS_REQUIRED NUM_OCC_LIBS)
else ()
set(OCC_LIBS)
foreach (OCC ${OCC_LIBS_REQUIRED})
find_library(OCC_LIB ${OCC}
PATH_SUFFIXES lib ${OCC_SYS_NAME}/lib ${OCC_SYS_NAME}/vc8/lib)
if (OCC_LIB)
list(APPEND OCC_LIBS ${OCC_LIB})
message(STATUS "Found OCC toolkit " ${OCC})
else ()
message(STATUS "OCC lib " ${OCC} " not Found")
endif ()
unset(OCC_LIB CACHE)
endforeach ()
list(LENGTH OCC_LIBS NUM_OCC_LIBS)
####################
# find openCASCADE #
####################
# TODO: In case we can separate functionality that doesn't require OCC,
# we could just warn and continue instead of aborting when sources
# or libraries are not found. However, the code currently has
# no checks if OCC was found or not so it would fail. Moreover,
# currently there is little to do only with the stuff that does not
# require OCC at all.
# if a user-specified location of OCC was provided, look in that location
if (OCC_INSTALL_DIR)
find_path(OCC_INC "Standard_Version.hxx"
PATHS ${OCC_INSTALL_DIR}
PATH_SUFFIXES opencascade include/opencascade occt/
NO_DEFAULT_PATH)
if (NOT OCC_INC)
message(WARNING "Could not find OpenCASCADE sources in the provided installation folder ${OCC_INSTALL_DIR}.")
endif ()
endif ()
# (maybe) look for system-wide installation
if (NOT OCC_INC)
find_path(OCC_INC "Standard_Version.hxx" PATH_SUFFIXES opencascade include/opencascade occt/)
if (NUM_OCC_LIBS EQUAL NUM_OCC_LIBS_REQUIRED)
set(HAVE_OCC TRUE)
list(APPEND CONFIG_OPTIONS "OpenCASCADE")
message(STATUS "Found required OpenCASCADE toolkits")
list(APPEND EXTERNAL_LIBRARIES ${OCC_LIBS})
list(APPEND EXTERNAL_INCLUDES ${OCC_INC})
if (HAVE_64BIT_SIZE_T)
add_definitions(-D_OCC64)
endif ()
else ()
message(WARNING "Did not find all required OpenCASCADE toolkits!")
if (NOT OCC_INC)
message(FATAL_ERROR "Could not find OpenCASCADE sources in system paths.")
endif ()
endif ()
# occ includes were found, get version
include_directories( ${OCC_INC} )
file(STRINGS ${OCC_INC}/Standard_Version.hxx
OCC_MAJOR REGEX "#define OCC_VERSION_MAJOR.*")
file(STRINGS ${OCC_INC}/Standard_Version.hxx
OCC_MINOR REGEX "#define OCC_VERSION_MINOR.*")
file(STRINGS ${OCC_INC}/Standard_Version.hxx
OCC_MAINT REGEX "#define OCC_VERSION_MAINTENANCE.*")
if (OCC_MAJOR AND OCC_MINOR AND OCC_MAINT)
string(REGEX MATCH "[0-9]+" OCC_MAJOR "${OCC_MAJOR}")
string(REGEX MATCH "[0-9]+" OCC_MINOR "${OCC_MINOR}")
string(REGEX MATCH "[0-9]+" OCC_MAINT "${OCC_MAINT}")
set(OCC_VERSION "${OCC_MAJOR}.${OCC_MINOR}.${OCC_MAINT}")
message(STATUS "Found OpenCASCADE version ${OCC_VERSION} in ${OCC_INC}")
else ()
message(FATAL_ERROR "OpenCascade sources not found")
message(WARNING "Could not extract OpenCASCADE version information.")
endif ()
# find required OCC toolkits
set(OCC_LIBS_REQUIRED
# FoundationClasses
TKernel TKMath
# ModelingData
TKG2d TKG3d TKGeomBase TKBRep
# ModelingAlgorithms
TKGeomAlgo TKTopAlgo TKPrim TKBO)
# function to search occ toolkit
function(searchOCCToolkit OCC_TK IS_REQUIRED)
if (OCC_INSTALL_DIR)
find_library(OCC_LIB ${OCC_TK}
PATHS ${OCC_INSTALL_DIR}
PATH_SUFFIXES lib ${OCC_SYS_NAME}/lib ${OCC_SYS_NAME}/vc8/lib
NO_DEFAULT_PATH)
if (NOT OCC_LIB)
message(WARNING "Could not find ${OCC_TK} in provided installation folder ${OCC_INSTALL_DIR}.")
endif()
endif ()
if (NOT OCC_LIB)
find_library(OCC_LIB ${OCC_TK}
PATH_SUFFIXES lib ${OCC_SYS_NAME}/lib ${OCC_SYS_NAME}/vc8/lib)
if (NOT OCC_LIB AND IS_REQUIRED)
message(FATAL_ERROR "Could not find required OCC toolkit ${OCC_TK}.")
elseif (NOT OCC_LIB)
message(WARNING "Could not find OCC toolkit ${OCC_TK}.")
endif ()
endif ()
if (OCC_LIB)
message(STATUS "Found ${OCC_TK} at ${OCC_LIB}")
list(APPEND OCC_LIBS ${OCC_LIB})
set(OCC_LIBS "${OCC_LIBS}" PARENT_SCOPE)
endif()
unset(OCC_LIB CACHE)
endfunction()
message(STATUS "Looking for required OCC toolkits")
foreach (OCC ${OCC_LIBS_REQUIRED})
searchOCCToolkit(${OCC} TRUE OCC_LIBS)
endforeach ()
if (OCC_ADDITIONAL_TOOLKITS)
message(STATUS "Looking for additional user-specified OCC toolkits")
foreach (OCC ${OCC_ADDITIONAL_TOOLKITS})
searchOCCToolkit(${OCC} FALSE OCC_LIBS)
endforeach ()
endif ()
###################
# Python bindings #
# option to enable/disable python bindings (default: on)
option(FRACKIT_ENABLE_PYTHONBINDINGS "Enable python bindings for Frackit" ON)
......@@ -120,6 +161,10 @@ endif ()
# TODO: make sure pip is installed
#################
# Documentation #
#################
# indicate the documentation build as an option and set it to ON by default
option(FRACKIT_BUILD_DOC "Build documentation" ON)
......@@ -145,6 +190,10 @@ elseif (NOT DOXYGEN_FOUND AND FRACKIT_BUILD_DOC)
message("Doxygen needs to be installed to generate the doxygen documentation")
endif ()
##################
# Directory tree #
##################
# include the sources
include_directories( ${CMAKE_SOURCE_DIR} )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment