1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00
occt/adm/templates/occt_macros.cmake
ibs 9f33b387e2 0024888: Refactoring of OCCT CMake meta-project
user sees just dirs of libs, shared libs and headers of 3rdparty products
documentation updated

3rdparty search priority was fixed: 1. user paths; 2. system paths
3rdparty debug usage fixed
vtk search introduced
occt information, generated by wok, was divided onto two files: occt_toolkits.cmake and occt_inc_toolkits.cmake
additional behavior of cmake search for freetype 2.5.1 and above

CMake (version < 3.0) don't know about new place of config/ftheader.h in freetype 2.5.1. There are cases when cmake seeks config/ftheader.h in defined place (3RDPARTY_FREETYPE_DIR variable), doesn't find it and start new search in system places. If system has own freetype header- cmake will find it and 3RDPARTY_FREETYPE* variables will point to different places. This situation is avoided

tcl, freetype, vtk are checked before usage of it (CSF variables usage)
tbb search mechanism was refactored
freetype search is processed by default cmake mechanism
tcl search is processed by default cmake mechanism

3rdparty macro seeks debug libraries (and release if debug ones aren't found); 3rdparty dll is sought in win case only

ADD_SUBDIRECTORY preferred to SUBDIRS

gendoc.bat search for tclsh.exe in user's system

0025141: CMake / MinGW: link recipe fails due to long command

0025146: Porting to Android

OCCT documentation updated. "Building with CMake and ADT for Android" article added

[CMAKE] custom.sh.in uses library variables instead unused dll ones.

-DDEBUG remove from CMAKE_CXX_FLAGS_DEBUG and CMAKE_C_FLAGS_DEBUG

hide unused 3rdparty in android case

also messages of freetype search mechanism slightly updated
2014-09-18 15:22:41 +04:00

202 lines
5.7 KiB
CMake

#
macro (OCCT_CHECK_AND_UNSET VARNAME)
if (DEFINED ${VARNAME})
unset (${VARNAME} CACHE)
endif()
endmacro()
macro (OCCT_CHECK_AND_UNSET_GROUP VARNAME)
OCCT_CHECK_AND_UNSET ("${VARNAME}_DIR")
OCCT_CHECK_AND_UNSET ("${VARNAME}_INCLUDE_DIR")
OCCT_CHECK_AND_UNSET ("${VARNAME}_LIBRARY")
OCCT_CHECK_AND_UNSET ("${VARNAME}_LIBRARY_DIR")
OCCT_CHECK_AND_UNSET ("${VARNAME}_DLL")
OCCT_CHECK_AND_UNSET ("${VARNAME}_DLL_DIR")
endmacro()
# BUILD_POSTFIX, IS_BUILD_DEBUG variables
macro (OCCT_MAKE_BUILD_POSTFIX)
if ("${BUILD_CONFIGURATION}" STREQUAL "Debug")
set (BUILD_POSTFIX "d")
set (IS_BUILD_DEBUG "")
else()
set (BUILD_POSTFIX "")
OCCT_CHECK_AND_UNSET (IS_BUILD_DEBUG)
endif()
endmacro()
# COMPILER_BITNESS variable
macro (OCCT_MAKE_COMPILER_BITNESS)
math (EXPR COMPILER_BITNESS "32 + 32*(${CMAKE_SIZEOF_VOID_P}/8)")
endmacro()
# OS_WITH_BIT
macro (OCCT_MAKE_OS_WITH_BITNESS)
OCCT_MAKE_COMPILER_BITNESS()
if (WIN32)
set (OS_WITH_BIT "win${COMPILER_BITNESS}")
elseif(APPLE)
set (OS_WITH_BIT "mac${COMPILER_BITNESS}")
else()
set (OS_WITH_BIT "lin${COMPILER_BITNESS}")
endif()
endmacro()
# COMPILER variable
macro (OCCT_MAKE_COMPILER_SHORT_NAME)
if (MSVC)
if (MSVC70)
set (COMPILER vc7)
elseif (MSVC80)
set (COMPILER vc8)
elseif (MSVC90)
set (COMPILER vc9)
elseif (MSVC10)
set (COMPILER vc10)
elseif (MSVC11)
set (COMPILER vc11)
elseif (MSVC12)
set (COMPILER vc12)
endif()
elseif (DEFINED CMAKE_COMPILER_IS_GNUCC)
set (COMPILER gcc)
elseif (DEFINED CMAKE_COMPILER_IS_GNUCXX)
set (COMPILER gxx)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set (COMPILER clang)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set (COMPILER icc)
else()
set (COMPILER ${CMAKE_GENERATOR})
string (REGEX REPLACE " " "" COMPILER ${COMPILER})
endif()
endmacro()
function (SUBDIRECTORY_NAMES MAIN_DIRECTORY RESULT)
file (GLOB SUB_ITEMS "${MAIN_DIRECTORY}/*")
foreach (ITEM ${SUB_ITEMS})
if (IS_DIRECTORY "${ITEM}")
get_filename_component (ITEM_NAME "${ITEM}" NAME)
list (APPEND LOCAL_RESULT "${ITEM_NAME}")
endif()
endforeach()
set (${RESULT} ${LOCAL_RESULT} PARENT_SCOPE)
endfunction()
function (FIND_PRODUCT_DIR ROOT_DIR PRODUCT_NAME RESULT)
OCCT_MAKE_COMPILER_SHORT_NAME()
OCCT_MAKE_COMPILER_BITNESS()
string (TOLOWER "${PRODUCT_NAME}" lower_PRODUCT_NAME)
list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*${COMPILER}.*${COMPILER_BITNESS}")
list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER}.*${COMPILER_BITNESS}")
list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+.*${COMPILER_BITNESS}")
list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}.*[0-9.]+")
list (APPEND SEARCH_TEMPLATES "${lower_PRODUCT_NAME}")
SUBDIRECTORY_NAMES ("${ROOT_DIR}" SUBDIR_NAME_LIST)
foreach (SEARCH_TEMPLATE ${SEARCH_TEMPLATES})
if (LOCAL_RESULT)
BREAK()
endif()
foreach (SUBDIR_NAME ${SUBDIR_NAME_LIST})
string (TOLOWER "${SUBDIR_NAME}" lower_SUBDIR_NAME)
string (REGEX MATCH "${SEARCH_TEMPLATE}" DUMMY_VAR "${lower_SUBDIR_NAME}")
if (DUMMY_VAR)
list (APPEND LOCAL_RESULT ${SUBDIR_NAME})
endif()
endforeach()
endforeach()
if (LOCAL_RESULT)
list (LENGTH "${LOCAL_RESULT}" LOC_LEN)
math (EXPR LAST_ELEMENT_INDEX "${LOC_LEN}-1")
list (GET LOCAL_RESULT ${LAST_ELEMENT_INDEX} DUMMY)
set (${RESULT} ${DUMMY} PARENT_SCOPE)
endif()
endfunction()
macro (OCCT_INSTALL_FILE_OR_DIR BEING_INSTALLED_OBJECT DESTINATION_PATH)
if (BUILD_PATCH_DIR AND EXISTS "${BUILD_PATCH_DIR}/${BEING_INSTALLED_OBJECT}")
if (IS_DIRECTORY "${BUILD_PATCH_DIR}/${BEING_INSTALLED_OBJECT}")
# first of all, install original files
install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
# secondly, rewrite original files with patched ones
install (DIRECTORY "${BUILD_PATCH_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
else()
install (FILES "${BUILD_PATCH_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
endif()
else()
if (IS_DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}")
install (DIRECTORY "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
else()
install (FILES "${CMAKE_SOURCE_DIR}/${BEING_INSTALLED_OBJECT}" DESTINATION "${DESTINATION_PATH}")
endif()
endif()
endmacro()
macro (OCCT_CONFIGURE_AND_INSTALL BEING_CONGIRUGED_FILE FINAL_NAME DESTINATION_PATH)
if (BUILD_PATCH_DIR AND EXISTS "${BUILD_PATCH_DIR}/${BEING_CONGIRUGED_FILE}")
configure_file("${BUILD_PATCH_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
else()
configure_file("${CMAKE_SOURCE_DIR}/${BEING_CONGIRUGED_FILE}" "${FINAL_NAME}" @ONLY)
endif()
install(FILES "${OCCT_BINARY_DIR}/${FINAL_NAME}" DESTINATION "${DESTINATION_PATH}")
endmacro()
function (OCCT_IS_PRODUCT_REQUIRED CSF_VAR_NAME USE_PRODUCT)
set (${USE_PRODUCT} OFF PARENT_SCOPE)
if (NOT USED_TOOLKITS)
message(STATUS "Warning: the list of being used toolkits is empty")
else()
foreach (USED_TOOLKIT ${USED_TOOLKITS})
if (BUILD_PATCH_DIR AND EXISTS "${BUILD_PATCH_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
file (READ "${BUILD_PATCH_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
elseif (EXISTS "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB")
file (READ "${CMAKE_SOURCE_DIR}/src/${USED_TOOLKIT}/EXTERNLIB" FILE_CONTENT)
endif()
string (REGEX MATCH "${CSF_VAR_NAME}" DOES_FILE_CONTAIN "${FILE_CONTENT}")
if (DOES_FILE_CONTAIN)
set (${USE_PRODUCT} ON PARENT_SCOPE)
break()
endif()
endforeach()
endif()
endfunction()