|
| 1 | +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 2 | +# # |
| 3 | +# Copyright (c) 2019, De Graef Group, Carnegie Mellon University # |
| 4 | +# All rights reserved. # |
| 5 | +# # |
| 6 | +# Author: William C. Lenthe # |
| 7 | +# # |
| 8 | +# This package is free software; you can redistribute it and/or # |
| 9 | +# modify it under the terms of the GNU General Public License as # |
| 10 | +# published by the Free Software Foundation; either version 2 of the # |
| 11 | +# License, or (at your option) any later version. # |
| 12 | +# # |
| 13 | +# This program is distributed in the hope that it will be useful, # |
| 14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 16 | +# GNU General Public License for more details. # |
| 17 | +# # |
| 18 | +# You should have received a copy of the GNU General Public License # |
| 19 | +# along with this program; if not, check the Free Software Foundation # |
| 20 | +# website: <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html> # |
| 21 | +# # |
| 22 | +# # |
| 23 | +# Interested in a commercial license? Contact: # |
| 24 | +# # |
| 25 | +# Center for Technology Transfer and Enterprise Creation # |
| 26 | +# 4615 Forbes Avenue, Suite 302 # |
| 27 | +# Pittsburgh, PA 15213 # |
| 28 | +# # |
| 29 | +# phone. : 412.268.7393 # |
| 30 | +# email : innovation@cmu.edu # |
| 31 | +# website: https://www.cmu.edu/cttec/ # |
| 32 | +# # |
| 33 | +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 34 | + |
| 35 | +project(EMSphInx) |
| 36 | +# cmake_minimum_required(VERSION 3.12) # 3.12 for the parallel option for cmake --build |
| 37 | +cmake_minimum_required(VERSION 3.14) # for FetchContent_MakeAvailable (could fall back to 3.12 with alternate pattern but it is now deprecated) |
| 38 | + |
| 39 | +set(CMAKE_CXX_STANDARD 11) # apparently you still need to explicitly request 2011 conformance in 2019... |
| 40 | + |
| 41 | +################################ |
| 42 | +# package options # |
| 43 | +################################ |
| 44 | + |
| 45 | +option(EMSPHINX_BUILD_SHARED "should shared or static libraries be preferred" OFF) |
| 46 | +option(EMSPHINX_FFTW_F "enable float templates by linking against fftw_f" OFF) |
| 47 | +option(EMSPHINX_FFTW_D "enable double templates by linking against fftw" ON ) |
| 48 | +option(EMSPHINX_FFTW_L "enable long double templates by linking against fftw_l" OFF) |
| 49 | +option(EMSPHINX_BUILD_FFTW "fetch and build FFTW instead of using an existing system installation" ON ) |
| 50 | +option(EMSPHINX_FFTW_SIMD "should SSE/SSE2/AVX instructions be enabled for fftw build (faster run, slower compiler)" ON ) |
| 51 | +option(EMSPHINX_FFTW_AVX2 "should AVX2 instructions be enabled for fftw build (not supported on all processors) " OFF) |
| 52 | +option(EMSPHINX_BUILD_HDF5 "fetch and build HDF5 instead of using an existing system installation" ON ) |
| 53 | +option(EMSPHINX_BUILD_TESTS "should test programs (/test/*) be built" ON ) |
| 54 | +option(EMSPHINX_BUILD_GUIS "should the GUI programs be built (experimental)" OFF) |
| 55 | +if(EMSPHINX_BUILD_GUIS) |
| 56 | + option(EMSPHINX_BUILD_wxWidgets "should wxWidgets be built from source" ON) |
| 57 | +endif() |
| 58 | + |
| 59 | +################################ |
| 60 | +# multicore compiling # |
| 61 | +################################ |
| 62 | + |
| 63 | +include(ProcessorCount) |
| 64 | +ProcessorCount(NCORES) |
| 65 | +if(NOT NCORES EQUAL 0) |
| 66 | + set(CMAKE_BUILD_PARALLEL_LEVEL NCORES) |
| 67 | +endif() |
| 68 | + |
| 69 | +################################ |
| 70 | +# compiler specific adjustment # |
| 71 | +################################ |
| 72 | + |
| 73 | +# visual studio |
| 74 | +if(MSVC) |
| 75 | + add_definitions(-D_SCL_SECURE_NO_WARNINGS) # these warnings are annoying and not critical |
| 76 | + add_definitions(-D_CRT_SECURE_NO_WARNINGS) # these warnings are annoying and not critical |
| 77 | + # add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>) # use multi core compiling |
| 78 | + add_compile_options(/MP) # the generator expression version breaks wxWidgets |
| 79 | +endif() |
| 80 | + |
| 81 | +# gcc |
| 82 | +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 83 | + set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-pthread" )# std::thread requires pthreads on gcc |
| 84 | +endif() |
| 85 | + |
| 86 | +# non clang osx |
| 87 | +# if(APPLE AND NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") # only for gcc, not clang |
| 88 | + # set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF) # there seems to be an rpath issue on apple + GCC |
| 89 | +# endif() |
| 90 | +set(MACOSX_RPATH ON) # still haven't fully resolved this... |
| 91 | + |
| 92 | +################################ |
| 93 | +# dynamic library copying # |
| 94 | +################################ |
| 95 | + |
| 96 | +# get prefix/extension for built libraries |
| 97 | +if(EMSPHINX_BUILD_SHARED) |
| 98 | + set(LIB_PRE ${CMAKE_SHARED_LIBRARY_PREFIX}) |
| 99 | + set(LIB_EXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) |
| 100 | +else() |
| 101 | + set(LIB_PRE ${CMAKE_STATIC_LIBRARY_PREFIX}) |
| 102 | + set(LIB_EXT ${CMAKE_STATIC_LIBRARY_SUFFIX}) |
| 103 | +endif() |
| 104 | + |
| 105 | +# determine name of files to link against (windows makes .dll for runtime but also keeps .lib for linking) and copy into build directory |
| 106 | +if(MSVC) |
| 107 | + set(LNK_EXT ${CMAKE_STATIC_LIBRARY_SUFFIX}) # link against the .lib |
| 108 | + set(CPY_DIR bin) # location to copy shared libraries from |
| 109 | +else() |
| 110 | + set(LNK_EXT ${LIB_EXT}) # link against static or dynamic as appropriate |
| 111 | + set(CPY_DIR lib) # location to copy shared libraries from |
| 112 | +endif() |
| 113 | + |
| 114 | +################################ |
| 115 | +# git versioning # |
| 116 | +################################ |
| 117 | + |
| 118 | +find_package(Git REQUIRED) |
| 119 | +execute_process( # get branch name |
| 120 | + COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD |
| 121 | + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 122 | + OUTPUT_VARIABLE EMSPHINX_GIT_BRANCH |
| 123 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 124 | +) |
| 125 | +execute_process( # get abbreviated hash |
| 126 | + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD |
| 127 | + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 128 | + OUTPUT_VARIABLE EMSPHINX_GIT_HASH |
| 129 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 130 | +) |
| 131 | + |
| 132 | +if("${EMSPHINX_GIT_BRANCH}" STREQUAL "") |
| 133 | + message(FATAL_ERROR "failed to determine git branch)") |
| 134 | +endif() |
| 135 | +if("${EMSPHINX_GIT_HASH}" STREQUAL "") |
| 136 | + message(FATAL_ERROR "failed to determine git hash)") |
| 137 | +endif() |
| 138 | + |
| 139 | +add_definitions("-DEMSPHINX_GIT_HASH=${EMSPHINX_GIT_HASH}") |
| 140 | +add_definitions("-DEMSPHINX_GIT_BRANCH=${EMSPHINX_GIT_BRANCH}") |
| 141 | + |
| 142 | +################################ |
| 143 | +# dependencies # |
| 144 | +################################ |
| 145 | + |
| 146 | +# fetch SHT file format content |
| 147 | +# this could be done with a git submodule but the user would have to call: |
| 148 | +# git submodule update |
| 149 | +# git clone --recursive |
| 150 | +# which is a bit annoying |
| 151 | +include(FetchContent) |
| 152 | +FetchContent_Declare( |
| 153 | + SHTfile |
| 154 | + GIT_REPOSITORY "https://github.com/EMsoft-org/SHTfile" |
| 155 | + GIT_TAG "cfd13df" |
| 156 | + # GIT_TAG "v3.1.2" # just get the most recent version for now |
| 157 | + # GIT_PROGRESS TRUE # its currently only 1 file, we probably don't need to print out progress |
| 158 | +) |
| 159 | +# set(FETCHCONTENT_QUIET NO) # again only 1 file |
| 160 | +FetchContent_MakeAvailable(SHTfile) |
| 161 | +FetchContent_GetProperties(SHTfile BINARY_DIR SHTfile_BINARY_DIR) |
| 162 | +include_directories(${SHTfile_BINARY_DIR}) |
| 163 | + |
| 164 | +# compiled dependencies |
| 165 | +include(${CMAKE_CURRENT_LIST_DIR}/depends/FFTW.cmake) # build or find existing FFTW |
| 166 | +include(${CMAKE_CURRENT_LIST_DIR}/depends/HDF5.cmake) # build or find existing HDF5 |
| 167 | + |
| 168 | +if(EMSPHINX_BUILD_GUIS) |
| 169 | + include(${CMAKE_CURRENT_LIST_DIR}/depends/wxWidgets.cmake) # build or find existing HDF5 |
| 170 | +endif() |
| 171 | + |
| 172 | +# png support, for now I've included these files directly due to download issues on some versions of cmake (if libcurl doesn't support https) |
| 173 | +set(BuildMiniZ OFF) |
| 174 | +if(BuildMiniZ) |
| 175 | + set(MINIZ_VERSION "2.0.8") |
| 176 | + ExternalProject_Add( |
| 177 | + miniz PREFIX "miniz" |
| 178 | + URL https://github.com/richgel999/miniz/releases/download/${MINIZ_VERSION}/miniz-${MINIZ_VERSION}.zip |
| 179 | + URL_HASH MD5=0692c3f080267b24419ab67c1eefc881 # make sure the download wasn't corrupted (/ someone hasn't injected a different version) |
| 180 | + CONFIGURE_COMMAND "" ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/miniz/src/miniz/ ${CMAKE_SOURCE_DIR}/include/miniz # copy everything (source + license are most critical) |
| 181 | + BUILD_COMMAND "" INSTALL_COMMAND "" |
| 182 | + ) |
| 183 | +endif(BuildMiniZ) |
| 184 | + |
| 185 | +################################ |
| 186 | +# add actual components # |
| 187 | +################################ |
| 188 | + |
| 189 | +# include headers |
| 190 | +include_directories(${CMAKE_CURRENT_LIST_DIR}/include) |
| 191 | +include_directories(${CMAKE_CURRENT_LIST_DIR}/icons) |
| 192 | + |
| 193 | +# add test programs if needed |
| 194 | +if(EMSPHINX_BUILD_TESTS) |
| 195 | + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/test ${CMAKE_BINARY_DIR}/test) # don't put in /cpp/test |
| 196 | +endif() |
| 197 | + |
| 198 | +# add actual programs |
| 199 | +include(${CMAKE_CURRENT_LIST_DIR}/programs/CMakeLists.txt) # include instead of add_subdirectory so we don't get a subfolder in the build |
0 commit comments