netgen/cmake/SuperBuild.cmake
Matthias Hochsteger f6a0b31b96 Cleanup CMake build system
- Use CMAKE_INSTALL_PREFIX instead of INSTALL_DIR
  - Allow finer control of install directories
  - Use compiled TCL code by default
  - Fix RPATH usage on Linux and MacOSX

### Allow finer control of install directories
The following variables can be set to either absolute or relative paths
NG_INSTALL_DIR_PYTHON: Python files
NG_INSTALL_DIR_BIN: Executables
NG_INSTALL_DIR_LIB: Libraries
NG_INSTALL_DIR_INCLUDE: header files
NG_INSTALL_DIR_CMAKE: CMake files
NG_INSTALL_DIR_RES: Resources

### Use compiled TCL code by default
The tcl files contained in Netgen are stored in onetcl.cpp as c-string.
This way it's not necessary to install tcl files or set NETGENDIR

### Fix RPATH usage on Linux and MacOSX
The Netgen installation should be completely relocatable now.

Squashed commit of the following:

commit 201eda5e62726bd87d76beb13c3e5643cd4c7810
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 21:10:08 2017 +0200

    cleanup

commit b4cd46a9d2f390b40c5223c8d9971f576b979644
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 20:47:46 2017 +0200

    fix

commit 6506a834dbee2fd7b6df3b3f3709d0b27344356f
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 20:41:45 2017 +0200

    allow gui test to fail

commit 56c5fc131f61259e6fb67b60f7fff955d2e8d2da
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 20:26:18 2017 +0200

    add python3-tk to docker images

commit 4d1b5aac1d028867339819599708a08f2098bbd6
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 11:22:18 2017 -0700

    windows fix

commit 92b5f8a95491ba3508143d7f1b94359edc0655ce
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 11:08:08 2017 -0700

    fix for windows

commit 3f7bf51434ef3b637b3563930ddb61d04af645cb
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 19:28:13 2017 +0200

    fixes, test for gui

commit ef1d0164a50fadf374e3b1e43a745b5f69a16ad6
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 19:06:55 2017 +0200

    fixes

commit 67645bb896012149c23c851b03287199c21fa129
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 17:24:58 2017 +0200

    netgen config

commit b587b77a282768719cffc366c56d82a1746e0be0
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 16:53:47 2017 +0200

    remove comments

commit 2b34cc78818afa1cf21484bd0976413a91db0851
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 05:03:00 2017 -0700

    fix windows

commit 9e98efa54065624e264eaf1acf74b44ef022a68d
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 13:42:11 2017 +0200

    fixes

commit 394b470a07d73431079f80caa36c7c7042077f40
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 12:24:40 2017 +0200

    fix rpath issue

commit 6787eae384a8592f90598258ccd8207cd499d9fc
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 11:37:05 2017 +0200

    some more fixes with install dir

commit fcf22659c60300e8d39d12e14b21c58a062e739c
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 01:34:06 2017 -0700

    some fixes

commit ede1f0c462978bb70d3b4e2251cb555a592e82e3
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 29 10:16:34 2017 +0200

    fixes

commit b6a1259876a77f54e419a44f1b44d03d5bb49b82
Merge: c79f9a3 6627b0b
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 24 09:35:50 2017 +0200

    Merge remote-tracking branch 'origin/master' into cmake_cleanup

commit c79f9a3421d4d2937c31dab4a601ce09d52b0e54
Merge: 99c3550 030ad1d
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 22 17:52:24 2017 +0200

    Merge remote-tracking branch 'origin/master' into cmake_cleanup

commit 99c35500850e08fdc847013bb384169b1483acb4
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Fri May 19 14:37:28 2017 +0200

    fix rpath

commit 8215e9748d9ee225266bc941da1ca252aebd27de
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Thu May 18 13:29:41 2017 +0200

    remove INSTALL_DIR, rename var to NETGEN_INSTALL_DIR_INCLUDE, install libngpy to python package folder

commit 23d028c4cf7572de9e2e277cda8f6b07b6b1d9f9
Merge: 57027c8 f72a247
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Thu May 18 12:03:59 2017 +0200

    Merge remote-tracking branch 'origin/master' into cmake_cleanup

commit 57027c8c706ff755bdf26887884bbdeca129fe8f
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Fri May 12 17:32:05 2017 +0200

    New CMake option: USE_INTERNAL_TCL (ON by default)

    This option uses the tcl code compiled in onetcl.cpp instead of separate
    tcl files by default. When set at configure time, no tcl files will be
    installed anymore.

commit 27ce5b7edd66d64e2453f5045f5ac08c313f7608
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Fri May 12 17:16:52 2017 +0200

    WIP: Cleanup of CMake files

      - Fix RPATH on Linux (TODO: other platforms)
      - New variables to specify install behaviour:
          NG_INSTALL_DIR_BIN
          NG_INSTALL_DIR_LIB
          NG_INSTALL_DIR_CMAKE
          NG_INSTALL_DIR_INCLUDE
2017-05-29 21:41:27 +02:00

192 lines
7.5 KiB
CMake

include (ExternalProject)
set_property (DIRECTORY PROPERTY EP_PREFIX dependencies)
set (NETGEN_DEPENDENCIES)
set (LAPACK_DEPENDENCIES)
set (NETGEN_CMAKE_ARGS "" CACHE INTERNAL "")
macro(set_vars VAR_OUT)
foreach(varname ${ARGN})
if(NOT "${${varname}}" STREQUAL "")
string(REPLACE ";" "$<SEMICOLON>" varvalue "${${varname}}" )
set(${VAR_OUT} ${${VAR_OUT}};-D${varname}=${varvalue} CACHE INTERNAL "")
endif()
endforeach()
endmacro()
#######################################################################
if(WIN32)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_CXX_FLAGS_NEW ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_NEW} CACHE STRING "compile flags" FORCE)
string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_CXX_FLAGS_NEW ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_NEW} CACHE STRING "compile flags" FORCE)
string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_SHARED_LINKER_FLAGS_NEW ${CMAKE_SHARED_LINKER_FLAGS})
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_NEW} /IGNORE:4217,4049" CACHE STRING "compile flags" FORCE)
string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_EXE_LINKER_FLAGS_NEW ${CMAKE_EXE_LINKER_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS"${CMAKE_EXE_LINKER_FLAGS_NEW}/IGNORE:4217,4049" CACHE STRING "compile flags" FORCE)
endif(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
if(${CMAKE_SIZEOF_VOID_P} MATCHES 4)
# 32 bit
set(EXT_LIBS_DOWNLOAD_URL_WIN "http://www.asc.tuwien.ac.at/~mhochsteger/ngsuite/ext_libs32.zip" CACHE STRING INTERNAL)
set(OCC_DOWNLOAD_URL_WIN "http://www.asc.tuwien.ac.at/~mhochsteger/ngsuite/occ32.zip" CACHE STRING INTERNAL)
else(${CMAKE_SIZEOF_VOID_P} MATCHES 4)
# 64 bit
set(EXT_LIBS_DOWNLOAD_URL_WIN "http://www.asc.tuwien.ac.at/~mhochsteger/ngsuite/ext_libs64.zip" CACHE STRING INTERNAL)
set(OCC_DOWNLOAD_URL_WIN "http://www.asc.tuwien.ac.at/~mhochsteger/ngsuite/occ64.zip" CACHE STRING INTERNAL)
endif(${CMAKE_SIZEOF_VOID_P} MATCHES 4)
endif(WIN32)
if(UNIX)
message("Checking for write permissions in install directory...")
execute_process(COMMAND mkdir -p ${CMAKE_INSTALL_PREFIX})
execute_process(COMMAND test -w ${CMAKE_INSTALL_PREFIX} RESULT_VARIABLE res)
if(res)
message(WARNING "No write access at install directory, please set correct permissions")
endif()
endif(UNIX)
if(NOT WIN32)
find_package(ZLIB REQUIRED)
set_vars(NETGEN_CMAKE_ARGS ZLIB_INCLUDE_DIRS ZLIB_LIBRARIES)
endif(NOT WIN32)
#######################################################################
if (USE_PYTHON)
find_path(PYBIND_INCLUDE_DIR pybind11/pybind11.h PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies/pybind11/include NO_DEFAULT_PATH)
if( NOT PYBIND_INCLUDE_DIR )
# if the pybind submodule is missing, try to initialize and update all submodules
execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
find_path(PYBIND_INCLUDE_DIR pybind11/pybind11.h ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies/pybind11/include)
endif( NOT PYBIND_INCLUDE_DIR )
if( PYBIND_INCLUDE_DIR )
message("-- Found Pybind11: ${PYBIND_INCLUDE_DIR}")
else( PYBIND_INCLUDE_DIR )
message(FATAL_ERROR "Could NOT find pybind11!")
endif( PYBIND_INCLUDE_DIR )
find_package(PythonInterp 3 REQUIRED)
find_package(PythonLibs 3 REQUIRED)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1,0,''))" OUTPUT_VARIABLE PYTHON_PACKAGES_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
file(TO_CMAKE_PATH ${PYTHON_PACKAGES_INSTALL_DIR} PYTHON_PACKAGES_INSTALL_DIR)
set_vars(NETGEN_CMAKE_ARGS PYTHON_PACKAGES_INSTALL_DIR PYTHON_INCLUDE_DIRS PYTHON_LIBRARIES PYTHON_EXECUTABLE PYTHON_VERSION PYBIND_INCLUDE_DIR)
endif (USE_PYTHON)
#######################################################################
if(USE_OCC AND WIN32 AND NOT OCC_INCLUDE_DIR)
ExternalProject_Add(win_download_occ
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/tcl
URL ${OCC_DOWNLOAD_URL_WIN}
UPDATE_COMMAND "" # Disable update
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX}
LOG_DOWNLOAD 1
)
list(APPEND NETGEN_DEPENDENCIES win_download_occ)
endif(USE_OCC AND WIN32 AND NOT OCC_INCLUDE_DIR)
#######################################################################
if(USE_GUI)
include(cmake/external_projects/tcltk.cmake)
endif(USE_GUI)
#######################################################################
if(USE_MPI)
if(UNIX)
find_package(METIS QUIET)
if(NOT METIS_FOUND)
message(STATUS "Could not find METIS, it will be built from source")
include(cmake/external_projects/metis.cmake)
endif()
else(UNIX)
find_package(METIS REQUIRED)
endif(UNIX)
endif(USE_MPI)
#######################################################################
# propagate cmake variables to Netgen subproject
set_vars( NETGEN_CMAKE_ARGS
CMAKE_CXX_COMPILER
CMAKE_BUILD_TYPE
CMAKE_SHARED_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS_RELEASE
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_RELEASE
USE_GUI
USE_PYTHON
USE_MPI
USE_VT
USE_VTUNE
USE_NUMA
USE_CCACHE
USE_NATIVE_ARCH
USE_OCC
USE_MPEG
USE_INTERNAL_TCL
INSTALL_PROFILES
INTEL_MIC
CMAKE_PREFIX_PATH
CMAKE_INSTALL_PREFIX
)
# propagate all variables set on the command line using cmake -DFOO=BAR
# to Netgen subproject
get_cmake_property(CACHE_VARS CACHE_VARIABLES)
foreach(CACHE_VAR ${CACHE_VARS})
get_property(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING)
if(CACHE_VAR_HELPSTRING STREQUAL "No help, variable specified on the command line.")
get_property(CACHE_VAR_TYPE CACHE ${CACHE_VAR} PROPERTY TYPE)
set(NETGEN_CMAKE_ARGS ${NETGEN_CMAKE_ARGS};-D${CACHE_VAR}:${CACHE_VAR_TYPE}=${${CACHE_VAR}} CACHE INTERNAL "")
endif()
endforeach()
if(${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
set(NETGEN_BUILD_COMMAND $(MAKE) --silent )
else()
set(NETGEN_BUILD_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/netgen --config ${CMAKE_BUILD_TYPE})
endif()
ExternalProject_Add (netgen
DEPENDS ${NETGEN_DEPENDENCIES}
SOURCE_DIR ${PROJECT_SOURCE_DIR}
CMAKE_ARGS -DUSE_SUPERBUILD=OFF ${NETGEN_CMAKE_ARGS}
INSTALL_COMMAND ""
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/netgen
BUILD_COMMAND ${NETGEN_BUILD_COMMAND}
STEP_TARGETS build
)
# Check if the git submodules (i.e. pybind11) are up to date
# in case, something is wrong, emit a warning but continue
ExternalProject_Add_Step(netgen check_submodules
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_submodules.cmake
DEPENDERS install # Steps on which this step depends
)
# Due to 'ALWAYS 1', this step is always run which also forces a build of
# the Netgen subproject
ExternalProject_Add_Step(netgen check_submodules1
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_submodules.cmake
DEPENDEES configure # Steps on which this step depends
DEPENDERS build # Steps that depend on this step
ALWAYS 1 # No stamp file, step always runs
)
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/netgen)")
add_custom_target(test_netgen
${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/netgen
--target test
--config ${CMAKE_BUILD_TYPE}
)