blob: 62c84c6e414fce9dd2ef5d09f254cebadf2e5ac0 [file] [log] [blame]
Jim Cownie3b81ce62014-08-05 09:32:281#
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:3311
Jim Cownie3b81ce62014-08-05 09:32:2812################
13# CMAKE libiomp5
14cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
15project(libiomp C CXX)
Alp Toker7198f522014-06-01 18:01:3316
Jim Cownie3b81ce62014-08-05 09:32:2817#########
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)
Jim Cownie3051f972014-08-07 10:12:5452set(arch_possible_values 32e 32 arm ppc64)
Jim Cownie3b81ce62014-08-05 09:32:2853set(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
Jim Cownie3051f972014-08-07 10:12:5474# set to default architecture if the user did not specify an architecture explicitly
75if(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 Cownie3b81ce62014-08-05 09:32:2881endif()
82
83set(lib_type normal CACHE STRING "Performance,Profiling,Stubs library (normal/profile/stubs)")
84set(version 5 CACHE STRING "Produce libguide (version 4) or libiomp5 (version 5)")
85set(omp_version 40 CACHE STRING "The OpenMP version (40/30)")
86set(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.")
87set(mic_os lin CACHE STRING "Intel(R) MIC Architecture operating system (bsd/lin). Ignored if not Intel(R) MIC Architecture build.")
88set(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
93set(test_touch true CACHE BOOL "Perform a small touch test?" )
94set(test_relo true CACHE BOOL "Perform a relocation test for dynamic libraries?" )
95set(test_execstack true CACHE BOOL "Perform a execstack test for linux dynamic libraries?" )
96set(test_instr true CACHE BOOL "Perform an instruction test for Intel(R) MIC Architecture libraries?" )
97set(test_deps true CACHE BOOL "Perform a library dependency test?" )
98set(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.
102set(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)
105set(USER_C_FLAGS "" CACHE STRING "Appended user specified C compiler flags." )
106set(USER_CXX_FLAGS "" CACHE STRING "Appended user specified C++ compiler flags." )
107set(USER_CPP_FLAGS "" CACHE STRING "Appended user specified C preprocessor flags." )
108set(USER_ASM_FLAGS "" CACHE STRING "Appended user specified assembler flags." )
109set(USER_LD_FLAGS "" CACHE STRING "Appended user specified linker flags." )
110set(USER_LD_LIB_FLAGS "" CACHE STRING "Appended user specified linked libs flags. (i.e., -lm)")
111set(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
119if(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}")
123else()
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}")
129endif()
130
131# Check valid values
132check_variable(os "${os_possible_values}" )
133check_variable(arch "${arch_possible_values}" )
134check_variable(omp_version "${omp_version_possible_values}")
135check_variable(lib_type "${lib_type_possible_values}" )
136if("${os}" STREQUAL "mic")
137 check_variable(mic_arch "${mic_arch_possible_values}" )
138 check_variable(mic_os "${mic_os_possible_values}" )
139endif()
140# Get the build number from kmp_version.c
141get_build_number("${LIBOMP_WORK}" build_number)
142
143# Getting time and date
144# As of now, no timestamp will be created.
145set(date "No Timestamp")
146
147#################################################################
148# Set some useful flags variables for other parts of cmake to use
149# Operating System
150set(LINUX FALSE)
151set(MAC FALSE)
152set(WINDOWS FALSE)
153set(MIC FALSE)
154set(FREEBSD FALSE)
155if("${os}" STREQUAL "lin")
156 set(LINUX TRUE)
157 set(real_os lin)
158elseif("${os}" STREQUAL "mac")
159 set(MAC TRUE)
160 set(real_os mac)
161elseif("${os}" STREQUAL "win")
162 set(WINDOWS TRUE)
163 set(real_os win)
164elseif("${os}" STREQUAL "mic")
165 set(MIC TRUE)
166 set(real_os lrb)
167endif()
168if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
169 set(FREEBSD TRUE)
170endif()
171
172# Architecture
173set(IA32 FALSE)
174set(INTEL64 FALSE)
175set(ARM FALSE)
Jim Cownie3051f972014-08-07 10:12:54176set(PPC64 FALSE)
Jim Cownie3b81ce62014-08-05 09:32:28177if("${arch}" STREQUAL "32") # IA-32 architecture
178 set(IA32 TRUE)
179elseif("${arch}" STREQUAL "32e") # Intel(R) 64 architecture
180 set(INTEL64 TRUE)
181elseif("${arch}" STREQUAL "arm") # ARM architecture
182 set(ARM TRUE)
Jim Cownie3051f972014-08-07 10:12:54183elseif("${arch}" STREQUAL "ppc64") # PPC64 architecture
184 set(PPC64 TRUE)
Jim Cownie3b81ce62014-08-05 09:32:28185endif()
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.
189set(RELEASE_BUILD FALSE)
190set(DEBUG_BUILD FALSE)
191set(RELWITHDEBINFO_BUILD FALSE)
192if("${cmake_build_type_lowercase}" STREQUAL "release")
193 set(RELEASE_BUILD TRUE)
194elseif("${cmake_build_type_lowercase}" STREQUAL "debug")
195 set(DEBUG_BUILD TRUE)
196elseif("${cmake_build_type_lowercase}" STREQUAL "relwithdebinfo")
197 set(RELWITHDEBINFO_BUILD TRUE)
198endif()
199
200# Stats-gathering on or off?
201set(STATS_GATHERING FALSE)
202if("${stats}") # string "on" or "ON" is seen as boolean TRUE
203 set(STATS_GATHERING TRUE)
204endif()
205
206# Include itt notify interface? Right now, always.
207set(USE_ITT_NOTIFY TRUE)
208
209# normal, profile, stubs library.
210set(NORMAL_LIBRARY FALSE)
211set(STUBS_LIBRARY FALSE)
212set(PROFILE_LIBRARY FALSE)
213if("${lib_type}" STREQUAL "normal")
214 set(NORMAL_LIBRARY TRUE)
215elseif("${lib_type}" STREQUAL "profile")
216 set(PROFILE_LIBRARY TRUE)
217elseif("${lib_type}" STREQUAL "stubs")
218 set(STUBS_LIBRARY TRUE)
219endif()
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 **
230set(COMPILER_SUPPORTS_QUAD_PRECISION false CACHE BOOL "*INCOMPLETE* Does the compiler support a 128-bit floating point type?")
231set(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.
235set(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
239set(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.
242if({${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.")
244else()
245 set(USE_ADAPTIVE_LOCKS false CACHE BOOL "Should TSX-based lock be compiled (adaptive lock in kmp_lock.cpp). These are x86 specific.")
246endif()
247
248##################################
249# Error checking the configuration
250if(${STATS_GATHERING} AND (${WINDOWS} OR ${MAC}))
251 error_say("Stats-gathering functionality is only supported on x86-Linux and Intel(R) MIC Architecture")
252endif()
253if(${STATS_GATHERING} AND NOT (${IA32} OR ${INTEL64}))
254 error_say("Stats-gathering functionality is only supported on x86-Linux and Intel(R) MIC Architecture")
255endif()
256if(${USE_ADAPTIVE_LOCKS} AND NOT(${IA32} OR ${INTEL64}))
257 error_say("Adaptive locks (TSX) functionality is only supported on x86 Architecture")
258endif()
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
266if(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}")
269endif()
270if(NOT "${omp_version}" STREQUAL "40")
271 set(suffix "${suffix}.${omp_version}")
272endif()
273if(${STATS_GATHERING})
274 set(suffix "${suffix}.s1")
275endif()
276if(${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()
283endif()
284
285####################################
286# Setting file extensions / suffixes
287set(obj ${CMAKE_C_OUTPUT_EXTENSION} )
288set(lib ${CMAKE_STATIC_LIBRARY_SUFFIX})
289set(dll ${CMAKE_SHARED_LIBRARY_SUFFIX})
290set(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)
295if(NOT "${PERL_FOUND}") # variable is defined in FindPerl Standard CMake Module
296 error_say("Error: Could not find valid perl")
297endif()
298
299#########################
300# Setting directory names
301set(platform "${real_os}_${arch}" ) # i.e., lin_32e, mac_32
302set(build_dir "${CMAKE_CURRENT_BINARY_DIR}" ) # build directory (Where CMakeCache.txt is created, build files generated)
303set(src_dir "${LIBOMP_WORK}/src" )
304set(tools_dir "${LIBOMP_WORK}/tools" )
305set(export_dir "${LIBOMP_WORK}/exports" )
306set(export_cmn_dir "${export_dir}/common${suffix}" )
307set(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
310if(${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)
314endif()
315set(inc_dir "${LIBOMP_WORK}/src/include/${omp_version}")
316
317############################
318# Setting final library name
319set(lib_item "libiomp")
320if(${PROFILE_LIBRARY})
321 set(lib_item "${lib_item}prof")
322endif()
323if(${STUBS_LIBRARY})
324 set(lib_item "${lib_item}stubs")
325endif()
326set(lib_item "${lib_item}${version}")
327if(${WINDOWS})
328 set(lib_item "${lib_item}md")
329endif()
330set(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
335set(lib_file "${lib_item}${lib_ext}")
336
337########################################
338# Setting export file names (full paths)
339if(${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()
346endif()
347set(export_lib_files "${lib_file}" "${imp_file}" "${pdb_file}")
348set(export_inc_files "iomp_lib.h")
349set(export_mod_files "omp_lib.mod" "omp_lib_kinds.mod")
350set(export_cmn_files1 "omp.h" "omp_lib.h" "omp_lib.f" "omp_lib.f90")
351set(export_cmn_files2 "iomp.h")
352add_prefix("${export_lib_dir}/" export_lib_files)
353add_prefix("${export_ptf_dir}/include_compat/" export_inc_files)
354add_prefix("${export_ptf_dir}/include/" export_mod_files)
355add_prefix("${export_cmn_dir}/include/" export_cmn_files1)
356add_prefix("${export_cmn_dir}/include_compat/" export_cmn_files2)
357set(export_cmn_files "${export_cmn_files1}" "${export_cmn_files2}")
358if("${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)
361endif()
362
363#########################
364# Getting legal type/arch
365set_legal_type(legal_type)
366set_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
382set(include_dirs ${CMAKE_CURRENT_BINARY_DIR} ${src_dir} ${src_dir}/i18n ${inc_dir} ${src_dir}/thirdparty/ittnotify)
383include_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.
387if(${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()
399else()
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()
411endif()
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.
414set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_C_COMPILER_ID} ${CMAKE_MODULE_PATH})
415find_file(compiler_specific_include_file_found CFlags.cmake ${CMAKE_MODULE_PATH})
416if(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)
420else()
421 warning_say("Could not find cmake/${CMAKE_C_COMPILER_ID}/CFlags.cmake: will only use default flags")
422endif()
423
424# Grab all the compiler-independent flags
425append_c_and_cxx_flags_common(C_FLAGS CXX_FLAGS)
426append_asm_flags_common(ASM_FLAGS)
427append_fort_flags_common(F_FLAGS)
428append_linker_flags_common(LD_FLAGS LD_LIB_FLAGS)
429append_archiver_flags_common(AR_FLAGS)
430append_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)
434list_to_string("${DEFINITIONS_FLAGS}" DEFINITIONS_FLAGS)
435list_to_string("${C_FLAGS}" C_FLAGS )
436list_to_string("${CXX_FLAGS}" CXX_FLAGS )
437list_to_string("${ASM_FLAGS}" ASM_FLAGS )
438list_to_string("${LD_FLAGS}" LD_FLAGS )
439list_to_string("${LD_LIB_FLAGS}" LD_LIB_FLAGS )
440list_to_string("${AR_FLAGS}" AR_FLAGS ) # Windows specific for creating import library
441string(STRIP "${DEFINITIONS_FLAGS}" DEFINITIONS_FLAGS)
442string(STRIP "${C_FLAGS}" C_FLAGS )
443string(STRIP "${CXX_FLAGS}" CXX_FLAGS )
444string(STRIP "${ASM_FLAGS}" ASM_FLAGS )
445string(STRIP "${LD_FLAGS}" LD_FLAGS )
446string(STRIP "${LD_LIB_FLAGS}" LD_LIB_FLAGS )
447string(STRIP "${AR_FLAGS}" AR_FLAGS ) # Windows specific for creating import library
448
449# Grab the Perl flags
450set_ev_flags(ev_flags) # expand-vars.pl flags
451set_gd_flags(gd_flags) # generate-def.pl flags (Windows only)
452set(oa_opts "--os=${real_os}" "--arch=${arch}") # sent to the perl scripts
453
454#########################################################
455# Getting correct source files (cmake/SourceFiles.cmake)
456set_c_files(lib_c_items)
457set_cpp_files(lib_cxx_items)
458set_asm_files(lib_asm_items)
459set_imp_c_files(imp_c_items) # Windows-specific
460
461###################################
462# Setting all source file variables
463set(lib_src_files "${lib_c_items}" "${lib_cxx_items}" "${lib_asm_items}")
464set(imp_src_files "${imp_c_items}")
465add_prefix("${src_dir}/" lib_src_files)
466add_prefix("${src_dir}/" imp_src_files) # Windows-specific
467add_prefix("${src_dir}/" lib_c_items )
468add_prefix("${src_dir}/" lib_cxx_items)
469add_prefix("${src_dir}/" lib_asm_items)
470add_prefix("${src_dir}/" imp_c_items ) # Windows-specific
471
472#####################################################################
473# Debug print outs. Will print "variable = ${variable}" if GLOBAL_DEBUG == 1
474if(GLOBAL_DEBUG)
475 include(CMakePrintSystemInformation)
476endif()
477debug_say_var(CMAKE_ASM_COMPILE_OBJECT)
478debug_say_var(CMAKE_RC_COMPILER)
479debug_say_var(CMAKE_C_COMPILER_ID)
480debug_say_var(LIBOMP_WORK)
481debug_say_var(date)
482debug_say_var(stats)
483debug_say_var(lib_file)
484debug_say_var(export_lib_files)
485debug_say_var(DEFINITIONS_FLAGS)
486debug_say_var(C_FLAGS)
487debug_say_var(CXX_FLAGS)
488debug_say_var(ASM_FLAGS)
489debug_say_var(F_FLAGS)
490debug_say_var(LD_FLAGS)
491debug_say_var(LD_LIB_FLAGS)
492debug_say_var(AR_FLAGS)
493debug_say_var(ev_flags)
494debug_say_var(gd_flags)
495debug_say_var(oa_opts)
496debug_say_var(lib_c_items)
497debug_say_var(lib_cxx_items)
498debug_say_var(lib_asm_items)
499debug_say_var(imp_c_items)
500debug_say_var(lib_src_files)
501debug_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 ---
514add_custom_target(lib ALL DEPENDS ${export_lib_files})
515add_custom_target(inc ALL DEPENDS ${export_inc_files})
516if(${create_fortran_modules})
517add_custom_target(mod ALL DEPENDS ${export_mod_files})
518endif()
519# --- Enforce the tests to be completed/skipped before copying to exports directory ---
520if(${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}")
527endif()
528
529#############################
530# --- Create Common Files ---
531add_custom_target(common DEPENDS ${export_cmn_files})
532add_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
541macro (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()
555endmacro()
556# copy from build directory to final resting places in exports directory
557simple_copy_recipe("omp.h" "${build_dir}" "${export_cmn_dir}/include")
558simple_copy_recipe("omp_lib.h" "${build_dir}" "${export_cmn_dir}/include")
559simple_copy_recipe("omp_lib.f" "${build_dir}" "${export_cmn_dir}/include")
560simple_copy_recipe("omp_lib.f90" "${build_dir}" "${export_cmn_dir}/include")
561simple_copy_recipe("iomp.h" "${build_dir}" "${export_cmn_dir}/include_compat")
562simple_copy_recipe("${lib_file}" "${build_dir}" "${export_lib_dir}")
563simple_copy_recipe("${imp_file}" "${build_dir}" "${export_lib_dir}")
564simple_copy_recipe("${pdb_file}" "${build_dir}" "${export_lib_dir}")
565simple_copy_recipe("${dbg_file}" "${build_dir}" "${export_lib_dir}")
566simple_copy_recipe("omp_lib.mod" "${build_dir}" "${export_ptf_dir}/include")
567simple_copy_recipe("omp_lib_kinds.mod" "${build_dir}" "${export_ptf_dir}/include")
568simple_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
576add_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.
579if(${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)
584else()
585 # Unix assembly files can be handled by compiler.
586 enable_language(ASM)
587endif()
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.
591if(${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 "")
595endif()
596
597# --- ${lib_file} rule ---
598add_library(iomp5 SHARED ${lib_src_files})
599set_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
607add_dependencies(lib iomp5)
608
609# Linking command will include libraries in LD_LIB_FLAGS
610target_link_libraries(iomp5 ${LD_LIB_FLAGS})
611
612# Create *.inc and omp.h before compiling any sources
613add_dependencies(iomp5 needed-headers)
614if(${WINDOWS})
615# Create .def and .rc file before compiling any sources
616 add_dependencies(iomp5 needed-windows-files)
617endif()
618
619# Set the compiler flags for each type of source
620set_source_files_properties(${lib_c_items}
621 ${imp_c_items} PROPERTIES COMPILE_FLAGS "${C_FLAGS}" )
622set_source_files_properties(${lib_cxx_items} PROPERTIES COMPILE_FLAGS "${CXX_FLAGS}")
623set_source_files_properties(${lib_asm_items} PROPERTIES COMPILE_FLAGS "${ASM_FLAGS}")
624# Set the -D definitions for all sources
625add_definitions(${DEFINITIONS_FLAGS})
626
627# If creating a build that imitates build.pl's rules then set USE_BUILDPL_RULES to true
628if(${USE_BUILDPL_RULES})
629 include(BuildPLRules)
630endif()
631
632######################################################
633# --- Source file specific flags ---
634# kmp_version.o : -D _KMP_BUILD_TIME="\"$(date)}\""
635set_source_files_properties(${src_dir}/kmp_version.c PROPERTIES COMPILE_DEFINITIONS "_KMP_BUILD_TIME=\"\\\"${date}\\\"\"")
636
637# z_Linux_asm.o : -D KMP_ARCH_*
638if(${ARM})
639 set_source_files_properties(${src_dir}/z_Linux_asm.s PROPERTIES COMPILE_DEFINITIONS "KMP_ARCH_ARM")
640elseif(${INTEL64})
641 set_source_files_properties(${src_dir}/z_Linux_asm.s PROPERTIES COMPILE_DEFINITIONS "KMP_ARCH_X86_64")
642elseif(${IA32})
643 set_source_files_properties(${src_dir}/z_Linux_asm.s PROPERTIES COMPILE_DEFINITIONS "KMP_ARCH_X86")
Jim Cownie3051f972014-08-07 10:12:54644elseif(${PPC64})
645 set_source_files_properties(${src_dir}/z_Linux_asm.s PROPERTIES COMPILE_DEFINITIONS "KMP_ARCH_PPC64")
Jim Cownie3b81ce62014-08-05 09:32:28646endif()
647
648if(${WINDOWS})
649 set_source_files_properties(${src_dir}/thirdparty/ittnotify/ittnotify_static.c PROPERTIES COMPILE_DEFINITIONS "UNICODE")
650endif()
651
652######################################################
653# MAC specific build rules
654if(${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()
667endif()
668
669######################################################
670# Windows specific build rules
671if(${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()
709endif()
710
711######################################################
712# kmp_i18n_id.inc and kmp_i18n_default.inc
713set(perlcmd "${PERL_EXECUTABLE}" "${tools_dir}/message-converter.pl" "${oa_opts}" "--prefix=kmp_i18n" "--enum=kmp_i18n_id.inc" "${src_dir}/i18n/en_US.txt")
714add_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)
719set(perlcmd "${PERL_EXECUTABLE}" "${tools_dir}/message-converter.pl" "${oa_opts}" "--prefix=kmp_i18n" "--default=kmp_i18n_default.inc" "${src_dir}/i18n/en_US.txt")
720add_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 ...)
729if(${tests})
730 include(MicroTests)
731endif()
732
733######################################################
734# --- Create Fortran Files ---
735# omp_lib.mod
736if(${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})
761endif()
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
767macro(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()
784endmacro()
785string_to_list("${ev_flags}" ev_flags)
786# omp_lib.h : ev-flags += -D KMP_INT_PTR_KIND="int_ptr_kind()"
787set_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)
789if(${IA32}) # 32 bit archs
790 set_source_files_properties(iomp_lib.h PROPERTIES COMPILE_DEFINITIONS "-D KMP_INT_PTR_KIND=4")
791else()
792 set_source_files_properties(iomp_lib.h PROPERTIES COMPILE_DEFINITIONS "-D KMP_INT_PTR_KIND=8")
793endif()
794# libiomp.rc : ev-flags += -D KMP_FILE=$(lib_file)
795set_source_files_properties(libiomp.rc PROPERTIES COMPILE_DEFINITIONS "-D KMP_FILE=${lib_file}")
796expand_vars_recipe(omp.h)
797expand_vars_recipe(omp_lib.h)
798expand_vars_recipe(omp_lib.f)
799expand_vars_recipe(omp_lib.f90)
800expand_vars_recipe(iomp.h)
801expand_vars_recipe(iomp_lib.h)
802expand_vars_recipe(libiomp.rc)
803
804
805####################################################################
806# Print configuration after all variables are set.
807say("")
808say("----------------------- CONFIGURATION -----------------------")
809say("Operating System : ${os}")
810say("Architecture : ${arch}")
811say("Build Type : ${CMAKE_BUILD_TYPE}")
812say("OpenMP Version : ${omp_version}")
813say("Lib Type : ${lib_type}")
814if(${MIC})
815 say("Intel(R) MIC Architecture : ${mic_arch}")
816 say("Intel(R) MIC Architecture OS : ${mic_os}")
817endif()
818say("Fortran Modules : ${create_fortran_modules}")
819# will say development if all zeros
820if("${build_number}" STREQUAL "00000000")
821 set(build "development")
822else()
823 set(build "${build_number}")
824endif()
825say("Build : ${build}")
826say("Stats-Gathering : ${stats}")
827say("Use build.pl rules : ${USE_BUILDPL_RULES}")
828say("Adaptive locks : ${USE_ADAPTIVE_LOCKS}")
829say("Use predefined linker flags : ${USE_PREDEFINED_LINKER_FLAGS}")
830say("Compiler supports quad precision : ${COMPILER_SUPPORTS_QUAD_PRECISION}")
831say("-------------------------------------------------------------")
832say("")
833