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