blob: 6565c5c700becee706f3e3eef0ee44b00b1a9ed7 [file] [log] [blame]
Jim Cownie4cc4bb42014-10-07 16:25:50 +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#
11
Jim Cownie3b81ce62014-08-05 09:32:28 +000012###############################################################################
Andrey Churbanov19be9782015-01-16 13:05:23 +000013# This file contains additional build rules that correspond to build.pl's rules.
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000014# Building libomp.dbg is linux only, Windows will build libompmd.dll.pdb
Jonathan Peyton7979a072015-05-20 22:33:24 +000015# This file is only active if ${LIBOMP_USE_BUILDPL_RULES} is true.
Jim Cownie3b81ce62014-08-05 09:32:28 +000016#
17# ######### BUILD DEPENDENCIES ##########
18#
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000019# exports/.../libomp.so exports/.../libomp.dbg
Jim Cownie3b81ce62014-08-05 09:32:28 +000020# [copy] | | [copy]
21# | |
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000022# ./libomp.so ./libomp.dbg
Jim Cownie3b81ce62014-08-05 09:32:28 +000023# [copy] / OR \____________ [copy] | [copy]
24# / \ |
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000025# ./unstripped/libomp.so ./stripped/libomp.so ./unstripped/libomp.dbg
Jim Cownie3b81ce62014-08-05 09:32:28 +000026# / \ /
27# / [linking] \[strip] /[strip and store]
28# / \ /
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000029# ${objs} (maybe compiled with -g) ./unstripped/libomp.so (library with debug info in it)
Jim Cownie3b81ce62014-08-05 09:32:28 +000030# |
31# | [linking]
32# |
33# ${objs} (always compiled with -g)
34#
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000035# For icc Linux builds, we always include debugging information via -g and create libomp.dbg
Jim Cownie3b81ce62014-08-05 09:32:28 +000036# so that Intel(R) Parallel Amplifier can use the .dbg file.
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000037# For icc Windows builds, we always include debugging information via -Zi and create libomp.pdb
38# in a fashion similar to libomp.dbg
Jim Cownie3b81ce62014-08-05 09:32:28 +000039# For icc Mac builds, we don't bother with the debug info.
40
41# We build library in unstripped directory
42file(MAKE_DIRECTORY ${build_dir}/unstripped)
43
44# Only build the .dbg file for Release builds
45# Debug and RelWithDebInfo builds should not create a .dbg file.
46# The debug info should remain in the library file.
47if(${LINUX} AND ${RELEASE_BUILD})
48 set(dbg_file ${lib_item}.dbg)
49endif()
50
51################################
52# --- Create $(lib_file).dbg ---
53if(NOT "${dbg_file}" STREQUAL "")
54 # if a ${dbg_file} file is going to be created, then
55 file(MAKE_DIRECTORY ${build_dir}/stripped)
56
57 # ./${lib_file} : stripped/${lib_file}
58 # copy stripped/${lib_file} ./${lib_file}
59 simple_copy_recipe("${lib_file}" "${build_dir}/stripped" "${build_dir}")
60
61 # stripped/${lib_file} : unstripped/${lib_file} ./${dbg_file}
62 # objcopy --strip-debug unstripped/${lib_file} stripped/${lib_file}.tmp
63 # objcopy --add-gnu-debuglink=${dbg_file} stripped/${lib_file}.tmp stripped/${lib_file}
64 add_custom_command(
65 OUTPUT ${build_dir}/stripped/${lib_file}
66 COMMAND ${CMAKE_OBJCOPY} --strip-debug ${build_dir}/unstripped/${lib_file} ${build_dir}/stripped/${lib_file}.tmp
67 COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${dbg_file} ${build_dir}/stripped/${lib_file}.tmp ${build_dir}/stripped/${lib_file}
68 DEPENDS "${build_dir}/${dbg_file}"
69 )
70
71 # ./${dbg_file} : unstripped/${dbg_file}
72 # copy unstripped/${dbg_file} ./${dbg_file}
73 simple_copy_recipe("${dbg_file}" "${build_dir}/unstripped" "${build_dir}")
74
75 # unstripped/${dbg_file} : unstripped/${lib_file}
76 # objcopy --only-keep-debug unstripped/${lib_file} unstripped/${dbg_file}
77 add_custom_command(
78 OUTPUT ${build_dir}/unstripped/${dbg_file}
79 COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${build_dir}/unstripped/${lib_file} ${build_dir}/unstripped/${dbg_file}
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000080 DEPENDS omp
Jim Cownie3b81ce62014-08-05 09:32:28 +000081 )
82
83else()
84
85 # ./${lib_file} : unstripped/${lib_file}
86 # copy unstripped/${lib_file} ./${lib_file}
87 simple_copy_recipe("${lib_file}" "${build_dir}/unstripped" "${build_dir}")
88endif()
89
90# Windows specific command to move around debug info files post-build
91if(NOT "${pdb_file}" STREQUAL "" AND ${RELEASE_BUILD})
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000092 add_custom_command(TARGET omp POST_BUILD
Jim Cownie3b81ce62014-08-05 09:32:28 +000093 COMMAND ${CMAKE_COMMAND} -E rename ${pdb_file} ${pdb_file}.nonstripped
94 COMMAND ${CMAKE_COMMAND} -E rename ${pdb_file}.stripped ${pdb_file}
95 )
96endif()
97
Jonathan Peyton227e1ae2015-06-01 03:05:13 +000098# Have icc build libomp in unstripped directory
99set_target_properties(omp PROPERTIES
Jim Cownie3b81ce62014-08-05 09:32:28 +0000100 LIBRARY_OUTPUT_DIRECTORY "${build_dir}/unstripped"
101 RUNTIME_OUTPUT_DIRECTORY "${build_dir}/unstripped"
102 ARCHIVE_OUTPUT_DIRECTORY "${build_dir}"
103)
104
105# Always use RelWithDebInfo flags for Release builds when using the build.pl's build rules (use -g -O2 instead of just -O3)
Jonathan Peyton227e1ae2015-06-01 03:05:13 +0000106# The debug info is then stripped out at the end of the build and put into libomp.dbg for Linux
Jim Cownie3b81ce62014-08-05 09:32:28 +0000107if(${RELEASE_BUILD} AND NOT ${MAC})
108 set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELWITHDEBINFO} )
109 set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
110 set(CMAKE_ASM_FLAGS_RELEASE ${CMAKE_ASM_FLAGS_RELWITHDEBINFO})
111endif()
112