|
| 1 | +#### CMakeLists.txt : CMake configuration and build script |
| 2 | +#### for the gtDMMB/pmfe sources |
| 3 | +#### Author: Maxie D. Schmidt (github.com/maxieds) |
| 4 | +#### Created: 2020.11.02 |
| 5 | + |
| 6 | +## CMake specific configuration and build environment settings: |
| 7 | +cmake_minimum_required(VERSION 3.10 FATAL_ERROR) |
| 8 | + |
| 9 | +set(CMAKE_DEBUG_POSTFIX d) |
| 10 | +set(CMAKE_CXX_STANDARD 14) |
| 11 | +set(CMAKE_CXX_STANDARD_REQUIRED True) |
| 12 | +set(CMAKE_BUILD_TYPE Release) |
| 13 | +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) |
| 14 | +set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 15 | +set(CMAKE_C_COMPILER gcc) |
| 16 | +set(CMAKE_CXX_COMPILER g++) |
| 17 | +set(CMAKE_LINKER g++) |
| 18 | +set(SHELL /bin/bash) |
| 19 | +set(CMAKE_RULE_MESSAGES ON) |
| 20 | +set(CMAKE_VERBOSE_MAKEFILE ON) |
| 21 | +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) |
| 22 | + |
| 23 | +## Define the PMFE project and define the output binaries: |
| 24 | +project(gtDMMB_PMFE) |
| 25 | + |
| 26 | +set(PMFE_VERSION_MAJOR "1") |
| 27 | +set(PMFE_VERSION_MINOR "0") |
| 28 | +set(PMFE_VERSION_PATCH "0") |
| 29 | +set(VERSION "${PMFE_VERSION_MAJOR}.${PMFE_VERSION_MINOR}.${PMFE_VERSION_PATCH}") |
| 30 | +set(PMFE_PACKAGE_NAME "gtDMMB-PMFE") |
| 31 | +set(PMFE_PACKAGE_VERSION ${VERSION}) |
| 32 | +set(PMFE_PACKAGE_STRING "${PMFE_PACKAGE_NAME} v${PMFE_PACKAGE_VERSION}") |
| 33 | + |
| 34 | +## Option to enable auto running of unit tests after recompiling: |
| 35 | +option(RUN_UNIT_TESTS "Enable running tests after build" OFF) |
| 36 | + |
| 37 | +## Configure pkg-config script for some dependency libraries: |
| 38 | +include(FindPkgConfig) |
| 39 | +if(NOT PKG_CONFIG_FOUND) |
| 40 | + message(FATAL_ERROR "Unable to configure libGMP : pkg-config not found ..." ) |
| 41 | +endif() |
| 42 | + |
| 43 | +if(APPLE) |
| 44 | + execute_process( |
| 45 | + COMMAND bash -c "echo -n $(greadlink -f $(find .. -mindepth 1 -maxdepth 1 -iname 'gmp-*' -type d -printf \"../%f\" | head -n1))" |
| 46 | + OUTPUT_VARIABLE PkgConfigLocalPCFilesPath |
| 47 | + ) |
| 48 | +elseif(UNIX AND NOT APPLE) |
| 49 | + execute_process( |
| 50 | + COMMAND bash -c "echo -n $(readlink -f $(find .. -mindepth 1 -maxdepth 1 -iname 'gmp-*' -type d -printf \"../%f\" | head -n1))" |
| 51 | + OUTPUT_VARIABLE PkgConfigLocalPCFilesPath |
| 52 | + ) |
| 53 | +endif() |
| 54 | +string(STRIP "${PkgConfigLocalPCFilesPath}" PkgConfigLocalPCFilesPath) |
| 55 | + |
| 56 | +set(ENV{PKG_CONFIG_PATH} "${PkgConfigLocalPCFilesPath}") |
| 57 | +execute_process( |
| 58 | + COMMAND bash -c "pkg-config gmp --libs --static" |
| 59 | + OUTPUT_VARIABLE PC_GMP_LIBRARIES |
| 60 | +) |
| 61 | +string(STRIP "${PC_GMP_LIBRARIES}" PC_GMP_LIBRARIES) |
| 62 | +execute_process( |
| 63 | + COMMAND bash -c "pkg-config gmp --cflags" |
| 64 | + OUTPUT_VARIABLE PC_GMP_INCLUDE_DIRS |
| 65 | +) |
| 66 | +string(STRIP "${PC_GMP_INCLUDE_DIRS}" PC_GMP_INCLUDE_DIRS) |
| 67 | +execute_process( |
| 68 | + COMMAND bash -c "pkg-config gmpxx --libs --static" |
| 69 | + OUTPUT_VARIABLE PC_GMPXX_LIBRARIES |
| 70 | +) |
| 71 | +string(STRIP "${PC_GMPXX_LIBRARIES}" PC_GMPXX_LIBRARIES) |
| 72 | +execute_process( |
| 73 | + COMMAND bash -c "pkg-config gmpxx --cflags" |
| 74 | + OUTPUT_VARIABLE PC_GMPXX_INCLUDE_DIRS |
| 75 | +) |
| 76 | +string(STRIP "${PC_GMPXX_INCLUDE_DIRS}" PC_GMPXX_INCLUDE_DIRS) |
| 77 | + |
| 78 | +## Configure paths on requisite build time libraries (Boost): |
| 79 | +set(Boost_USE_STATIC_LIBS ON) |
| 80 | +set(Boost_USE_MULTITHREADED ON) |
| 81 | +set(Boost_USE_STATIC_RUNTIME ON) |
| 82 | +set(Boost_FIND_REQUIRED TRUE) |
| 83 | +set(Boost_FIND_QUIETLY TRUE) |
| 84 | +set(Boost_DEBUG FALSE) |
| 85 | +set(Boost_NO_BOOST_CMAKE TRUE) |
| 86 | +set(Boost_NO_SYSTEM_PATHS TRUE) |
| 87 | +if(NOT DEFINED BOOST_ROOT) |
| 88 | + set(BoostFileSystemRootPath "../BoostLocalInstall") |
| 89 | + set(BOOST_ROOT ${PROJECT_SOURCE_DIR}/${BoostFileSystemRootPath}) |
| 90 | +endif() |
| 91 | +set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include) |
| 92 | +set(Boost_LIBRARY_DIR ${BOOST_ROOT}/lib) |
| 93 | +#find_package( |
| 94 | +# Boost ${BOOST_MIN_VERSION} |
| 95 | +# COMPONENTS filesystem program_options system log log_setup thread atomic regex chrono |
| 96 | +# REQUIRED |
| 97 | +#) |
| 98 | +#if(NOT Boost_FOUND) |
| 99 | +# message(FATAL_ERROR "Boost Not Found ... Unable to complete the build") |
| 100 | +#endif() |
| 101 | + |
| 102 | +## Configure paths on requisite build time libraries (CGAL): |
| 103 | +if(APPLE) |
| 104 | + execute_process( |
| 105 | + COMMAND bash "-c" "echo $(greadlink -f $(find .. -mindepth 1 -maxdepth 1 -iname 'cgal*' -type d -printf \"${PROJECT_SOURCE_DIR}/../%f\n\" | head -n1))" |
| 106 | + OUTPUT_VARIABLE CGALFileSystemRootPath |
| 107 | + RESULT_VARIABLE CGALFileSystemRootPath_CmdResult |
| 108 | + ) |
| 109 | + string(STRIP ${CGALFileSystemRootPath} CGALFileSystemRootPath) |
| 110 | + set(CGAL_DIR ${CGALFileSystemRootPath}) |
| 111 | +elseif(UNIX AND NOT APPLE) |
| 112 | + execute_process( |
| 113 | + COMMAND bash "-c" "echo $(readlink -f $(find .. -mindepth 1 -maxdepth 1 -iname 'cgal*' -type d -printf \"${PROJECT_SOURCE_DIR}/../%f\n\" | head -n1))" |
| 114 | + OUTPUT_VARIABLE CGALFileSystemRootPath |
| 115 | + RESULT_VARIABLE CGALFileSystemRootPath_CmdResult |
| 116 | + ) |
| 117 | + string(STRIP ${CGALFileSystemRootPath} CGALFileSystemRootPath) |
| 118 | + set(CGAL_DIR ${CGALFileSystemRootPath}) |
| 119 | +endif() |
| 120 | +set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "Force CGAL to maintain CMAKE flags") |
| 121 | +file(GLOB CGALBaseFilesList "${CGAL_DIR}/*") |
| 122 | +set(CGALIncludeFilesList "") |
| 123 | +foreach(fsEntry ${CGALBaseFilesList}) |
| 124 | + if(NOT ${fsEntry} MATCHES ".*\\.svn\$" AND IS_DIRECTORY ${fsEntry} |
| 125 | + AND IS_DIRECTORY ${fsEntry}/include) |
| 126 | + list(APPEND CGALIncludeFilesList "${fsEntry}/include") |
| 127 | + endif() |
| 128 | +endforeach() |
| 129 | +# AND NOT EXISTS ${fsEntry}/include/CGAL/Regular_complex_d.h |
| 130 | + |
| 131 | +## Build the binaries for the PMFE project: |
| 132 | + |
| 133 | +add_custom_command( |
| 134 | + OUTPUT BuildConfigHeaderIsSetup |
| 135 | + COMMAND cmake "-P" "${PROJECT_SOURCE_DIR}/cmake/AutogenBuildConfigHeader.cmake" |
| 136 | +) |
| 137 | +add_custom_target( |
| 138 | + BuildConfigHeader ALL |
| 139 | + DEPENDS BuildConfigHeaderIsSetup |
| 140 | +) |
| 141 | + |
| 142 | +file(GLOB ALL_TARGET_SOURCES src/*.cc) |
| 143 | +include_directories(${CGALIncludeFilesList} "${Boost_INCLUDE_DIR}" |
| 144 | + "${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/iB4e" |
| 145 | +) |
| 146 | +link_libraries("${Boost_LIBRARY_DIR}/libboost_program_options.a" "${Boost_LIBRARY_DIR}/libboost_system.a" |
| 147 | + "${Boost_LIBRARY_DIR}/libboost_log.a" |
| 148 | + "${Boost_LIBRARY_DIR}/libboost_thread.a" "${Boost_LIBRARY_DIR}/libboost_atomic.a" |
| 149 | + "${Boost_LIBRARY_DIR}/libboost_regex.a" "${Boost_LIBRARY_DIR}/libboost_chrono.a") |
| 150 | +add_executable( |
| 151 | + pmfe_findmfe_bin ${ALL_TARGET_SOURCES} src/bin-findmfe.cc |
| 152 | +) |
| 153 | +add_dependencies(pmfe_findmfe_bin BuildConfigHeader) |
| 154 | +set_target_properties( |
| 155 | + pmfe_findmfe_bin PROPERTIES |
| 156 | + OUTPUT_NAME "pmfe-findmfe" |
| 157 | + COMPILE_FLAGS "${CMAKE_CXX_FLAGS}" |
| 158 | +) |
| 159 | + |
| 160 | +add_executable( |
| 161 | + pmfe_scorer_bin ${ALL_TARGET_SOURCES} src/bin-scorer.cc |
| 162 | +) |
| 163 | +add_dependencies(pmfe_findmfe_bin BuildConfigHeader) |
| 164 | +set_target_properties( |
| 165 | + pmfe_scorer_bin PROPERTIES |
| 166 | + OUTPUT_NAME "pmfe-scorer" |
| 167 | + COMPILE_FLAGS "${CMAKE_CXX_FLAGS}" |
| 168 | +) |
| 169 | + |
| 170 | +add_executable( |
| 171 | + pmfe_parametrizer_bin ${ALL_TARGET_SOURCES} src/bin-parametrizer.cc |
| 172 | +) |
| 173 | +add_dependencies(pmfe_findmfe_bin BuildConfigHeader) |
| 174 | +set_target_properties( |
| 175 | + pmfe_parametrizer_bin PROPERTIES |
| 176 | + OUTPUT_NAME "pmfe-parametrizer" |
| 177 | + COMPILE_FLAGS "${CMAKE_CXX_FLAGS}" |
| 178 | +) |
| 179 | + |
| 180 | +add_executable( |
| 181 | + pmfe_subopt_bin ${ALL_TARGET_SOURCES} src/bin-subopt.cc |
| 182 | +) |
| 183 | +add_dependencies(pmfe_findmfe_bin BuildConfigHeader) |
| 184 | +set_target_properties( |
| 185 | + pmfe_subopt_bin PROPERTIES |
| 186 | + OUTPUT_NAME "pmfe-subopt" |
| 187 | + COMPILE_FLAGS "${CMAKE_CXX_FLAGS}" |
| 188 | +) |
| 189 | + |
| 190 | +add_executable( |
| 191 | + pmfe_tests_bin ${ALL_TARGET_SOURCES} src/bin-tests.cc |
| 192 | +) |
| 193 | +add_dependencies(pmfe_findmfe_bin BuildConfigHeader) |
| 194 | +set_target_properties( |
| 195 | + pmfe_subopt_bin PROPERTIES |
| 196 | + OUTPUT_NAME "pmfe-tests" |
| 197 | + COMPILE_FLAGS "${CMAKE_CXX_FLAGS}" |
| 198 | +) |
| 199 | + |
| 200 | +## Install targets (both for binary sub-utilities and the |
| 201 | +## Python library to be used with SageMath): |
| 202 | +if(IS_DIRECTORY "/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9") |
| 203 | + set(RHEL_INCLUDE_APPENDS "-I/opt/rh/devtoolset-9/root/usr/include/c++/9") |
| 204 | + set(RHEL_LINKER_APPENDS "-L/opt/rh/devtoolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9") |
| 205 | +else() |
| 206 | + set(RHEL_INCLUDE_APPENDS "") |
| 207 | + set(RHEL_LINKER_APPENDS "") |
| 208 | +endif() |
| 209 | +if(APPLE) |
| 210 | + set(CMAKE_CXX_FLAGS |
| 211 | + "${CMAKE_CXX_FLAGS} -Wall -std=c++14 -stdlib=libc++ -fPIC -fopenmp -Wall -g -O3 \ |
| 212 | + -DBOOST_LOG_DYN_LINK=0 -DCGAL_HEADER_ONLY -D_GLIBCXX_USE_CXX11_ABI=0 \ |
| 213 | + -I/usr/local/include -Iinclude/ -IiB4e/ \ |
| 214 | + ${PC_GMP_INCLUDE_DIRS} ${PC_GMPXX_INCLUDE_DIRS} \ |
| 215 | + -I${Boost_INCLUDE_DIR} ${CGAL_INCLUDE_DIRS} |
| 216 | + -DPMFE_PACKAGE_VERSION=\"${PMFE_PACKAGE_VERSION}\"" |
| 217 | + ) |
| 218 | + set(CMAKE_EXE_LINKER_FLAGS |
| 219 | + "${CMAKE_CXX_FLAGS} ${CMAKE_EXE_LINKER_FLAGS} \ |
| 220 | + -L/usr/local/lib -lgmp -lgmpxx -lCGAL -lm -lboost_filesystem \ |
| 221 | + -lboost_program_options -lboost_system -lboost_log -lboost_log_setup \ |
| 222 | + -lc++ -lboost_log-mt \ |
| 223 | + ${PC_GMP_LIBRARIES} ${PC_GMPXX_LIBRARIES} ${Boost_LIBRARIES}" |
| 224 | + ) |
| 225 | +elseif(UNIX AND NOT APPLE) # Primary target: Linux (typically RHEL) |
| 226 | + set(CMAKE_CXX_FLAGS |
| 227 | + "-fPIC -fopenmp -Wall -g -O3 -fvisibility=hidden -fvisibility-inlines-hidden \ |
| 228 | + -DABI=0 -DBOOST_FILESYSTEM_NO_DEPRECATED -UBOOST_DISABLE_THREADS \ |
| 229 | + -DBOOST_LOG_DYN_LINK=1 -BOOST_ALL_DYN_LINK=1 -D_GLIBCXX_USE_CXX11_ABI=1 \ |
| 230 | + -DCGAL_HEADER_ONLY -DGAL_USE_LEDA=1 ${RHEL_INCLUDE_APPENDS} ${CMAKE_CXX_FLAGS}" |
| 231 | + ) |
| 232 | + set(CMAKE_EXE_LINKER_FLAGS |
| 233 | + "${RHEL_LINKER_APPENDS} -L/usr/lib -L/usr/local/lib \ |
| 234 | + ${PC_GMP_LIBRARIES} ${PC_GMPXX_LIBRARIES} ${CMAKE_EXE_LINKER_FLAGS} -L${Boost_LIBRARY_DIR} \ |
| 235 | + -static -lboost_filesystem -lboost_program_options -lboost_system \ |
| 236 | + -lboost_log -lboost_log_setup -lpthread -lm" |
| 237 | + ) |
| 238 | +endif() |
| 239 | + |
| 240 | +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS}") |
| 241 | +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS}") |
| 242 | + |
| 243 | +install( |
| 244 | + TARGETS pmfe_findmfe_bin pmfe_scorer_bin pmfe_parametrizer_bin pmfe_subopt_bin pmfe_tests_bin |
| 245 | + DESTINATION ${EXECUTABLE_OUTPUT_PATH} |
| 246 | +) |
| 247 | + |
| 248 | +## Backup the old wrapper scripts and copy the new ones in their place: |
| 249 | +install( |
| 250 | + SCRIPT cmake/PostBuildAutogenWrapperScript.cmake |
| 251 | +) |
| 252 | + |
| 253 | +set(UserRunnerScriptPath "../../PMFECommandRunner.sh") |
| 254 | +set(DevRunnerScriptPath "../../PMFEDeveloperCommandRunner.sh") |
| 255 | +set(SageInitScriptPath "../../init.sage") |
| 256 | +set(SageInitScriptNestedPath "../SageInit/init.sage") |
| 257 | + |
| 258 | +execute_process ( |
| 259 | + COMMAND bash -c |
| 260 | + "cp ${UserRunnerScriptPath} ${UserRunnerScriptPath}.bak && |
| 261 | + cp ${DevRunnerScriptPath} ${DevRunnerScriptPath}.bak && |
| 262 | + cp ${SageInitScriptPath} ${SageInitScriptPath}.bak && |
| 263 | + cp ${SageInitScriptNestedPath} ${SageInitScriptNestedPath}.bak" |
| 264 | +) |
| 265 | +execute_process ( |
| 266 | + COMMAND bash -c |
| 267 | + "touch wrapper-runner-script/PMFECommandRunner.sh && |
| 268 | + cp wrapper-runner-script/PMFECommandRunner.sh ${UserRunnerScriptPath} && |
| 269 | + touch wrapper-runner-script/PMFEDeveloperCommandRunner.sh && |
| 270 | + cp wrapper-runner-script/PMFEDeveloperCommandRunner.sh ${DevRunnerScriptPath} && |
| 271 | + cp wrapper-runner-script/init.sage ${SageInitScriptPath} && |
| 272 | + cp wrapper-runner-script/init.sage ${SageInitScriptNestedPath}" |
| 273 | +) |
| 274 | + |
| 275 | +## Running of unit tests configuration: |
| 276 | +function(Func_runUnitTest UnitTestName) |
| 277 | + add_test(NAME "PMFEUnitTestCheck-${UnitTestName}" COMMAND pmfe-tests -n ${UnitTestName} -a -s) |
| 278 | + set_tests_properties( |
| 279 | + "PMFEUnitTestCheck-${UnitTestName}" PROPERTIES |
| 280 | + PASS_REGULAR_EXPRESSION "All tests passed .*" |
| 281 | + ) |
| 282 | +endfunction(Func_runUnitTest) |
| 283 | + |
| 284 | +if(RUN_UNIT_TESTS) |
| 285 | + enable_testing() |
| 286 | + message("Running *ALL* unit tests -- NOTE: This can take a long time -- ...") |
| 287 | + Func_runUnitTest("16S") |
| 288 | + Func_runUnitTest("5S") |
| 289 | + Func_runUnitTest("asuum") |
| 290 | + Func_runUnitTest("atabira") |
| 291 | + Func_runUnitTest("bbigemina") |
| 292 | + Func_runUnitTest("biological") |
| 293 | + Func_runUnitTest("cdiphtheriae") |
| 294 | + Func_runUnitTest("celegans") |
| 295 | + Func_runUnitTest("combinatorial") |
| 296 | + Func_runUnitTest("dmobilis") |
| 297 | + Func_runUnitTest("ecoli") |
| 298 | + Func_runUnitTest("ecuniculi") |
| 299 | + Func_runUnitTest("ehexamita") |
| 300 | + Func_runUnitTest("garboreum") |
| 301 | + Func_runUnitTest("gardaea") |
| 302 | + Func_runUnitTest("gintestinalis") |
| 303 | + Func_runUnitTest("gmuris") |
| 304 | + Func_runUnitTest("hsapiens") |
| 305 | + Func_runUnitTest("hvolcanii") |
| 306 | + Func_runUnitTest("ldelbrueckii") |
| 307 | + Func_runUnitTest("mfe") |
| 308 | + Func_runUnitTest("onivara") |
| 309 | + Func_runUnitTest("random") |
| 310 | + Func_runUnitTest("rnorvegicus") |
| 311 | + Func_runUnitTest("stokodaii") |
| 312 | + Func_runUnitTest("synthetic") |
| 313 | + Func_runUnitTest("tRNA") |
| 314 | + Func_runUnitTest("vnecatrix") |
| 315 | + Func_runUnitTest("zmays") |
| 316 | +endif() |
0 commit comments