From 9364274a6b97419cb06de6aaee58849b1943218e Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 23 Jun 2023 03:03:14 -0700 Subject: [PATCH] Install zlib and tcl/tk correctly for custom NG_INSTALL_DIR_* settings --- CMakeLists.txt | 101 ++++++++++++++-------------- cmake/SuperBuild.cmake | 8 +++ cmake/external_projects/tcltk.cmake | 5 +- cmake/external_projects/zlib.cmake | 4 +- 4 files changed, 66 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a18972a..e136fa1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ endif(NOT CMAKE_BUILD_TYPE) cmake_minimum_required(VERSION 3.13) cmake_policy(VERSION 3.13) +set(CMAKE_POLICY_DEFAULT_CMP0135 NEW) # DOWNLOAD_TIMESTAMP to extract date include (CMakeDependentOption) option( USE_NATIVE_ARCH "build for native cpu architecture" ON) @@ -71,59 +72,15 @@ endif(UNIX AND USE_SUPERBUILD) if (USE_SUPERBUILD) project (SUPERBUILD) - if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR_DEFAULT}" CACHE PATH "Install directory" FORCE) - endif() - - # execute the superbuild (this script will be invoked again without the - # USE_SUPERBUILD option this time) - include (cmake/SuperBuild.cmake) - return() # stop processing this file further else() project(Netgen) - if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR_DEFAULT}" CACHE PATH "Install directory" FORCE) - endif() endif() -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR_DEFAULT}" CACHE PATH "Install directory" FORCE) +endif() -include (${CMAKE_CURRENT_LIST_DIR}/cmake/generate_version_file.cmake) -set(CPACK_PACKAGE_VERSION "${NETGEN_VERSION}") - - -####################################################################### -if(USE_CCACHE) - find_program(CCACHE_FOUND NAMES ccache ccache.bat) - if(CCACHE_FOUND) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND}) - endif(CCACHE_FOUND) -endif(USE_CCACHE) - -####################################################################### -if(INTEL_MIC) - set(MKL_ARCH "mic") - include(cmake/mic.cmake) -else(INTEL_MIC) - set(MKL_ARCH "intel64") -endif(INTEL_MIC) - -####################################################################### -# Append install paths of software in non-standard paths (e.g. openmpi, metis, intel mkl, ...) -# cmake -DUSE_MPI=ON -DCMAKE_PREFIX_PATH="/opt/openmpi165;/opt/metis51" ../ -set(ADDITIONAL_PATHS "" CACHE PATH "List of paths to additional libraries in non-standard locations, separated by ';'") -if (ADDITIONAL_PATHS) - set(CMAKE_PREFIX_PATH ${ADDITIONAL_PATHS}) -endif (ADDITIONAL_PATHS) - -####################################################################### -# build options -include_directories ("${PROJECT_SOURCE_DIR}/include") -include_directories ("${PROJECT_SOURCE_DIR}/libsrc") -include_directories ("${PROJECT_SOURCE_DIR}/libsrc/include") -include_directories ("${PROJECT_BINARY_DIR}") - -set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(NG_INSTALL_SUFFIX netgen CACHE STRING "Suffix appended to install directories (project name)") if(USE_PYTHON) find_package(PythonInterp 3 REQUIRED) @@ -135,8 +92,6 @@ if(USE_PYTHON) file(TO_CMAKE_PATH ${PYTHON_PACKAGES_INSTALL_DIR} PYTHON_PACKAGES_INSTALL_DIR) endif(USE_PYTHON) -set(NG_INSTALL_SUFFIX netgen CACHE STRING "Suffix appended to install directories (project name)") - if(APPLE) set(NG_INSTALL_DIR_BIN_DEFAULT Contents/MacOS) set(NG_INSTALL_DIR_LIB_DEFAULT Contents/MacOS) @@ -182,6 +137,52 @@ file(RELATIVE_PATH NETGEN_RESOURCE_DIR ${NETGEN_CMAKE_DIR_ABSOLUTE} ${NETGEN_RES file(RELATIVE_PATH NETGEN_RPATH ${NETGEN_BINARY_DIR_ABSOLUTE} ${NETGEN_LIBRARY_DIR_ABSOLUTE}) +if (USE_SUPERBUILD) + # execute the superbuild (this script will be invoked again without the + # USE_SUPERBUILD option this time) + include (cmake/SuperBuild.cmake) + return() # stop processing this file further +endif() + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +include (${CMAKE_CURRENT_LIST_DIR}/cmake/generate_version_file.cmake) +set(CPACK_PACKAGE_VERSION "${NETGEN_VERSION}") + + +####################################################################### +if(USE_CCACHE) + find_program(CCACHE_FOUND NAMES ccache ccache.bat) + if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND}) + endif(CCACHE_FOUND) +endif(USE_CCACHE) + +####################################################################### +if(INTEL_MIC) + set(MKL_ARCH "mic") + include(cmake/mic.cmake) +else(INTEL_MIC) + set(MKL_ARCH "intel64") +endif(INTEL_MIC) + +####################################################################### +# Append install paths of software in non-standard paths (e.g. openmpi, metis, intel mkl, ...) +# cmake -DUSE_MPI=ON -DCMAKE_PREFIX_PATH="/opt/openmpi165;/opt/metis51" ../ +set(ADDITIONAL_PATHS "" CACHE PATH "List of paths to additional libraries in non-standard locations, separated by ';'") +if (ADDITIONAL_PATHS) + set(CMAKE_PREFIX_PATH ${ADDITIONAL_PATHS}) +endif (ADDITIONAL_PATHS) + +####################################################################### +# build options +include_directories ("${PROJECT_SOURCE_DIR}/include") +include_directories ("${PROJECT_SOURCE_DIR}/libsrc") +include_directories ("${PROJECT_SOURCE_DIR}/libsrc/include") +include_directories ("${PROJECT_BINARY_DIR}") + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + if(USE_PYTHON) get_filename_component(NETGEN_PYTHON_DIR_ABSOLUTE ${NG_INSTALL_DIR_PYTHON} ABSOLUTE BASE_DIR ${CMAKE_INSTALL_PREFIX}) file(RELATIVE_PATH NETGEN_PYTHON_DIR ${NETGEN_CMAKE_DIR_ABSOLUTE} ${NETGEN_PYTHON_DIR_ABSOLUTE}) diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 387f7b29..7e81b3f2 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -249,6 +249,14 @@ set_vars( NETGEN_CMAKE_ARGS NGLIB_LIBRARY_TYPE NGCORE_LIBRARY_TYPE NGGUI_LIBRARY_TYPE + + NG_INSTALL_DIR_PYTHON + NG_INSTALL_DIR_BIN + NG_INSTALL_DIR_LIB + NG_INSTALL_DIR_INCLUDE + NG_INSTALL_DIR_CMAKE + NG_INSTALL_DIR_RES + NG_INSTALL_SUFFIX ) # propagate all variables set on the command line using cmake -DFOO=BAR diff --git a/cmake/external_projects/tcltk.cmake b/cmake/external_projects/tcltk.cmake index 637c1899..8d1e1247 100644 --- a/cmake/external_projects/tcltk.cmake +++ b/cmake/external_projects/tcltk.cmake @@ -183,7 +183,10 @@ elseif(WIN32) BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "" BUILD_COMMAND "" - INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX} + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory lib ${CMAKE_INSTALL_PREFIX}/${NG_INSTALL_DIR_LIB} + COMMAND ${CMAKE_COMMAND} -E copy_directory bin ${CMAKE_INSTALL_PREFIX}/${NG_INSTALL_DIR_BIN} + COMMAND ${CMAKE_COMMAND} -E copy_directory include ${CMAKE_INSTALL_PREFIX}/${NG_INSTALL_DIR_INCLUDE} + ${SUBPROJECT_ARGS} ) diff --git a/cmake/external_projects/zlib.cmake b/cmake/external_projects/zlib.cmake index c655090f..ddda799d 100644 --- a/cmake/external_projects/zlib.cmake +++ b/cmake/external_projects/zlib.cmake @@ -6,7 +6,9 @@ if(WIN32) BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "" BUILD_COMMAND "" - INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX} + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory lib ${CMAKE_INSTALL_PREFIX}/${NG_INSTALL_DIR_LIB} + COMMAND ${CMAKE_COMMAND} -E copy_directory bin ${CMAKE_INSTALL_PREFIX}/${NG_INSTALL_DIR_BIN} + COMMAND ${CMAKE_COMMAND} -E copy_directory include ${CMAKE_INSTALL_PREFIX}/${NG_INSTALL_DIR_INCLUDE} LOG_DOWNLOAD 1 )