Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 | [diff] [blame] | 1 | # |
| 2 | #//===----------------------------------------------------------------------===// |
| 3 | #// |
| 4 | #// The LLVM Compiler Infrastructure |
| 5 | #// |
| 6 | #// This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | #// Source Licenses. See LICENSE.txt for details. |
| 8 | #// |
| 9 | #//===----------------------------------------------------------------------===// |
| 10 | # |
Alp Toker | 7198f52 | 2014-06-01 18:01:33 | [diff] [blame] | 11 | |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 | [diff] [blame] | 12 | ################ |
| 13 | # CMAKE libiomp5 |
| 14 | cmake_minimum_required(VERSION 2.8 FATAL_ERROR) |
| 15 | project(libiomp C CXX) |
Alp Toker | 7198f52 | 2014-06-01 18:01:33 | [diff] [blame] | 16 | |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 | [diff] [blame] | 17 | ######### |
| 18 | # GLOBALS |
| 19 | set(GLOBAL_DEBUG 0) |
| 20 | |
| 21 | # Add cmake directory to search for custom cmake functions |
| 22 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) |
| 23 | |
| 24 | # Set base libomp directory (directory with exports/ , src/ , tools/ , etc.) |
| 25 | # The top-level CMakeLists.txt should define this variable. |
| 26 | set(LIBOMP_WORK ${CMAKE_CURRENT_SOURCE_DIR}) |
| 27 | |
| 28 | # These include files are in cmake/ subdirectory except for FindPerl which is a cmake standard module |
| 29 | include(HelperFunctions) |
| 30 | include(Definitions) # -D definitions when compiling |
| 31 | include(CommonFlags) # compiler, assembler, fortran, linker flags common for all compilers |
| 32 | include(SourceFiles) # source files to compile |
| 33 | include(PerlFlags) # Perl flags for generate-def.pl and expand-vars.pl |
| 34 | include(FindPerl) # Standard cmake module to check for Perl |
| 35 | |
| 36 | #################################################################### |
| 37 | # CONFIGURATION |
| 38 | # |
| 39 | # * Any variable/value that is CACHE-ed can be changed after the initial run of cmake |
| 40 | # through the file, CMakeCache.txt which is in the build directory. |
| 41 | # * If you change any value in CMakeCache.txt, then just run cmake .. |
| 42 | # and the changed will be picked up. One can also use -DVARIABLE=VALUE |
| 43 | # when calling cmake to changed configuration values. |
| 44 | # * CMAKE_C_COMPILER, CMAKE_CXX_COMPILER, CMAKE_ASM_MASM_COMPILER, CMAKE_ASM_COMPILER, |
| 45 | # CMAKE_Fortran_COMPILER can only by specified on the initial run of cmake. |
| 46 | # This means you cannot specify -DCMAKE_C_COMPILER= on a subsequent run of cmake |
| 47 | # in the same build directory until that build directory is emptied. |
| 48 | # If you want to change the compiler, then empty the build directory and rerun cmake. |
| 49 | |
| 50 | # Build Configuration |
| 51 | set(os_possible_values lin mac win mic) |
Jim Cownie | 3051f97 | 2014-08-07 10:12:54 | [diff] [blame^] | 52 | set(arch_possible_values 32e 32 arm ppc64) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 | [diff] [blame] | 53 | set(build_type_possible_values release debug relwithdebinfo) |
| 54 | set(omp_version_possible_values 40 30) |
| 55 | set(lib_type_possible_values normal profile stubs) |
| 56 | set(mic_arch_possible_values knf knc) |
| 57 | set(mic_os_possible_values bsd lin) |
| 58 | |
| 59 | # Below, cmake will try and determine the operating system and architecture for you (it assumes Intel architecture) |
| 60 | # These values are set in CMakeCache.txt when cmake is first run (-Dvar_name=... will take precedence) |
| 61 | # parameter | default value |
| 62 | # ---------------------------- |
| 63 | # Right now, this build system considers os=lin to mean "Unix-like that is not MAC" |
| 64 | if(${APPLE}) # Apple goes first because CMake considers Mac to be a Unix based operating system, while libiomp5 considers it a special case |
| 65 | set(os mac CACHE STRING "The operating system to build for (lin/mac/win/mic)") |
| 66 | elseif(${UNIX}) |
| 67 | set(os lin CACHE STRING "The operating system to build for (lin/mac/win/mic)") |
| 68 | elseif(${WIN32}) |
| 69 | set(os win CACHE STRING "The operating system to build for (lin/mac/win/mic)") |
| 70 | else() |
| 71 | set(os lin CACHE STRING "The operating system to build for (lin/mac/win/mic)") |
| 72 | endif() |
| 73 | |
Jim Cownie | 3051f97 | 2014-08-07 10:12:54 | [diff] [blame^] | 74 | # set to default architecture if the user did not specify an architecture explicitly |
| 75 | if(NOT arch) |
| 76 | if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") |
| 77 | set(arch 32 CACHE STRING "The architecture to build for (32e/32/arm/ppc64). 32e is Intel(R) 64 architecture, 32 is IA-32 architecture") |
| 78 | else() |
| 79 | set(arch 32e CACHE STRING "The architecture to build for (32e/32/arm/ppc64). 32e is Intel(R) 64 architecture, 32 is IA-32 architecture") |
| 80 | endif() |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 | [diff] [blame] | 81 | endif() |
| 82 | |
| 83 | set(lib_type normal CACHE STRING "Performance,Profiling,Stubs library (normal/profile/stubs)") |
| 84 | set(version 5 CACHE STRING "Produce libguide (version 4) or libiomp5 (version 5)") |
| 85 | set(omp_version 40 CACHE STRING "The OpenMP version (40/30)") |
| 86 | set(mic_arch knc CACHE STRING "Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) (knf/knc). Ignored if not Intel(R) MIC Architecture build.") |
| 87 | set(mic_os lin CACHE STRING "Intel(R) MIC Architecture operating system (bsd/lin). Ignored if not Intel(R) MIC Architecture build.") |
| 88 | set(create_fortran_modules false CACHE STRING "Create Fortran module files? (requires fortran compiler)") |
| 89 | |
| 90 | # - These tests are little tests performed after the library is formed. |
| 91 | # - The library won't be copied to the exports directory until it has passed/skipped all below tests |
| 92 | # - To skip these tests, just pass -Dtests=OFF to cmake or change tests value in CMakeCache.txt to OFF after running cmake |
| 93 | set(test_touch true CACHE BOOL "Perform a small touch test?" ) |
| 94 | set(test_relo true CACHE BOOL "Perform a relocation test for dynamic libraries?" ) |
| 95 | set(test_execstack true CACHE BOOL "Perform a execstack test for linux dynamic libraries?" ) |
| 96 | set(test_instr true CACHE BOOL "Perform an instruction test for Intel(R) MIC Architecture libraries?" ) |
| 97 | set(test_deps true CACHE BOOL "Perform a library dependency test?" ) |
| 98 | set(tests false CACHE BOOL "Perform touch, relo, execstack, instr, and deps tests?" ) |
| 99 | |
| 100 | # - stats-gathering enables OpenMP stats where things like the number of parallel regions, clock ticks spent in |
| 101 | # particular openmp regions are recorded. |
| 102 | set(stats false CACHE BOOL "Stats-Gathering functionality?" ) |
| 103 | |
| 104 | # User specified flags. These are appended to the predetermined flags found in CommonFlags.cmake and ${CMAKE_C_COMPILER_ID}/*Flags.cmake (i.e., GNU/CFlags.cmake) |
| 105 | set(USER_C_FLAGS "" CACHE STRING "Appended user specified C compiler flags." ) |
| 106 | set(USER_CXX_FLAGS "" CACHE STRING "Appended user specified C++ compiler flags." ) |
| 107 | set(USER_CPP_FLAGS "" CACHE STRING "Appended user specified C preprocessor flags." ) |
| 108 | set(USER_ASM_FLAGS "" CACHE STRING "Appended user specified assembler flags." ) |
| 109 | set(USER_LD_FLAGS "" CACHE STRING "Appended user specified linker flags." ) |
| 110 | set(USER_LD_LIB_FLAGS "" CACHE STRING "Appended user specified linked libs flags. (i.e., -lm)") |
| 111 | set(USER_F_FLAGS "" CACHE STRING "Appended user specified Fortran compiler flags. These are only used if create_fortran_modules==true." ) |
| 112 | |
| 113 | # - Allow three build types: Release, Debug, RelWithDebInfo (these relate to build.pl's release, debug, and diag settings respectively) |
| 114 | # - default is Release (when CMAKE_BUILD_TYPE is not defined) |
| 115 | # - CMAKE_BUILD_TYPE affects the -O and -g flags (CMake magically includes correct version of them on per compiler basis) |
| 116 | # - typical: Release = -O3 -DNDEBUG |
| 117 | # RelWithDebInfo = -O2 -g -DNDEBUG |
| 118 | # Debug = -g |
| 119 | if(CMAKE_BUILD_TYPE) |
| 120 | # CMAKE_BUILD_TYPE was defined, check for validity |
| 121 | string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lowercase) |
| 122 | check_variable(cmake_build_type_lowercase "${build_type_possible_values}") |
| 123 | else() |
| 124 | # CMAKE_BUILD_TYPE was not defined, set default to Release |
| 125 | unset(CMAKE_BUILD_TYPE CACHE) |
| 126 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Release/Debug/RelWithDebInfo") |
| 127 | string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lowercase) |
| 128 | check_variable(cmake_build_type_lowercase "${build_type_possible_values}") |
| 129 | endif() |
| 130 | |
| 131 | # Check valid values |
| 132 | check_variable(os "${os_possible_values}" ) |
| 133 | check_variable(arch "${arch_possible_values}" ) |
| 134 | check_variable(omp_version "${omp_version_possible_values}") |
| 135 | check_variable(lib_type "${lib_type_possible_values}" ) |
| 136 | if("${os}" STREQUAL "mic") |
| 137 | check_variable(mic_arch "${mic_arch_possible_values}" ) |
| 138 | check_variable(mic_os "${mic_os_possible_values}" ) |
| 139 | endif() |
| 140 | # Get the build number from kmp_version.c |
| 141 | get_build_number("${LIBOMP_WORK}" build_number) |
| 142 | |
| 143 | # Getting time and date |
| 144 | # As of now, no timestamp will be created. |
| 145 | set(date "No Timestamp") |
| 146 | |
| 147 | ################################################################# |
| 148 | # Set some useful flags variables for other parts of cmake to use |
| 149 | # Operating System |
| 150 | set(LINUX FALSE) |
| 151 | set(MAC FALSE) |
| 152 | set(WINDOWS FALSE) |
| 153 | set(MIC FALSE) |
| 154 | set(FREEBSD FALSE) |
| 155 | if("${os}" STREQUAL "lin") |
| 156 | set(LINUX TRUE) |
| 157 | set(real_os lin) |
| 158 | elseif("${os}" STREQUAL "mac") |
| 159 | set(MAC TRUE) |
| 160 | set(real_os mac) |
| 161 | elseif("${os}" STREQUAL "win") |
| 162 | set(WINDOWS TRUE) |
| 163 | set(real_os win) |
| 164 | elseif("${os}" STREQUAL "mic") |
| 165 | set(MIC TRUE) |
| 166 | set(real_os lrb) |
| 167 | endif() |
| 168 | if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") |
| 169 | set(FREEBSD TRUE) |
| 170 | endif() |
| 171 | |
| 172 | # Architecture |
| 173 | set(IA32 FALSE) |
| 174 | set(INTEL64 FALSE) |
| 175 | set(ARM FALSE) |
Jim Cownie | 3051f97 | 2014-08-07 10:12:54 | [diff] [blame^] | 176 | set(PPC64 FALSE) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 | [diff] [blame] | 177 | if("${arch}" STREQUAL "32") # IA-32 architecture |
| 178 | set(IA32 TRUE) |
| 179 | elseif("${arch}" STREQUAL "32e") # Intel(R) 64 architecture |
| 180 | set(INTEL64 TRUE) |
| 181 | elseif("${arch}" STREQUAL "arm") # ARM architecture |
| 182 | set(ARM TRUE) |
Jim Cownie | 3051f97 | 2014-08-07 10:12:54 | [diff] [blame^] | 183 | elseif("${arch}" STREQUAL "ppc64") # PPC64 architecture |
| 184 | set(PPC64 TRUE) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 | [diff] [blame] | 185 | endif() |
| 186 | |
| 187 | # Set some flags based on build_type |
| 188 | # cmake_build_type_lowercase is based off of CMAKE_BUILD_TYPE, just put in lowercase. |
| 189 | set(RELEASE_BUILD FALSE) |
| 190 | set(DEBUG_BUILD FALSE) |
| 191 | set(RELWITHDEBINFO_BUILD FALSE) |
| 192 | if("${cmake_build_type_lowercase}" STREQUAL "release") |
| 193 | set(RELEASE_BUILD TRUE) |
| 194 | elseif("${cmake_build_type_lowercase}" STREQUAL "debug") |
| 195 | set(DEBUG_BUILD TRUE) |
| 196 | elseif("${cmake_build_type_lowercase}" STREQUAL "relwithdebinfo") |
| 197 | set(RELWITHDEBINFO_BUILD TRUE) |
| 198 | endif() |
| 199 | |
| 200 | # Stats-gathering on or off? |
| 201 | set(STATS_GATHERING FALSE) |
| 202 | if("${stats}") # string "on" or "ON" is seen as boolean TRUE |
| 203 | set(STATS_GATHERING TRUE) |
| 204 | endif() |
| 205 | |
| 206 | # Include itt notify interface? Right now, always. |
| 207 | set(USE_ITT_NOTIFY TRUE) |
| 208 | |
| 209 | # normal, profile, stubs library. |
| 210 | set(NORMAL_LIBRARY FALSE) |
| 211 | set(STUBS_LIBRARY FALSE) |
| 212 | set(PROFILE_LIBRARY FALSE) |
| 213 | if("${lib_type}" STREQUAL "normal") |
| 214 | set(NORMAL_LIBRARY TRUE) |
| 215 | elseif("${lib_type}" STREQUAL "profile") |
| 216 | set(PROFILE_LIBRARY TRUE) |
| 217 | elseif("${lib_type}" STREQUAL "stubs") |
| 218 | set(STUBS_LIBRARY TRUE) |
| 219 | endif() |
| 220 | |
| 221 | ############################################### |
| 222 | # Features for compilation and build in general |
| 223 | |
| 224 | # - Does the compiler support a 128-bit floating point data type? Default is false |
| 225 | # - If a compiler does, then change it in the CMakeCache.txt file (or using the cmake GUI) |
| 226 | # or send to cmake -DCOMPILER_SUPPORTS_QUAD_PRECISION=true |
| 227 | # - If COMPILER_SUPPORTS_QUAD_PRECISION is true, then a corresponding COMPILER_QUAD_TYPE must be given |
| 228 | # This is the compiler's quad-precision data type. |
| 229 | # ** TODO: This isn't complete yet. Finish it. Requires changing macros in kmp_os.h ** |
| 230 | set(COMPILER_SUPPORTS_QUAD_PRECISION false CACHE BOOL "*INCOMPLETE* Does the compiler support a 128-bit floating point type?") |
| 231 | set(COMPILER_QUAD_TYPE "" CACHE STRING "*INCOMPLETE* The quad precision data type (i.e., for gcc, __float128)") |
| 232 | |
| 233 | # - Should the orignal build rules for builds be used? (cmake/OriginalBuildRules.cmake). This setting is off by default. |
| 234 | # - This always compiles with -g. And if it is a release build, the debug info is stripped out via objcopy and put into libiomp5.dbg. |
| 235 | set(USE_BUILDPL_RULES false CACHE BOOL "Should the build follow build.pl rules/recipes?") |
| 236 | |
| 237 | # - Should the build use the predefined linker flags (OS-dependent) in CommonFlags.cmake? |
| 238 | # - these predefined linker flags should work for Windows, Mac, and True Linux for the most popular compilers/linkers |
| 239 | set(USE_PREDEFINED_LINKER_FLAGS true CACHE BOOL "Should the build use the predefined linker flags in CommonFlags.cmake?") |
| 240 | |
| 241 | # - TSX based locks have __asm code which can be troublesome for some compilers. This feature is also x86 specific. |
| 242 | if({${IA32} OR ${INTEL64}) |
| 243 | set(USE_ADAPTIVE_LOCKS true CACHE BOOL "Should TSX-based lock be compiled (adaptive lock in kmp_lock.cpp). These are x86 specific.") |
| 244 | else() |
| 245 | set(USE_ADAPTIVE_LOCKS false CACHE BOOL "Should TSX-based lock be compiled (adaptive lock in kmp_lock.cpp). These are x86 specific.") |
| 246 | endif() |
| 247 | |
| 248 | ################################## |
| 249 | # Error checking the configuration |
| 250 | if(${STATS_GATHERING} AND (${WINDOWS} OR ${MAC})) |
| 251 | error_say("Stats-gathering functionality is only supported on x86-Linux and Intel(R) MIC Architecture") |
| 252 | endif() |
| 253 | if(${STATS_GATHERING} AND NOT (${IA32} OR ${INTEL64})) |
| 254 | error_say("Stats-gathering functionality is only supported on x86-Linux and Intel(R) MIC Architecture") |
| 255 | endif() |
| 256 | if(${USE_ADAPTIVE_LOCKS} AND NOT(${IA32} OR ${INTEL64})) |
| 257 | error_say("Adaptive locks (TSX) functionality is only supported on x86 Architecture") |
| 258 | endif() |
| 259 | |
| 260 | ############################################### |
| 261 | # - Create the suffix for the export directory |
| 262 | # - Only add to suffix when not a default value |
| 263 | # - Example suffix: .deb.30.s1 |
| 264 | # final export directory: exports/lin_32e.deb.30.s1/lib |
| 265 | # - These suffixes imply the build is a Debug, OpenMP 3.0, Stats-Gathering version of the library |
| 266 | if(NOT "${cmake_build_type_lowercase}" STREQUAL "release") |
| 267 | string(SUBSTRING "${cmake_build_type_lowercase}" 0 3 build_type_suffix) |
| 268 | set(suffix "${suffix}.${build_type_suffix}") |
| 269 | endif() |
| 270 | if(NOT "${omp_version}" STREQUAL "40") |
| 271 | set(suffix "${suffix}.${omp_version}") |
| 272 | endif() |
| 273 | if(${STATS_GATHERING}) |
| 274 | set(suffix "${suffix}.s1") |
| 275 | endif() |
| 276 | if(${MIC}) |
| 277 | if(NOT "${mic_arch}" STREQUAL "knf") |
| 278 | set(suffix "${suffix}.${mic_arch}") |
| 279 | endif() |
| 280 | if(NOT "${mic_os}" STREQUAL "bsd") |
| 281 | set(suffix "${suffix}.${mic_os}") |
| 282 | endif() |
| 283 | endif() |
| 284 | |
| 285 | #################################### |
| 286 | # Setting file extensions / suffixes |
| 287 | set(obj ${CMAKE_C_OUTPUT_EXTENSION} ) |
| 288 | set(lib ${CMAKE_STATIC_LIBRARY_SUFFIX}) |
| 289 | set(dll ${CMAKE_SHARED_LIBRARY_SUFFIX}) |
| 290 | set(exe ${CMAKE_EXECUTABLE_SUFFIX} ) |
| 291 | |
| 292 | ###################### |
| 293 | # Find perl executable |
| 294 | # Perl is used to create omp.h (and other headers) along with kmp_i18n_id.inc and kmp_i18n_default.inc (see below in Rules section) |
| 295 | if(NOT "${PERL_FOUND}") # variable is defined in FindPerl Standard CMake Module |
| 296 | error_say("Error: Could not find valid perl") |
| 297 | endif() |
| 298 | |
| 299 | ######################### |
| 300 | # Setting directory names |
| 301 | set(platform "${real_os}_${arch}" ) # i.e., lin_32e, mac_32 |
| 302 | set(build_dir "${CMAKE_CURRENT_BINARY_DIR}" ) # build directory (Where CMakeCache.txt is created, build files generated) |
| 303 | set(src_dir "${LIBOMP_WORK}/src" ) |
| 304 | set(tools_dir "${LIBOMP_WORK}/tools" ) |
| 305 | set(export_dir "${LIBOMP_WORK}/exports" ) |
| 306 | set(export_cmn_dir "${export_dir}/common${suffix}" ) |
| 307 | set(export_ptf_dir "${export_dir}/${platform}${suffix}") |
| 308 | _export_lib_dir(${platform} export_lib_dir) # set exports directory (relative to build_dir) i.e., ../exports/lin_32e/lib/ |
| 309 | # or i.e., ../exports/mac_32e/lib.thin/ for mac |
| 310 | if(${MAC}) |
| 311 | # macs use lib.thin/ subdirectory for non-fat libraries that only contain one architecture |
| 312 | # macs use lib/ subdirectory for fat libraries that contain both IA-32 architecture and Intel(R) 64 architecture code. |
| 313 | _export_lib_fat_dir(${platform} export_lib_fat_dir) |
| 314 | endif() |
| 315 | set(inc_dir "${LIBOMP_WORK}/src/include/${omp_version}") |
| 316 | |
| 317 | ############################ |
| 318 | # Setting final library name |
| 319 | set(lib_item "libiomp") |
| 320 | if(${PROFILE_LIBRARY}) |
| 321 | set(lib_item "${lib_item}prof") |
| 322 | endif() |
| 323 | if(${STUBS_LIBRARY}) |
| 324 | set(lib_item "${lib_item}stubs") |
| 325 | endif() |
| 326 | set(lib_item "${lib_item}${version}") |
| 327 | if(${WINDOWS}) |
| 328 | set(lib_item "${lib_item}md") |
| 329 | endif() |
| 330 | set(lib_ext "${dll}") |
| 331 | # ${lib_file} is real library name: |
| 332 | # libiomp5.so for Linux |
| 333 | # libiomp5.dylib for Mac |
| 334 | # libiomp5md.dll for Windows |
| 335 | set(lib_file "${lib_item}${lib_ext}") |
| 336 | |
| 337 | ######################################## |
| 338 | # Setting export file names (full paths) |
| 339 | if(${WINDOWS}) |
| 340 | set(imp_file "${lib_item}${lib}") # this is exported (libiomp5md.lib) |
| 341 | set(def_file "${lib_item}.def") # this is not exported |
| 342 | set(rc_file "${lib_item}.rc") # this is not exported |
| 343 | if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo" OR ${USE_BUILDPL_RULES}) |
| 344 | set(pdb_file "${lib_file}.pdb") # this is exported if it exists (libiomp5md.dll.pdb) |
| 345 | endif() |
| 346 | endif() |
| 347 | set(export_lib_files "${lib_file}" "${imp_file}" "${pdb_file}") |
| 348 | set(export_inc_files "iomp_lib.h") |
| 349 | set(export_mod_files "omp_lib.mod" "omp_lib_kinds.mod") |
| 350 | set(export_cmn_files1 "omp.h" "omp_lib.h" "omp_lib.f" "omp_lib.f90") |
| 351 | set(export_cmn_files2 "iomp.h") |
| 352 | add_prefix("${export_lib_dir}/" export_lib_files) |
| 353 | add_prefix("${export_ptf_dir}/include_compat/" export_inc_files) |
| 354 | add_prefix("${export_ptf_dir}/include/" export_mod_files) |
| 355 | add_prefix("${export_cmn_dir}/include/" export_cmn_files1) |
| 356 | add_prefix("${export_cmn_dir}/include_compat/" export_cmn_files2) |
| 357 | set(export_cmn_files "${export_cmn_files1}" "${export_cmn_files2}") |
| 358 | if("${export_lib_fat_dir}") |
| 359 | set(export_lib_fat_files "${lib_file}" "${imp_file}") |
| 360 | add_prefix("${export_lib_fat_dir}/" export_lib_fat_files) |
| 361 | endif() |
| 362 | |
| 363 | ######################### |
| 364 | # Getting legal type/arch |
| 365 | set_legal_type(legal_type) |
| 366 | set_legal_arch(legal_arch) |
| 367 | |
| 368 | ################################################# |
| 369 | # Preprocessor Definitions (cmake/Definitions.cmake) |
| 370 | # Preprocessor Includes |
| 371 | # Compiler (C/C++) Flags (cmake/CommonFlags.cmake) |
| 372 | # Assembler Flags (cmake/CommonFlags.cmake) |
| 373 | # Fortran Flags (cmake/CommonFlags.cmake) |
| 374 | # Linker Flags (cmake/CommonFlags.cmake) |
| 375 | # Archiver Flags (cmake/CommonFlags.cmake) |
| 376 | # Helper Perl Script Flags (cmake/PerlFlags.cmake) |
| 377 | # * Inside the cmake/CommonFlags.cmake file, the USER_*_FLAGS are added. |
| 378 | # * Cannot use CMAKE_*_FLAGS directly because -x c++ is put in the linker command and mangles the linking phase. |
| 379 | |
| 380 | # preprocessor flags (-D definitions and -I includes) |
| 381 | # Grab environment variable CPPFLAGS and append those to definitions |
| 382 | set(include_dirs ${CMAKE_CURRENT_BINARY_DIR} ${src_dir} ${src_dir}/i18n ${inc_dir} ${src_dir}/thirdparty/ittnotify) |
| 383 | include_directories(${include_dirs}) |
| 384 | |
| 385 | # Grab assembler-dependent flags |
| 386 | # CMake will look for cmake/${CMAKE_ASM_COMPILER_ID}/AsmFlags.cmake to append additional assembler flags. |
| 387 | if(${WINDOWS}) |
| 388 | # Windows based systems use CMAKE_ASM_MASM_COMPILER |
| 389 | # The windows assembly files are in MASM format, and they require a tool that can handle MASM syntax (ml.exe or ml64.exe typically) |
| 390 | enable_language(ASM_MASM) |
| 391 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_ASM_MASM_COMPILER_ID} ${CMAKE_MODULE_PATH}) |
| 392 | find_file(assembler_specific_include_file_found AsmFlags.cmake ${CMAKE_MODULE_PATH}) |
| 393 | if(assembler_specific_include_file_found) |
| 394 | include(AsmFlags) |
| 395 | append_assembler_specific_asm_flags(ASM_FLAGS) |
| 396 | else() |
| 397 | warning_say("Could not find cmake/${CMAKE_ASM_MASM_COMPILER_ID}/AsmFlags.cmake: will only use default flags") |
| 398 | endif() |
| 399 | else() |
| 400 | # Unix (including Mac) based systems use CMAKE_ASM_COMPILER |
| 401 | # Unix assembly files can be handled by compiler usually. |
| 402 | enable_language(ASM) |
| 403 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_ASM_COMPILER_ID} ${CMAKE_MODULE_PATH}) |
| 404 | find_file(assembler_specific_include_file_found AsmFlags.cmake ${CMAKE_MODULE_PATH}) |
| 405 | if(assembler_specific_include_file_found) |
| 406 | include(AsmFlags) |
| 407 | append_assembler_specific_asm_flags(ASM_FLAGS) |
| 408 | else() |
| 409 | warning_say("Could not find cmake/${CMAKE_ASM_COMPILER_ID}/AsmFlags.cmake: will only use default flags") |
| 410 | endif() |
| 411 | endif() |
| 412 | # Grab compiler-dependent flags |
| 413 | # Cmake will look for cmake/${CMAKE_C_COMPILER_ID}/CFlags.cmake to append additional c, cxx, and linker flags. |
| 414 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_C_COMPILER_ID} ${CMAKE_MODULE_PATH}) |
| 415 | find_file(compiler_specific_include_file_found CFlags.cmake ${CMAKE_MODULE_PATH}) |
| 416 | if(compiler_specific_include_file_found) |
| 417 | include(CFlags) # COMPILER_SUPPORTS_QUAD_PRECISION changed in here |
| 418 | append_compiler_specific_c_and_cxx_flags(C_FLAGS CXX_FLAGS) |
| 419 | append_compiler_specific_linker_flags(LD_FLAGS LD_LIB_FLAGS) |
| 420 | else() |
| 421 | warning_say("Could not find cmake/${CMAKE_C_COMPILER_ID}/CFlags.cmake: will only use default flags") |
| 422 | endif() |
| 423 | |
| 424 | # Grab all the compiler-independent flags |
| 425 | append_c_and_cxx_flags_common(C_FLAGS CXX_FLAGS) |
| 426 | append_asm_flags_common(ASM_FLAGS) |
| 427 | append_fort_flags_common(F_FLAGS) |
| 428 | append_linker_flags_common(LD_FLAGS LD_LIB_FLAGS) |
| 429 | append_archiver_flags_common(AR_FLAGS) |
| 430 | append_cpp_flags(DEFINITIONS_FLAGS) |
| 431 | |
| 432 | # Setup the flags correctly for cmake (covert to string) |
| 433 | # Pretty them up (STRIP any beginning and trailing whitespace) |
| 434 | list_to_string("${DEFINITIONS_FLAGS}" DEFINITIONS_FLAGS) |
| 435 | list_to_string("${C_FLAGS}" C_FLAGS ) |
| 436 | list_to_string("${CXX_FLAGS}" CXX_FLAGS ) |
| 437 | list_to_string("${ASM_FLAGS}" ASM_FLAGS ) |
| 438 | list_to_string("${LD_FLAGS}" LD_FLAGS ) |
| 439 | list_to_string("${LD_LIB_FLAGS}" LD_LIB_FLAGS ) |
| 440 | list_to_string("${AR_FLAGS}" AR_FLAGS ) # Windows specific for creating import library |
| 441 | string(STRIP "${DEFINITIONS_FLAGS}" DEFINITIONS_FLAGS) |
| 442 | string(STRIP "${C_FLAGS}" C_FLAGS ) |
| 443 | string(STRIP "${CXX_FLAGS}" CXX_FLAGS ) |
| 444 | string(STRIP "${ASM_FLAGS}" ASM_FLAGS ) |
| 445 | string(STRIP "${LD_FLAGS}" LD_FLAGS ) |
| 446 | string(STRIP "${LD_LIB_FLAGS}" LD_LIB_FLAGS ) |
| 447 | string(STRIP "${AR_FLAGS}" AR_FLAGS ) # Windows specific for creating import library |
| 448 | |
| 449 | # Grab the Perl flags |
| 450 | set_ev_flags(ev_flags) # expand-vars.pl flags |
| 451 | set_gd_flags(gd_flags) # generate-def.pl flags (Windows only) |
| 452 | set(oa_opts "--os=${real_os}" "--arch=${arch}") # sent to the perl scripts |
| 453 | |
| 454 | ######################################################### |
| 455 | # Getting correct source files (cmake/SourceFiles.cmake) |
| 456 | set_c_files(lib_c_items) |
| 457 | set_cpp_files(lib_cxx_items) |
| 458 | set_asm_files(lib_asm_items) |
| 459 | set_imp_c_files(imp_c_items) # Windows-specific |
| 460 | |
| 461 | ################################### |
| 462 | # Setting all source file variables |
| 463 | set(lib_src_files "${lib_c_items}" "${lib_cxx_items}" "${lib_asm_items}") |
| 464 | set(imp_src_files "${imp_c_items}") |
| 465 | add_prefix("${src_dir}/" lib_src_files) |
| 466 | add_prefix("${src_dir}/" imp_src_files) # Windows-specific |
| 467 | add_prefix("${src_dir}/" lib_c_items ) |
| 468 | add_prefix("${src_dir}/" lib_cxx_items) |
| 469 | add_prefix("${src_dir}/" lib_asm_items) |
| 470 | add_prefix("${src_dir}/" imp_c_items ) # Windows-specific |
| 471 | |
| 472 | ##################################################################### |
| 473 | # Debug print outs. Will print "variable = ${variable}" if GLOBAL_DEBUG == 1 |
| 474 | if(GLOBAL_DEBUG) |
| 475 | include(CMakePrintSystemInformation) |
| 476 | endif() |
| 477 | debug_say_var(CMAKE_ASM_COMPILE_OBJECT) |
| 478 | debug_say_var(CMAKE_RC_COMPILER) |
| 479 | debug_say_var(CMAKE_C_COMPILER_ID) |
| 480 | debug_say_var(LIBOMP_WORK) |
| 481 | debug_say_var(date) |
| 482 | debug_say_var(stats) |
| 483 | debug_say_var(lib_file) |
| 484 | debug_say_var(export_lib_files) |
| 485 | debug_say_var(DEFINITIONS_FLAGS) |
| 486 | debug_say_var(C_FLAGS) |
| 487 | debug_say_var(CXX_FLAGS) |
| 488 | debug_say_var(ASM_FLAGS) |
| 489 | debug_say_var(F_FLAGS) |
| 490 | debug_say_var(LD_FLAGS) |
| 491 | debug_say_var(LD_LIB_FLAGS) |
| 492 | debug_say_var(AR_FLAGS) |
| 493 | debug_say_var(ev_flags) |
| 494 | debug_say_var(gd_flags) |
| 495 | debug_say_var(oa_opts) |
| 496 | debug_say_var(lib_c_items) |
| 497 | debug_say_var(lib_cxx_items) |
| 498 | debug_say_var(lib_asm_items) |
| 499 | debug_say_var(imp_c_items) |
| 500 | debug_say_var(lib_src_files) |
| 501 | debug_say_var(imp_src_files) |
| 502 | |
| 503 | #################################################################### |
| 504 | # --------------------- # |
| 505 | # --- Rules/Recipes --- # |
| 506 | # --------------------- # |
| 507 | #################################################################### |
| 508 | # Below, ${ldeps} always stands for "local dependencies" for the |
| 509 | # next immediate target to be created via add_custom_target() or |
| 510 | # add_custom_command() |
| 511 | |
| 512 | #################### |
| 513 | # --- Create all --- |
| 514 | add_custom_target(lib ALL DEPENDS ${export_lib_files}) |
| 515 | add_custom_target(inc ALL DEPENDS ${export_inc_files}) |
| 516 | if(${create_fortran_modules}) |
| 517 | add_custom_target(mod ALL DEPENDS ${export_mod_files}) |
| 518 | endif() |
| 519 | # --- Enforce the tests to be completed/skipped before copying to exports directory --- |
| 520 | if(${tests}) |
| 521 | if(${WINDOWS}) |
| 522 | set(test-dependencies test-touch-mt/.success test-touch-md/.success test-relo/.success test-execstack/.success test-instr/.success test-deps/.success) |
| 523 | else() |
| 524 | set(test-dependencies test-touch-rt/.success test-relo/.success test-execstack/.success test-instr/.success test-deps/.success) |
| 525 | endif() |
| 526 | set_source_files_properties(${export_lib_files} PROPERTIES OBJECT_DEPENDS "${test-dependencies}") |
| 527 | endif() |
| 528 | |
| 529 | ############################# |
| 530 | # --- Create Common Files --- |
| 531 | add_custom_target(common DEPENDS ${export_cmn_files}) |
| 532 | add_custom_target(clean-common COMMAND ${CMAKE_COMMAND} -E remove -f ${export_cmn_files}) |
| 533 | |
| 534 | ########################################## |
| 535 | # --- Copy files to export directories --- |
| 536 | # - just a simple copy recipe which acts as an install step |
| 537 | # - copies out of the src_dir into the dest_dir |
| 538 | # |
| 539 | # dest_dir/target : src_dir/target |
| 540 | # cp src_dir/target dest_dir/target |
| 541 | macro (simple_copy_recipe target src_dir dest_dir) |
| 542 | get_source_file_property(extra_depends ${dest_dir}/${target} OBJECT_DEPENDS) |
| 543 | if("${extra_depends}" MATCHES "NOTFOUND") |
| 544 | set(extra_depends) |
| 545 | endif() |
| 546 | set(ldeps ${src_dir}/${target} "${extra_depends}") |
| 547 | if(NOT "${target}" STREQUAL "") |
| 548 | file(MAKE_DIRECTORY ${dest_dir}) # make sure destination directory exists |
| 549 | add_custom_command( |
| 550 | OUTPUT ${dest_dir}/${target} |
| 551 | COMMAND ${CMAKE_COMMAND} -E copy ${src_dir}/${target} ${dest_dir}/${target} |
| 552 | DEPENDS ${ldeps} |
| 553 | ) |
| 554 | endif() |
| 555 | endmacro() |
| 556 | # copy from build directory to final resting places in exports directory |
| 557 | simple_copy_recipe("omp.h" "${build_dir}" "${export_cmn_dir}/include") |
| 558 | simple_copy_recipe("omp_lib.h" "${build_dir}" "${export_cmn_dir}/include") |
| 559 | simple_copy_recipe("omp_lib.f" "${build_dir}" "${export_cmn_dir}/include") |
| 560 | simple_copy_recipe("omp_lib.f90" "${build_dir}" "${export_cmn_dir}/include") |
| 561 | simple_copy_recipe("iomp.h" "${build_dir}" "${export_cmn_dir}/include_compat") |
| 562 | simple_copy_recipe("${lib_file}" "${build_dir}" "${export_lib_dir}") |
| 563 | simple_copy_recipe("${imp_file}" "${build_dir}" "${export_lib_dir}") |
| 564 | simple_copy_recipe("${pdb_file}" "${build_dir}" "${export_lib_dir}") |
| 565 | simple_copy_recipe("${dbg_file}" "${build_dir}" "${export_lib_dir}") |
| 566 | simple_copy_recipe("omp_lib.mod" "${build_dir}" "${export_ptf_dir}/include") |
| 567 | simple_copy_recipe("omp_lib_kinds.mod" "${build_dir}" "${export_ptf_dir}/include") |
| 568 | simple_copy_recipe("iomp_lib.h" "${build_dir}" "${export_ptf_dir}/include_compat") |
| 569 | |
| 570 | ###################################################### |
| 571 | # --- Build the main library --- |
| 572 | # $(lib_file) <== Main library file to create |
| 573 | |
| 574 | # objects depend on : .inc files and omp.h |
| 575 | # This way the *.inc and omp.h are generated before any compilations take place |
| 576 | add_custom_target(needed-headers DEPENDS ${build_dir}/kmp_i18n_id.inc ${build_dir}/kmp_i18n_default.inc ${build_dir}/omp.h) |
| 577 | |
| 578 | # For Windows, there is a definitions file (.def) and resource file (.res) created using generate-def.pl and rc.exe respectively. |
| 579 | if(${WINDOWS}) |
| 580 | add_custom_target(needed-windows-files DEPENDS ${build_dir}/${def_file} ${build_dir}/${rc_file}) |
| 581 | list(APPEND lib_src_files ${build_dir}/${rc_file}) |
| 582 | # The windows assembly files are in MASM format, and they require a tool that can handle MASM syntax (ml.exe or ml64.exe typically) |
| 583 | enable_language(ASM_MASM) |
| 584 | else() |
| 585 | # Unix assembly files can be handled by compiler. |
| 586 | enable_language(ASM) |
| 587 | endif() |
| 588 | |
| 589 | # Remove any cmake-automatic linking of libraries by linker, This is so linux |
| 590 | # and mac don't include libstdc++ just because we compile c++ files. |
| 591 | if(${USE_PREDEFINED_LINKER_FLAGS}) |
| 592 | set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "") |
| 593 | set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") |
| 594 | set(CMAKE_ASM_IMPLICIT_LINK_LIBRARIES "") |
| 595 | endif() |
| 596 | |
| 597 | # --- ${lib_file} rule --- |
| 598 | add_library(iomp5 SHARED ${lib_src_files}) |
| 599 | set_target_properties(iomp5 PROPERTIES |
| 600 | PREFIX "" SUFFIX "" # Take control |
| 601 | OUTPUT_NAME "${lib_file}" # of output name |
| 602 | LINK_FLAGS "${LD_FLAGS}" |
| 603 | LINKER_LANGUAGE C # use C Compiler for linking step |
| 604 | SKIP_BUILD_RPATH true # have Mac linker -install_name just be "-install_name libiomp5.dylib" |
| 605 | ) |
| 606 | # Target lib (export files) depend on the library (iomp5) being built |
| 607 | add_dependencies(lib iomp5) |
| 608 | |
| 609 | # Linking command will include libraries in LD_LIB_FLAGS |
| 610 | target_link_libraries(iomp5 ${LD_LIB_FLAGS}) |
| 611 | |
| 612 | # Create *.inc and omp.h before compiling any sources |
| 613 | add_dependencies(iomp5 needed-headers) |
| 614 | if(${WINDOWS}) |
| 615 | # Create .def and .rc file before compiling any sources |
| 616 | add_dependencies(iomp5 needed-windows-files) |
| 617 | endif() |
| 618 | |
| 619 | # Set the compiler flags for each type of source |
| 620 | set_source_files_properties(${lib_c_items} |
| 621 | ${imp_c_items} PROPERTIES COMPILE_FLAGS "${C_FLAGS}" ) |
| 622 | set_source_files_properties(${lib_cxx_items} PROPERTIES COMPILE_FLAGS "${CXX_FLAGS}") |
| 623 | set_source_files_properties(${lib_asm_items} PROPERTIES COMPILE_FLAGS "${ASM_FLAGS}") |
| 624 | # Set the -D definitions for all sources |
| 625 | add_definitions(${DEFINITIONS_FLAGS}) |
| 626 | |
| 627 | # If creating a build that imitates build.pl's rules then set USE_BUILDPL_RULES to true |
| 628 | if(${USE_BUILDPL_RULES}) |
| 629 | include(BuildPLRules) |
| 630 | endif() |
| 631 | |
| 632 | ###################################################### |
| 633 | # --- Source file specific flags --- |
| 634 | # kmp_version.o : -D _KMP_BUILD_TIME="\"$(date)}\"" |
| 635 | set_source_files_properties(${src_dir}/kmp_version.c PROPERTIES COMPILE_DEFINITIONS "_KMP_BUILD_TIME=\"\\\"${date}\\\"\"") |
| 636 | |
| 637 | # z_Linux_asm.o : -D KMP_ARCH_* |
| 638 | if(${ARM}) |
| 639 | set_source_files_properties(${src_dir}/z_Linux_asm.s PROPERTIES COMPILE_DEFINITIONS "KMP_ARCH_ARM") |
| 640 | elseif(${INTEL64}) |
| 641 | set_source_files_properties(${src_dir}/z_Linux_asm.s PROPERTIES COMPILE_DEFINITIONS "KMP_ARCH_X86_64") |
| 642 | elseif(${IA32}) |
| 643 | set_source_files_properties(${src_dir}/z_Linux_asm.s PROPERTIES COMPILE_DEFINITIONS "KMP_ARCH_X86") |
Jim Cownie | 3051f97 | 2014-08-07 10:12:54 | [diff] [blame^] | 644 | elseif(${PPC64}) |
| 645 | set_source_files_properties(${src_dir}/z_Linux_asm.s PROPERTIES COMPILE_DEFINITIONS "KMP_ARCH_PPC64") |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 | [diff] [blame] | 646 | endif() |
| 647 | |
| 648 | if(${WINDOWS}) |
| 649 | set_source_files_properties(${src_dir}/thirdparty/ittnotify/ittnotify_static.c PROPERTIES COMPILE_DEFINITIONS "UNICODE") |
| 650 | endif() |
| 651 | |
| 652 | ###################################################### |
| 653 | # MAC specific build rules |
| 654 | if(${MAC}) |
| 655 | # fat library rules |
| 656 | if(${INTEL64}) |
| 657 | _export_lib_fat_dir( "mac_32e" export_fat_mac_32e) |
| 658 | _export_lib_dir( "mac_32" export_mac_32 ) |
| 659 | _export_lib_dir( "mac_32e" export_mac_32e ) |
| 660 | file(MAKE_DIRECTORY ${export_fat_mac_32e}) |
| 661 | add_custom_target(fat |
| 662 | COMMAND ${CMAKE_COMMAND} -E echo Building 32 and 32e fat libraries from ${export_mac_32}/${lib_file} and ${export_mac_32e}/${lib_file} |
| 663 | COMMAND ${CMAKE_COMMAND} -E echo Will put fat library in ${export_fat_mac_32e} directory |
| 664 | COMMAND lipo -create -output ${export_fat_mac_32e}/${lib_file} ${export_mac_32}/${lib_file} ${export_mac_32e}/${lib_file} |
| 665 | ) |
| 666 | endif() |
| 667 | endif() |
| 668 | |
| 669 | ###################################################### |
| 670 | # Windows specific build rules |
| 671 | if(${WINDOWS}) |
| 672 | |
| 673 | # --- Create $(imp_file) --- |
| 674 | # This file is first created in the unstripped/${lib_file} creation step. |
| 675 | # It is then "re-linked" to include kmp_import.c which prevents linking of both Visual Studio OpenMP and newly built OpenMP |
| 676 | if(NOT "${imp_file}" STREQUAL "") |
| 677 | set(generated_import_file ${lib_file}${lib}) |
| 678 | add_library(iomp5imp STATIC ${generated_import_file} ${imp_src_files}) |
| 679 | set_source_files_properties(${generated_import_file} PROPERTIES GENERATED TRUE EXTERNAL_OBJECT TRUE) |
| 680 | set_target_properties(iomp5imp PROPERTIES |
| 681 | PREFIX "" SUFFIX "" |
| 682 | OUTPUT_NAME "${imp_file}" |
| 683 | STATIC_LIBRARY_FLAGS "${AR_FLAGS}" |
| 684 | LINKER_LANGUAGE C |
| 685 | SKIP_BUILD_RPATH true |
| 686 | ) |
| 687 | add_custom_command(TARGET iomp5imp PRE_BUILD COMMAND ${CMAKE_COMMAND} -E remove -f ${imp_file}) |
| 688 | add_dependencies(iomp5imp iomp5) |
| 689 | endif() |
| 690 | |
| 691 | # --- Create $(def_file) --- |
| 692 | if(NOT "${def_file}" STREQUAL "") |
| 693 | string_to_list("${gd_flags}" gd_flags) |
| 694 | add_custom_command( |
| 695 | OUTPUT ${def_file} |
| 696 | COMMAND ${PERL_EXECUTABLE} ${tools_dir}/generate-def.pl ${gd_flags} -o ${def_file} ${src_dir}/dllexports |
| 697 | DEPENDS ${src_dir}/dllexports ${tools_dir}/generate-def.pl |
| 698 | ) |
| 699 | endif() |
| 700 | |
| 701 | # --- Create $(rc_file) --- |
| 702 | if(NOT "${rc_file}" STREQUAL "") |
| 703 | add_custom_command( |
| 704 | OUTPUT ${rc_file} |
| 705 | COMMAND ${CMAKE_COMMAND} -E copy libiomp.rc ${rc_file} |
| 706 | DEPENDS libiomp.rc |
| 707 | ) |
| 708 | endif() |
| 709 | endif() |
| 710 | |
| 711 | ###################################################### |
| 712 | # kmp_i18n_id.inc and kmp_i18n_default.inc |
| 713 | set(perlcmd "${PERL_EXECUTABLE}" "${tools_dir}/message-converter.pl" "${oa_opts}" "--prefix=kmp_i18n" "--enum=kmp_i18n_id.inc" "${src_dir}/i18n/en_US.txt") |
| 714 | add_custom_command( |
| 715 | OUTPUT ${build_dir}/kmp_i18n_id.inc |
| 716 | COMMAND ${perlcmd} |
| 717 | DEPENDS ${src_dir}/i18n/en_US.txt ${tools_dir}/message-converter.pl |
| 718 | ) |
| 719 | set(perlcmd "${PERL_EXECUTABLE}" "${tools_dir}/message-converter.pl" "${oa_opts}" "--prefix=kmp_i18n" "--default=kmp_i18n_default.inc" "${src_dir}/i18n/en_US.txt") |
| 720 | add_custom_command( |
| 721 | OUTPUT ${build_dir}/kmp_i18n_default.inc |
| 722 | COMMAND ${perlcmd} |
| 723 | DEPENDS ${src_dir}/i18n/en_US.txt ${tools_dir}/message-converter.pl |
| 724 | ) |
| 725 | |
| 726 | ###################################################### |
| 727 | # Micro test rules for after library has been built (cmake/MicroTests.cmake) |
| 728 | # - Only perform if ${tests} == true (specify when invoking: cmake -Dtests=on ...) |
| 729 | if(${tests}) |
| 730 | include(MicroTests) |
| 731 | endif() |
| 732 | |
| 733 | ###################################################### |
| 734 | # --- Create Fortran Files --- |
| 735 | # omp_lib.mod |
| 736 | if(${create_fortran_modules}) |
| 737 | # Grab fortran-compiler-dependent flags |
| 738 | # Cmake will look for cmake/${CMAKE_Fortran_COMPILER_ID}/FortranFlags.cmake to append additional fortran flags. |
| 739 | enable_language(Fortran) |
| 740 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_Fortran_COMPILER_ID} ${CMAKE_MODULE_PATH}) |
| 741 | find_file(fortran_specific_include_file_found FortranFlags.cmake ${CMAKE_MODULE_PATH}) |
| 742 | if(fortran_specific_include_file_found) |
| 743 | include(FortranFlags) |
| 744 | append_fortran_compiler_specific_fort_flags(F_FLAGS) |
| 745 | else() |
| 746 | warning_say("Could not find cmake/${CMAKE_Fortran_COMPILER_ID}/FortranFlags.cmake: will only use default flags in CommonFlags.cmake") |
| 747 | endif() |
| 748 | set(omp_lib_f "omp_lib.f90" ) |
| 749 | add_custom_command( |
| 750 | OUTPUT "omp_lib.mod" |
| 751 | COMMAND ${CMAKE_Fortran_COMPILER} -c ${F_FLAGS} ${omp_lib_f} |
| 752 | DEPENDS ${omp_lib_f} |
| 753 | ) |
| 754 | add_custom_command( |
| 755 | OUTPUT "omp_lib_kinds.mod" |
| 756 | COMMAND ${CMAKE_Fortran_COMPILER} -c ${F_FLAGS} ${omp_lib_f} |
| 757 | DEPENDS ${omp_lib_f} |
| 758 | ) |
| 759 | # clean omp_lib.o from build directory when "make clean" |
| 760 | set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES omp_lib${obj}) |
| 761 | endif() |
| 762 | |
| 763 | ############################################################### |
| 764 | # --- Using expand-vars.pl to generate files --- |
| 765 | # - 'file' is generated using expand-vars.pl and 'file'.var |
| 766 | # - Any .h .f .f90 .rc files should be created with this recipe |
| 767 | macro(expand_vars_recipe filename) |
| 768 | get_source_file_property(extra_ev_flags ${filename} COMPILE_DEFINITIONS) |
| 769 | if("${extra_ev_flags}" MATCHES "NOTFOUND") |
| 770 | set(extra_ev_flags) |
| 771 | else() |
| 772 | string_to_list("${extra_ev_flags}" extra_ev_flags) |
| 773 | endif() |
| 774 | find_file(${filename}_path ${filename}.var PATHS ${src_dir}/include/${omp_version} ${src_dir}) |
| 775 | set(ldeps "${${filename}_path}" "${src_dir}/kmp_version.c" "${tools_dir}/expand-vars.pl") |
| 776 | set(expandvarscmd ${PERL_EXECUTABLE} ${tools_dir}/expand-vars.pl --strict ${ev_flags} ${extra_ev_flags} ${${filename}_path} ${filename}) |
| 777 | if(NOT "${filename}" STREQUAL "") |
| 778 | add_custom_command( |
| 779 | OUTPUT ${filename} |
| 780 | COMMAND ${expandvarscmd} |
| 781 | DEPENDS ${ldeps} |
| 782 | ) |
| 783 | endif() |
| 784 | endmacro() |
| 785 | string_to_list("${ev_flags}" ev_flags) |
| 786 | # omp_lib.h : ev-flags += -D KMP_INT_PTR_KIND="int_ptr_kind()" |
| 787 | set_source_files_properties(omp_lib.h PROPERTIES COMPILE_DEFINITIONS "-D KMP_INT_PTR_KIND=\"int_ptr_kind()\"") |
| 788 | # iomp_lib.h : ev-flags += -D KMP_INT_PTR_KIND=$(if $(filter 32,$(arch)),4,8) |
| 789 | if(${IA32}) # 32 bit archs |
| 790 | set_source_files_properties(iomp_lib.h PROPERTIES COMPILE_DEFINITIONS "-D KMP_INT_PTR_KIND=4") |
| 791 | else() |
| 792 | set_source_files_properties(iomp_lib.h PROPERTIES COMPILE_DEFINITIONS "-D KMP_INT_PTR_KIND=8") |
| 793 | endif() |
| 794 | # libiomp.rc : ev-flags += -D KMP_FILE=$(lib_file) |
| 795 | set_source_files_properties(libiomp.rc PROPERTIES COMPILE_DEFINITIONS "-D KMP_FILE=${lib_file}") |
| 796 | expand_vars_recipe(omp.h) |
| 797 | expand_vars_recipe(omp_lib.h) |
| 798 | expand_vars_recipe(omp_lib.f) |
| 799 | expand_vars_recipe(omp_lib.f90) |
| 800 | expand_vars_recipe(iomp.h) |
| 801 | expand_vars_recipe(iomp_lib.h) |
| 802 | expand_vars_recipe(libiomp.rc) |
| 803 | |
| 804 | |
| 805 | #################################################################### |
| 806 | # Print configuration after all variables are set. |
| 807 | say("") |
| 808 | say("----------------------- CONFIGURATION -----------------------") |
| 809 | say("Operating System : ${os}") |
| 810 | say("Architecture : ${arch}") |
| 811 | say("Build Type : ${CMAKE_BUILD_TYPE}") |
| 812 | say("OpenMP Version : ${omp_version}") |
| 813 | say("Lib Type : ${lib_type}") |
| 814 | if(${MIC}) |
| 815 | say("Intel(R) MIC Architecture : ${mic_arch}") |
| 816 | say("Intel(R) MIC Architecture OS : ${mic_os}") |
| 817 | endif() |
| 818 | say("Fortran Modules : ${create_fortran_modules}") |
| 819 | # will say development if all zeros |
| 820 | if("${build_number}" STREQUAL "00000000") |
| 821 | set(build "development") |
| 822 | else() |
| 823 | set(build "${build_number}") |
| 824 | endif() |
| 825 | say("Build : ${build}") |
| 826 | say("Stats-Gathering : ${stats}") |
| 827 | say("Use build.pl rules : ${USE_BUILDPL_RULES}") |
| 828 | say("Adaptive locks : ${USE_ADAPTIVE_LOCKS}") |
| 829 | say("Use predefined linker flags : ${USE_PREDEFINED_LINKER_FLAGS}") |
| 830 | say("Compiler supports quad precision : ${COMPILER_SUPPORTS_QUAD_PRECISION}") |
| 831 | say("-------------------------------------------------------------") |
| 832 | say("") |
| 833 | |