blob: 2b06900b724f38630ea4fb595bb9dbf3b8080c3a [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################
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000013# CMAKE libomp
Jim Cownie3b81ce62014-08-05 09:32:28 +000014cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
Alp Toker7198f522014-06-01 18:01:33 +000015
Jim Cownie3b81ce62014-08-05 09:32:28 +000016#########
17# GLOBALS
18set(GLOBAL_DEBUG 0)
19
20# Add cmake directory to search for custom cmake functions
21set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
22
Andrey Churbanov648467e2015-05-05 20:02:52 +000023#######################################################################
24# Standalone build or part of LLVM?
Jonathan Peyton7979a072015-05-20 22:33:24 +000025set(LIBOMP_STANDALONE_BUILD FALSE)
Andrey Churbanov648467e2015-05-05 20:02:52 +000026if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}" OR
27 "${CMAKE_SOURCE_DIR}/runtime" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000028 project(libomp C CXX)
Jonathan Peyton7979a072015-05-20 22:33:24 +000029 set(LIBOMP_STANDALONE_BUILD TRUE)
Andrey Churbanov648467e2015-05-05 20:02:52 +000030endif()
31
Jim Cownie3b81ce62014-08-05 09:32:28 +000032# These include files are in cmake/ subdirectory except for FindPerl which is a cmake standard module
33include(HelperFunctions)
34include(Definitions) # -D definitions when compiling
35include(CommonFlags) # compiler, assembler, fortran, linker flags common for all compilers
36include(SourceFiles) # source files to compile
37include(PerlFlags) # Perl flags for generate-def.pl and expand-vars.pl
38include(FindPerl) # Standard cmake module to check for Perl
Andrey Churbanov17cce422015-01-13 14:35:23 +000039include(GetArchitecture) # get_architecture()
Jim Cownie3b81ce62014-08-05 09:32:28 +000040
41####################################################################
42# CONFIGURATION
43#
44# * Any variable/value that is CACHE-ed can be changed after the initial run of cmake
45# through the file, CMakeCache.txt which is in the build directory.
46# * If you change any value in CMakeCache.txt, then just run cmake ..
47# and the changed will be picked up. One can also use -DVARIABLE=VALUE
48# when calling cmake to changed configuration values.
49# * CMAKE_C_COMPILER, CMAKE_CXX_COMPILER, CMAKE_ASM_MASM_COMPILER, CMAKE_ASM_COMPILER,
50# CMAKE_Fortran_COMPILER can only by specified on the initial run of cmake.
51# This means you cannot specify -DCMAKE_C_COMPILER= on a subsequent run of cmake
52# in the same build directory until that build directory is emptied.
53# If you want to change the compiler, then empty the build directory and rerun cmake.
54
55# Build Configuration
Jonathan Peytonfbb15142015-05-26 17:27:01 +000056set(os_possible_values lin mac win)
57set(arch_possible_values 32e 32 arm ppc64 ppc64le aarch64 mic)
58set(build_type_possible_values release debug relwithdebinfo)
Andrey Churbanov062e1982015-05-07 17:07:06 +000059set(omp_version_possible_values 41 40 30)
Jonathan Peytonfbb15142015-05-26 17:27:01 +000060set(lib_type_possible_values normal profile stubs)
61set(mic_arch_possible_values knf knc)
Jim Cownie3b81ce62014-08-05 09:32:28 +000062
Andrey Churbanov17cce422015-01-13 14:35:23 +000063# Below, cmake will try and determine the operating system and architecture for you.
Jim Cownie3b81ce62014-08-05 09:32:28 +000064# These values are set in CMakeCache.txt when cmake is first run (-Dvar_name=... will take precedence)
65# parameter | default value
66# ----------------------------
67# Right now, this build system considers os=lin to mean "Unix-like that is not MAC"
Jonathan Peytonfbb15142015-05-26 17:27:01 +000068# Apple goes first because CMake considers Mac to be a Unix based
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000069# operating system, while libomp considers it a special case
Jonathan Peytonfbb15142015-05-26 17:27:01 +000070if(${APPLE})
Andrey Churbanov17cce422015-01-13 14:35:23 +000071 set(temp_os mac)
Jim Cownie3b81ce62014-08-05 09:32:28 +000072elseif(${UNIX})
Andrey Churbanov17cce422015-01-13 14:35:23 +000073 set(temp_os lin)
Jim Cownie3b81ce62014-08-05 09:32:28 +000074elseif(${WIN32})
Andrey Churbanov17cce422015-01-13 14:35:23 +000075 set(temp_os win)
Jim Cownie3b81ce62014-08-05 09:32:28 +000076else()
Andrey Churbanov17cce422015-01-13 14:35:23 +000077 set(temp_os lin)
Jim Cownie3b81ce62014-08-05 09:32:28 +000078endif()
79
Andrey Churbanov17cce422015-01-13 14:35:23 +000080# If adding a new architecture, take a look at cmake/GetArchitecture.cmake
81get_architecture(detected_arch)
Jim Cownie3b81ce62014-08-05 09:32:28 +000082
Jonathan Peytonfbb15142015-05-26 17:27:01 +000083set(LIBOMP_OS ${temp_os} CACHE STRING
84 "The operating system to build for (lin/mac/win)")
85set(LIBOMP_ARCH ${detected_arch} CACHE STRING
86 "The architecture to build for (32e/32/arm/ppc64/ppc64le/aarch64/mic). 32e is Intel(R) 64 architecture, 32 is IA-32 architecture")
87set(LIBOMP_LIB_TYPE normal CACHE STRING
88 "Performance,Profiling,Stubs library (normal/profile/stubs)")
89set(LIBOMP_VERSION 5 CACHE STRING
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000090 "Produce libguide (version 4) or libomp (version 5)")
Jonathan Peytonfbb15142015-05-26 17:27:01 +000091set(LIBOMP_OMP_VERSION 41 CACHE STRING
92 "The OpenMP version (41/40/30)")
93set(LIBOMP_MIC_ARCH knc CACHE STRING
94 "Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) (knf/knc). Ignored if not Intel(R) MIC Architecture build.")
95set(LIBOMP_FORTRAN_MODULES false CACHE BOOL
96 "Create Fortran module files? (requires fortran compiler)")
Jim Cownie3b81ce62014-08-05 09:32:28 +000097
98# - These tests are little tests performed after the library is formed.
Jonathan Peytonfbb15142015-05-26 17:27:01 +000099# - The library won't be copied to the exports directory
100# until it has passed/skipped all below tests
101# - To skip these tests, just pass -DLIBOMP_MICRO_TESTS=OFF to cmake
102set(LIBOMP_TEST_TOUCH true CACHE BOOL
103 "Perform a small touch test?")
104set(LIBOMP_TEST_RELO true CACHE BOOL
105 "Perform a relocation test for dynamic libraries?")
106set(LIBOMP_TEST_EXECSTACK true CACHE BOOL
107 "Perform a execstack test for linux dynamic libraries?")
108set(LIBOMP_TEST_INSTR true CACHE BOOL
109 "Perform an instruction test for Intel(R) MIC Architecture libraries?")
110set(LIBOMP_TEST_DEPS true CACHE BOOL
111 "Perform a library dependency test?")
112set(LIBOMP_MICRO_TESTS false CACHE BOOL
113 "Perform touch, relo, execstack, instr, and deps tests?")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000114
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000115# - stats-gathering enables OpenMP stats where things like the number of
116# parallel regions, clock ticks spent in particular openmp regions are recorded.
117set(LIBOMP_STATS false CACHE BOOL
118 "Stats-Gathering functionality?")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000119
Jonathan Peyton92907c22015-05-29 16:13:56 +0000120# - Support for universal fat binary builds on Mac
121# - Having this extra variable allows people to build this library as a universal library
122# without forcing a universal build of the llvm/clang compiler.
123set(LIBOMP_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING
124 "For Mac builds, semicolon separated list of architectures to build for universal fat binary.")
125set(CMAKE_OSX_ARCHITECTURES ${LIBOMP_OSX_ARCHITECTURES})
126
Andrey Churbanove5f44922015-04-29 16:22:07 +0000127# OMPT-support
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000128set(LIBOMP_OMPT_SUPPORT false CACHE BOOL
129 "OMPT-support?")
130set(LIBOMP_OMPT_BLAME true CACHE BOOL
131 "OMPT-blame?")
132set(LIBOMP_OMPT_TRACE true CACHE BOOL
133 "OMPT-trace?")
Andrey Churbanove5f44922015-04-29 16:22:07 +0000134
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000135# User specified flags. These are appended to the predetermined flags found
136# in CommonFlags.cmake and ${CMAKE_C_COMPILER_ID}/*Flags.cmake (e.g., GNU/CFlags.cmake)
137set(LIBOMP_CFLAGS "" CACHE STRING
138 "Appended user specified C compiler flags.")
139set(LIBOMP_CXXFLAGS "" CACHE STRING
140 "Appended user specified C++ compiler flags.")
141set(LIBOMP_CPPFLAGS "" CACHE STRING
142 "Appended user specified C preprocessor flags.")
143set(LIBOMP_ASMFLAGS "" CACHE STRING
144 "Appended user specified assembler flags.")
145set(LIBOMP_LDFLAGS "" CACHE STRING
146 "Appended user specified linker flags.")
147set(LIBOMP_LIBFLAGS "" CACHE STRING
148 "Appended user specified linked libs flags. (e.g., -lm)")
149set(LIBOMP_FFLAGS "" CACHE STRING
150 "Appended user specified Fortran compiler flags. These are only used if LIBOMP_FORTRAN_MODULES==true.")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000151
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000152# Should the libomp library and generated headers be copied into the original source exports/ directory
Andrey Churbanov708fa8e2015-05-14 12:54:08 +0000153# Turning this to false aids parallel builds to not interfere with each other.
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000154set(LIBOMP_COPY_EXPORTS true CACHE STRING
155 "Should exports be copied into source exports/ directory?")
Andrey Churbanov708fa8e2015-05-14 12:54:08 +0000156
Jim Cownie3b81ce62014-08-05 09:32:28 +0000157# - Allow three build types: Release, Debug, RelWithDebInfo (these relate to build.pl's release, debug, and diag settings respectively)
158# - default is Release (when CMAKE_BUILD_TYPE is not defined)
159# - CMAKE_BUILD_TYPE affects the -O and -g flags (CMake magically includes correct version of them on per compiler basis)
160# - typical: Release = -O3 -DNDEBUG
161# RelWithDebInfo = -O2 -g -DNDEBUG
162# Debug = -g
163if(CMAKE_BUILD_TYPE)
164 # CMAKE_BUILD_TYPE was defined, check for validity
165 string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lowercase)
166 check_variable(cmake_build_type_lowercase "${build_type_possible_values}")
167else()
168 # CMAKE_BUILD_TYPE was not defined, set default to Release
169 unset(CMAKE_BUILD_TYPE CACHE)
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000170 set(CMAKE_BUILD_TYPE Release CACHE STRING
171 "Choose the type of build, options are: Release/Debug/RelWithDebInfo")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000172 string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lowercase)
173 check_variable(cmake_build_type_lowercase "${build_type_possible_values}")
174endif()
175
Jonathan Peyton7979a072015-05-20 22:33:24 +0000176if(${LIBOMP_STANDALONE_BUILD})
Jonathan Peyton9919dfc2015-06-11 17:36:16 +0000177 # Allow user to choose a suffix for the installation directory, or if part of
178 # LLVM build then just use LLVM_LIBDIR_SUFFIX
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000179 set(LIBOMP_LIBDIR_SUFFIX "" CACHE STRING
180 "suffix of lib installation directory e.g., 64 => lib64")
Jonathan Peyton9919dfc2015-06-11 17:36:16 +0000181 # Should assertions be enabled? They are on by default, or it part of
182 # LLVM build then just use LLVM_ENABLE_ASSERTIONS
183 set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL
184 "enable assertions?")
Andrey Churbanov648467e2015-05-05 20:02:52 +0000185else()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000186 set(LIBOMP_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX})
Jonathan Peyton9919dfc2015-06-11 17:36:16 +0000187 set(LIBOMP_ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS})
Andrey Churbanov648467e2015-05-05 20:02:52 +0000188endif()
189
Jim Cownie3b81ce62014-08-05 09:32:28 +0000190# Check valid values
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000191check_variable(LIBOMP_OS "${os_possible_values}")
192check_variable(LIBOMP_ARCH "${arch_possible_values}")
Jonathan Peyton7979a072015-05-20 22:33:24 +0000193check_variable(LIBOMP_OMP_VERSION "${omp_version_possible_values}")
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000194check_variable(LIBOMP_LIB_TYPE "${lib_type_possible_values}")
Jonathan Peyton7979a072015-05-20 22:33:24 +0000195if("${LIBOMP_ARCH}" STREQUAL "mic")
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000196 check_variable(LIBOMP_MIC_ARCH "${mic_arch_possible_values}")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000197endif()
198# Get the build number from kmp_version.c
Andrey Churbanov708fa8e2015-05-14 12:54:08 +0000199get_build_number("${CMAKE_CURRENT_SOURCE_DIR}" build_number)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000200
201# Getting time and date
202# As of now, no timestamp will be created.
203set(date "No Timestamp")
204
205#################################################################
206# Set some useful flags variables for other parts of cmake to use
207# Operating System
208set(LINUX FALSE)
209set(MAC FALSE)
210set(WINDOWS FALSE)
211set(MIC FALSE)
212set(FREEBSD FALSE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000213if("${LIBOMP_OS}" STREQUAL "lin")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000214 set(LINUX TRUE)
215 set(real_os lin)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000216elseif("${LIBOMP_OS}" STREQUAL "mac")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000217 set(MAC TRUE)
218 set(real_os mac)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000219elseif("${LIBOMP_OS}" STREQUAL "win")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000220 set(WINDOWS TRUE)
221 set(real_os win)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000222endif()
223if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
224 set(FREEBSD TRUE)
225endif()
226
227# Architecture
228set(IA32 FALSE)
229set(INTEL64 FALSE)
230set(ARM FALSE)
Andrey Churbanovcbda8682015-01-13 14:43:35 +0000231set(AARCH64 FALSE)
Andrey Churbanovd1c55042015-01-19 18:29:35 +0000232set(PPC64BE FALSE)
233set(PPC64LE FALSE)
Jim Cownie3051f972014-08-07 10:12:54 +0000234set(PPC64 FALSE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000235if("${LIBOMP_ARCH}" STREQUAL "32") # IA-32 architecture
Jim Cownie3b81ce62014-08-05 09:32:28 +0000236 set(IA32 TRUE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000237elseif("${LIBOMP_ARCH}" STREQUAL "32e") # Intel(R) 64 architecture
Jim Cownie3b81ce62014-08-05 09:32:28 +0000238 set(INTEL64 TRUE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000239elseif("${LIBOMP_ARCH}" STREQUAL "arm") # ARM architecture
Jim Cownie3b81ce62014-08-05 09:32:28 +0000240 set(ARM TRUE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000241elseif("${LIBOMP_ARCH}" STREQUAL "ppc64") # PPC64BE architecture
Andrey Churbanovd1c55042015-01-19 18:29:35 +0000242 set(PPC64BE TRUE)
243 set(PPC64 TRUE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000244elseif("${LIBOMP_ARCH}" STREQUAL "ppc64le") # PPC64LE architecture
Andrey Churbanovd1c55042015-01-19 18:29:35 +0000245 set(PPC64LE TRUE)
246 set(PPC64 TRUE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000247elseif("${LIBOMP_ARCH}" STREQUAL "aarch64") # AARCH64 architecture
Andrey Churbanovcbda8682015-01-13 14:43:35 +0000248 set(AARCH64 TRUE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000249elseif("${LIBOMP_ARCH}" STREQUAL "mic") # Intel(R) Many Integrated Core Architecture
Andrey Churbanov19be9782015-01-16 13:05:23 +0000250 set(MIC TRUE)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000251endif()
252
253# Set some flags based on build_type
254# cmake_build_type_lowercase is based off of CMAKE_BUILD_TYPE, just put in lowercase.
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000255set(RELEASE_BUILD FALSE)
256set(DEBUG_BUILD FALSE)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000257set(RELWITHDEBINFO_BUILD FALSE)
258if("${cmake_build_type_lowercase}" STREQUAL "release")
259 set(RELEASE_BUILD TRUE)
260elseif("${cmake_build_type_lowercase}" STREQUAL "debug")
261 set(DEBUG_BUILD TRUE)
262elseif("${cmake_build_type_lowercase}" STREQUAL "relwithdebinfo")
263 set(RELWITHDEBINFO_BUILD TRUE)
264endif()
265
Jim Cownie3b81ce62014-08-05 09:32:28 +0000266# Include itt notify interface? Right now, always.
Jonathan Peyton7979a072015-05-20 22:33:24 +0000267set(LIBOMP_USE_ITT_NOTIFY TRUE)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000268
269# normal, profile, stubs library.
270set(NORMAL_LIBRARY FALSE)
271set(STUBS_LIBRARY FALSE)
272set(PROFILE_LIBRARY FALSE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000273if("${LIBOMP_LIB_TYPE}" STREQUAL "normal")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000274 set(NORMAL_LIBRARY TRUE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000275elseif("${LIBOMP_LIB_TYPE}" STREQUAL "profile")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000276 set(PROFILE_LIBRARY TRUE)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000277elseif("${LIBOMP_LIB_TYPE}" STREQUAL "stubs")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000278 set(STUBS_LIBRARY TRUE)
279endif()
280
281###############################################
282# Features for compilation and build in general
283
284# - Does the compiler support a 128-bit floating point data type? Default is false
285# - If a compiler does, then change it in the CMakeCache.txt file (or using the cmake GUI)
286# or send to cmake -DCOMPILER_SUPPORTS_QUAD_PRECISION=true
287# - If COMPILER_SUPPORTS_QUAD_PRECISION is true, then a corresponding COMPILER_QUAD_TYPE must be given
288# This is the compiler's quad-precision data type.
289# ** TODO: This isn't complete yet. Finish it. Requires changing macros in kmp_os.h **
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000290set(LIBOMP_COMPILER_SUPPORTS_QUAD_PRECISION false CACHE BOOL
291 "*INCOMPLETE* Does the compiler support a 128-bit floating point type?")
292set(LIBOMP_COMPILER_QUAD_TYPE "" CACHE STRING
293 "*INCOMPLETE* The quad precision data type (e.g., for gcc, __float128)")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000294
295# - Should the orignal build rules for builds be used? (cmake/OriginalBuildRules.cmake). This setting is off by default.
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000296# - This always compiles with -g. And if it is a release build, the debug info is stripped out via objcopy and put into libomp.dbg.
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000297set(LIBOMP_USE_BUILDPL_RULES false CACHE BOOL
298 "Should the build follow build.pl rules/recipes?")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000299
300# - Should the build use the predefined linker flags (OS-dependent) in CommonFlags.cmake?
301# - these predefined linker flags should work for Windows, Mac, and True Linux for the most popular compilers/linkers
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000302set(LIBOMP_USE_PREDEFINED_LINKER_FLAGS true CACHE BOOL
303 "Should the build use the predefined linker flags in CommonFlags.cmake?")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000304
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000305# - On multinode systems, larger alignment is desired to avoid false sharing
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000306set(LIBOMP_USE_INTERNODE_ALIGNMENT false CACHE BOOL
307 "Should larger alignment (4096 bytes) be used for some locks and data structures?")
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000308
309# - libgomp drop-in compatibility
310if(${LINUX} AND NOT ${PPC64})
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000311 set(LIBOMP_USE_VERSION_SYMBOLS true CACHE BOOL
312 "Should version symbols be used? These provide binary compatibility with libgomp.")
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000313else()
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000314 set(LIBOMP_USE_VERSION_SYMBOLS false)
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000315endif()
316
Jim Cownie3b81ce62014-08-05 09:32:28 +0000317# - TSX based locks have __asm code which can be troublesome for some compilers. This feature is also x86 specific.
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000318if(${IA32} OR ${INTEL64})
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000319 set(LIBOMP_USE_ADAPTIVE_LOCKS true CACHE BOOL
320 "Should TSX-based lock be compiled (adaptive lock in kmp_lock.cpp). These are x86 specific.")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000321else()
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000322 set(LIBOMP_USE_ADAPTIVE_LOCKS false)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000323endif()
324
325##################################
326# Error checking the configuration
Jonathan Peyton7979a072015-05-20 22:33:24 +0000327if(${LIBOMP_STATS} AND (${WINDOWS} OR ${MAC}))
Jim Cownie3b81ce62014-08-05 09:32:28 +0000328 error_say("Stats-gathering functionality is only supported on x86-Linux and Intel(R) MIC Architecture")
329endif()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000330if(${LIBOMP_STATS} AND NOT (${IA32} OR ${INTEL64} OR ${MIC}))
Jim Cownie3b81ce62014-08-05 09:32:28 +0000331 error_say("Stats-gathering functionality is only supported on x86-Linux and Intel(R) MIC Architecture")
332endif()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000333if(${LIBOMP_USE_ADAPTIVE_LOCKS} AND NOT(${IA32} OR ${INTEL64}))
Jim Cownie3b81ce62014-08-05 09:32:28 +0000334 error_say("Adaptive locks (TSX) functionality is only supported on x86 Architecture")
335endif()
Jonathan Peytonb689ded2015-06-17 15:43:34 +0000336if(${LIBOMP_OMPT_SUPPORT} AND ${WINDOWS})
337 error_say("OpenMP Tools Interface is not supported on Windows")
338endif()
Jim Cownie3b81ce62014-08-05 09:32:28 +0000339
340###############################################
341# - Create the suffix for the export directory
342# - Only add to suffix when not a default value
343# - Example suffix: .deb.30.s1
344# final export directory: exports/lin_32e.deb.30.s1/lib
345# - These suffixes imply the build is a Debug, OpenMP 3.0, Stats-Gathering version of the library
346if(NOT "${cmake_build_type_lowercase}" STREQUAL "release")
347 string(SUBSTRING "${cmake_build_type_lowercase}" 0 3 build_type_suffix)
348 set(suffix "${suffix}.${build_type_suffix}")
349endif()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000350if(NOT "${LIBOMP_OMP_VERSION}" STREQUAL "41")
351 set(suffix "${suffix}.${LIBOMP_OMP_VERSION}")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000352endif()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000353if(${LIBOMP_STATS})
Jim Cownie3b81ce62014-08-05 09:32:28 +0000354 set(suffix "${suffix}.s1")
355endif()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000356if(${LIBOMP_OMPT_SUPPORT})
Andrey Churbanove5f44922015-04-29 16:22:07 +0000357 set(suffix "${suffix}.ompt")
Jonathan Peyton7979a072015-05-20 22:33:24 +0000358 if(NOT ${LIBOMP_OMPT_BLAME})
Andrey Churbanove5f44922015-04-29 16:22:07 +0000359 set(suffix "${suffix}.no-ompt-blame")
360 endif()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000361 if(NOT ${LIBOMP_OMPT_TRACE})
Andrey Churbanove5f44922015-04-29 16:22:07 +0000362 set(suffix "${suffix}.no-ompt-trace")
363 endif()
364endif()
Jim Cownie3b81ce62014-08-05 09:32:28 +0000365
366####################################
367# Setting file extensions / suffixes
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000368set(obj ${CMAKE_C_OUTPUT_EXTENSION})
Jim Cownie3b81ce62014-08-05 09:32:28 +0000369set(lib ${CMAKE_STATIC_LIBRARY_SUFFIX})
370set(dll ${CMAKE_SHARED_LIBRARY_SUFFIX})
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000371set(exe ${CMAKE_EXECUTABLE_SUFFIX})
Jim Cownie3b81ce62014-08-05 09:32:28 +0000372
373######################
374# Find perl executable
375# 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)
376if(NOT "${PERL_FOUND}") # variable is defined in FindPerl Standard CMake Module
377 error_say("Error: Could not find valid perl")
378endif()
379
380#########################
381# Setting directory names
Andrey Churbanov19be9782015-01-16 13:05:23 +0000382if(${MIC})
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000383 set(platform "${real_os}_${LIBOMP_MIC_ARCH}") # e.g., lin_knf, lin_knc
Andrey Churbanov19be9782015-01-16 13:05:23 +0000384else()
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000385 set(platform "${real_os}_${LIBOMP_ARCH}") # e.g., lin_32e, mac_32
Andrey Churbanov19be9782015-01-16 13:05:23 +0000386endif()
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000387# build directory (Where CMakeCache.txt is created, build files generated)
388set(build_dir "${CMAKE_CURRENT_BINARY_DIR}")
389set(src_dir "${CMAKE_CURRENT_SOURCE_DIR}/src")
390set(tools_dir "${CMAKE_CURRENT_SOURCE_DIR}/tools")
391set(export_dir "${CMAKE_CURRENT_SOURCE_DIR}/exports")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000392set(export_ptf_dir "${export_dir}/${platform}${suffix}")
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000393set(export_cmn_dir "${export_dir}/common${suffix}/include")
Andrey Churbanov648467e2015-05-05 20:02:52 +0000394set(export_inc_dir "${export_ptf_dir}/include")
395set(export_mod_dir "${export_ptf_dir}/include_compat")
Andrey Churbanov19be9782015-01-16 13:05:23 +0000396_export_lib_dir(${platform} export_lib_dir) # set exports directory (relative to build_dir) e.g., ../exports/lin_32e/lib/
397 # or ../exports/mac_32e/lib.thin/ for mac
Jim Cownie3b81ce62014-08-05 09:32:28 +0000398if(${MAC})
399 # macs use lib.thin/ subdirectory for non-fat libraries that only contain one architecture
400 # macs use lib/ subdirectory for fat libraries that contain both IA-32 architecture and Intel(R) 64 architecture code.
401 _export_lib_fat_dir(${platform} export_lib_fat_dir)
402endif()
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000403set(inc_dir "${src_dir}/include/${LIBOMP_OMP_VERSION}")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000404
405############################
406# Setting final library name
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000407set(lib_item "libomp")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000408if(${PROFILE_LIBRARY})
409 set(lib_item "${lib_item}prof")
410endif()
411if(${STUBS_LIBRARY})
412 set(lib_item "${lib_item}stubs")
413endif()
Jim Cownie3b81ce62014-08-05 09:32:28 +0000414if(${WINDOWS})
415 set(lib_item "${lib_item}md")
416endif()
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000417set(LIBOMP_LIB_NAME "${lib_item}" CACHE STRING "OMP library name")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000418set(lib_ext "${dll}")
419# ${lib_file} is real library name:
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000420# libomp.so for Linux
421# libomp.dylib for Mac
422# libompmd.dll for Windows
Jonathan Peyton7979a072015-05-20 22:33:24 +0000423set(lib_file "${LIBOMP_LIB_NAME}${lib_ext}")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000424
425########################################
Andrey Churbanov648467e2015-05-05 20:02:52 +0000426# Setting export file names
Jim Cownie3b81ce62014-08-05 09:32:28 +0000427if(${WINDOWS})
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000428 set(imp_file "${lib_item}${lib}") # this is exported (libomp.lib)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000429 set(def_file "${lib_item}.def") # this is not exported
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000430 if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR
431 "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo" OR
432 ${LIBOMP_USE_BUILDPL_RULES})
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000433 set(pdb_file "${lib_file}.pdb") # this is exported if it exists (libompmd.dll.pdb)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000434 endif()
435endif()
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000436set(export_lib_files "${lib_file}" "${imp_file}" "${pdb_file}")
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000437set(export_mod_files "omp_lib.mod" "omp_lib_kinds.mod")
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000438set(export_cmn_files "omp.h" "omp_lib.h" "omp_lib.f" "omp_lib.f90")
Andrey Churbanove5f44922015-04-29 16:22:07 +0000439
Jonathan Peyton7979a072015-05-20 22:33:24 +0000440if(${LIBOMP_OMPT_SUPPORT})
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000441 set(export_cmn_files ${export_cmn_files} "ompt.h")
Andrey Churbanove5f44922015-04-29 16:22:07 +0000442endif()
443
Jim Cownie3b81ce62014-08-05 09:32:28 +0000444if("${export_lib_fat_dir}")
445 set(export_lib_fat_files "${lib_file}" "${imp_file}")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000446endif()
447
448#########################
449# Getting legal type/arch
450set_legal_type(legal_type)
451set_legal_arch(legal_arch)
452
453#################################################
454# Preprocessor Definitions (cmake/Definitions.cmake)
455# Preprocessor Includes
456# Compiler (C/C++) Flags (cmake/CommonFlags.cmake)
457# Assembler Flags (cmake/CommonFlags.cmake)
458# Fortran Flags (cmake/CommonFlags.cmake)
459# Linker Flags (cmake/CommonFlags.cmake)
460# Archiver Flags (cmake/CommonFlags.cmake)
461# Helper Perl Script Flags (cmake/PerlFlags.cmake)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000462# * Inside the cmake/CommonFlags.cmake file, the LIBOMP_*FLAGS are added.
Jim Cownie3b81ce62014-08-05 09:32:28 +0000463# * Cannot use CMAKE_*_FLAGS directly because -x c++ is put in the linker command and mangles the linking phase.
464
Andrey Churbanov648467e2015-05-05 20:02:52 +0000465# Grab compiler-dependent flags
466# Cmake will look for cmake/${CMAKE_C_COMPILER_ID}/CFlags.cmake to append additional c, cxx, and linker flags.
467set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_C_COMPILER_ID} ${CMAKE_MODULE_PATH})
468find_file(compiler_specific_include_file_found CFlags.cmake ${CMAKE_MODULE_PATH})
469if(compiler_specific_include_file_found)
470 include(CFlags) # COMPILER_SUPPORTS_QUAD_PRECISION changed in here
471 append_compiler_specific_c_and_cxx_flags(C_FLAGS CXX_FLAGS)
472 append_compiler_specific_linker_flags(LD_FLAGS LD_LIB_FLAGS)
473else()
474 warning_say("Could not find cmake/${CMAKE_C_COMPILER_ID}/CFlags.cmake: will only use default flags")
475endif()
Jim Cownie3b81ce62014-08-05 09:32:28 +0000476# Grab assembler-dependent flags
477# CMake will look for cmake/${CMAKE_ASM_COMPILER_ID}/AsmFlags.cmake to append additional assembler flags.
478if(${WINDOWS})
479 # Windows based systems use CMAKE_ASM_MASM_COMPILER
480 # The windows assembly files are in MASM format, and they require a tool that can handle MASM syntax (ml.exe or ml64.exe typically)
481 enable_language(ASM_MASM)
482 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_ASM_MASM_COMPILER_ID} ${CMAKE_MODULE_PATH})
483 find_file(assembler_specific_include_file_found AsmFlags.cmake ${CMAKE_MODULE_PATH})
484 if(assembler_specific_include_file_found)
485 include(AsmFlags)
486 append_assembler_specific_asm_flags(ASM_FLAGS)
487 else()
488 warning_say("Could not find cmake/${CMAKE_ASM_MASM_COMPILER_ID}/AsmFlags.cmake: will only use default flags")
489 endif()
490else()
491 # Unix (including Mac) based systems use CMAKE_ASM_COMPILER
492 # Unix assembly files can be handled by compiler usually.
Jim Cownie3b81ce62014-08-05 09:32:28 +0000493 find_file(assembler_specific_include_file_found AsmFlags.cmake ${CMAKE_MODULE_PATH})
494 if(assembler_specific_include_file_found)
495 include(AsmFlags)
496 append_assembler_specific_asm_flags(ASM_FLAGS)
497 else()
498 warning_say("Could not find cmake/${CMAKE_ASM_COMPILER_ID}/AsmFlags.cmake: will only use default flags")
499 endif()
500endif()
Jim Cownie3b81ce62014-08-05 09:32:28 +0000501
502# Grab all the compiler-independent flags
503append_c_and_cxx_flags_common(C_FLAGS CXX_FLAGS)
504append_asm_flags_common(ASM_FLAGS)
505append_fort_flags_common(F_FLAGS)
506append_linker_flags_common(LD_FLAGS LD_LIB_FLAGS)
507append_archiver_flags_common(AR_FLAGS)
508append_cpp_flags(DEFINITIONS_FLAGS)
509
510# Setup the flags correctly for cmake (covert to string)
511# Pretty them up (STRIP any beginning and trailing whitespace)
512list_to_string("${DEFINITIONS_FLAGS}" DEFINITIONS_FLAGS)
Jonathan Peytonfbb15142015-05-26 17:27:01 +0000513list_to_string("${C_FLAGS}" C_FLAGS)
514list_to_string("${CXX_FLAGS}" CXX_FLAGS)
515list_to_string("${ASM_FLAGS}" ASM_FLAGS)
516list_to_string("${LD_FLAGS}" LD_FLAGS)
517list_to_string("${LD_LIB_FLAGS}" LD_LIB_FLAGS)
518# Windows specific for creating import library
519list_to_string("${AR_FLAGS}" AR_FLAGS)
520string(STRIP "${DEFINITIONS_FLAGS}" DEFINITIONS_FLAGS)
521string(STRIP "${C_FLAGS}" C_FLAGS)
522string(STRIP "${CXX_FLAGS}" CXX_FLAGS)
523string(STRIP "${ASM_FLAGS}" ASM_FLAGS)
524string(STRIP "${LD_FLAGS}" LD_FLAGS)
525string(STRIP "${LD_LIB_FLAGS}" LD_LIB_FLAGS)
526# Windows specific for creating import library
527string(STRIP "${AR_FLAGS}" AR_FLAGS)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000528
529# Grab the Perl flags
530set_ev_flags(ev_flags) # expand-vars.pl flags
531set_gd_flags(gd_flags) # generate-def.pl flags (Windows only)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000532set(oa_opts "--os=${real_os}" "--arch=${LIBOMP_ARCH}") # sent to the perl scripts
Jim Cownie3b81ce62014-08-05 09:32:28 +0000533
534#########################################################
535# Getting correct source files (cmake/SourceFiles.cmake)
536set_c_files(lib_c_items)
537set_cpp_files(lib_cxx_items)
538set_asm_files(lib_asm_items)
539set_imp_c_files(imp_c_items) # Windows-specific
Jim Cownie3b81ce62014-08-05 09:32:28 +0000540set(lib_src_files "${lib_c_items}" "${lib_cxx_items}" "${lib_asm_items}")
541set(imp_src_files "${imp_c_items}")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000542
543#####################################################################
544# Debug print outs. Will print "variable = ${variable}" if GLOBAL_DEBUG == 1
545if(GLOBAL_DEBUG)
546 include(CMakePrintSystemInformation)
547endif()
548debug_say_var(CMAKE_ASM_COMPILE_OBJECT)
549debug_say_var(CMAKE_RC_COMPILER)
550debug_say_var(CMAKE_C_COMPILER_ID)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000551debug_say_var(date)
Jonathan Peyton7979a072015-05-20 22:33:24 +0000552debug_say_var(LIBOMP_STATS)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000553debug_say_var(lib_file)
554debug_say_var(export_lib_files)
555debug_say_var(DEFINITIONS_FLAGS)
556debug_say_var(C_FLAGS)
557debug_say_var(CXX_FLAGS)
558debug_say_var(ASM_FLAGS)
559debug_say_var(F_FLAGS)
560debug_say_var(LD_FLAGS)
561debug_say_var(LD_LIB_FLAGS)
562debug_say_var(AR_FLAGS)
563debug_say_var(ev_flags)
564debug_say_var(gd_flags)
565debug_say_var(oa_opts)
566debug_say_var(lib_c_items)
567debug_say_var(lib_cxx_items)
568debug_say_var(lib_asm_items)
569debug_say_var(imp_c_items)
570debug_say_var(lib_src_files)
571debug_say_var(imp_src_files)
572
573####################################################################
Jim Cownie3b81ce62014-08-05 09:32:28 +0000574# Print configuration after all variables are set.
Jonathan Peyton7979a072015-05-20 22:33:24 +0000575if(${LIBOMP_STANDALONE_BUILD})
576 say("LIBOMP: Operating System -- ${LIBOMP_OS}")
577 say("LIBOMP: Target Architecture -- ${LIBOMP_ARCH}")
Andrey Churbanov648467e2015-05-05 20:02:52 +0000578 if(${MIC})
Jonathan Peyton7979a072015-05-20 22:33:24 +0000579 say("LIBOMP: Intel(R) MIC Architecture -- ${LIBOMP_MIC_ARCH}")
Andrey Churbanov648467e2015-05-05 20:02:52 +0000580 endif()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000581 say("LIBOMP: Build Type -- ${CMAKE_BUILD_TYPE}")
582 say("LIBOMP: OpenMP Version -- ${LIBOMP_OMP_VERSION}")
583 say("LIBOMP: Lib Type -- ${LIBOMP_LIB_TYPE}")
584 say("LIBOMP: Fortran Modules -- ${LIBOMP_FORTRAN_MODULES}")
Andrey Churbanov648467e2015-05-05 20:02:52 +0000585 # will say development if all zeros
586 if("${build_number}" STREQUAL "00000000")
587 set(build "development")
588 else()
589 set(build "${build_number}")
590 endif()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000591 say("LIBOMP: Build -- ${build}")
592 say("LIBOMP: Stats-Gathering -- ${LIBOMP_STATS}")
593 say("LIBOMP: OMPT-support -- ${LIBOMP_OMPT_SUPPORT}")
594 if(${LIBOMP_OMPT_SUPPORT})
595 say("LIBOMP: OMPT-blame -- ${LIBOMP_OMPT_BLAME}")
596 say("LIBOMP: OMPT-trace -- ${LIBOMP_OMPT_TRACE}")
Andrey Churbanov648467e2015-05-05 20:02:52 +0000597 endif()
Jonathan Peyton7979a072015-05-20 22:33:24 +0000598 say("LIBOMP: Use build.pl rules -- ${LIBOMP_USE_BUILDPL_RULES}")
599 say("LIBOMP: Adaptive locks -- ${LIBOMP_USE_ADAPTIVE_LOCKS}")
600 say("LIBOMP: Use predefined linker flags -- ${LIBOMP_USE_PREDEFINED_LINKER_FLAGS}")
601 say("LIBOMP: Compiler supports quad precision -- ${LIBOMP_COMPILER_SUPPORTS_QUAD_PRECISION}")
Jim Cownie3b81ce62014-08-05 09:32:28 +0000602endif()
Andrey Churbanov648467e2015-05-05 20:02:52 +0000603
Jonathan Peyton52158902015-06-11 17:23:57 +0000604add_subdirectory(src)
Jim Cownie3b81ce62014-08-05 09:32:28 +0000605