blob: 01af0589312792b21d24a95acc44c6f4341c5d34 [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###############################################################################
13# This file contains additional build rules that correspond to build.pl's rules
14# Building libiomp5.dbg is linux only, Windows will build libiomp5md.dll.pdb
15#
16# ######### BUILD DEPENDENCIES ##########
17#
18# exports/.../libiomp5.so exports/.../libiomp5.dbg
19# [copy] | | [copy]
20# | |
21# ./libiomp5.so ./libiomp5.dbg
22# [copy] / OR \____________ [copy] | [copy]
23# / \ |
24# ./unstripped/libiomp5.so ./stripped/libiomp5.so ./unstripped/libiomp5.dbg
25# / \ /
26# / [linking] \[strip] /[strip and store]
27# / \ /
28# ${objs} (maybe compiled with -g) ./unstripped/libiomp5.so (library with debug info in it)
29# |
30# | [linking]
31# |
32# ${objs} (always compiled with -g)
33#
34# For icc Linux builds, we always include debugging information via -g and create libiomp5.dbg
35# so that Intel(R) Parallel Amplifier can use the .dbg file.
36# For icc Windows builds, we always include debugging information via -Zi and create libiomp5.pdb
37# in a fashion similar to libiomp5.dbg
38# For icc Mac builds, we don't bother with the debug info.
39
40# We build library in unstripped directory
41file(MAKE_DIRECTORY ${build_dir}/unstripped)
42
43# Only build the .dbg file for Release builds
44# Debug and RelWithDebInfo builds should not create a .dbg file.
45# The debug info should remain in the library file.
46if(${LINUX} AND ${RELEASE_BUILD})
47 set(dbg_file ${lib_item}.dbg)
48endif()
49
50################################
51# --- Create $(lib_file).dbg ---
52if(NOT "${dbg_file}" STREQUAL "")
53 # if a ${dbg_file} file is going to be created, then
54 file(MAKE_DIRECTORY ${build_dir}/stripped)
55
56 # ./${lib_file} : stripped/${lib_file}
57 # copy stripped/${lib_file} ./${lib_file}
58 simple_copy_recipe("${lib_file}" "${build_dir}/stripped" "${build_dir}")
59
60 # stripped/${lib_file} : unstripped/${lib_file} ./${dbg_file}
61 # objcopy --strip-debug unstripped/${lib_file} stripped/${lib_file}.tmp
62 # objcopy --add-gnu-debuglink=${dbg_file} stripped/${lib_file}.tmp stripped/${lib_file}
63 add_custom_command(
64 OUTPUT ${build_dir}/stripped/${lib_file}
65 COMMAND ${CMAKE_OBJCOPY} --strip-debug ${build_dir}/unstripped/${lib_file} ${build_dir}/stripped/${lib_file}.tmp
66 COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${dbg_file} ${build_dir}/stripped/${lib_file}.tmp ${build_dir}/stripped/${lib_file}
67 DEPENDS "${build_dir}/${dbg_file}"
68 )
69
70 # ./${dbg_file} : unstripped/${dbg_file}
71 # copy unstripped/${dbg_file} ./${dbg_file}
72 simple_copy_recipe("${dbg_file}" "${build_dir}/unstripped" "${build_dir}")
73
74 # unstripped/${dbg_file} : unstripped/${lib_file}
75 # objcopy --only-keep-debug unstripped/${lib_file} unstripped/${dbg_file}
76 add_custom_command(
77 OUTPUT ${build_dir}/unstripped/${dbg_file}
78 COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${build_dir}/unstripped/${lib_file} ${build_dir}/unstripped/${dbg_file}
79 DEPENDS iomp5
80 )
81
82else()
83
84 # ./${lib_file} : unstripped/${lib_file}
85 # copy unstripped/${lib_file} ./${lib_file}
86 simple_copy_recipe("${lib_file}" "${build_dir}/unstripped" "${build_dir}")
87endif()
88
89# Windows specific command to move around debug info files post-build
90if(NOT "${pdb_file}" STREQUAL "" AND ${RELEASE_BUILD})
91 add_custom_command(TARGET iomp5 POST_BUILD
92 COMMAND ${CMAKE_COMMAND} -E rename ${pdb_file} ${pdb_file}.nonstripped
93 COMMAND ${CMAKE_COMMAND} -E rename ${pdb_file}.stripped ${pdb_file}
94 )
95endif()
96
97# Have icc build libiomp5 in unstripped directory
98set_target_properties(iomp5 PROPERTIES
99 LIBRARY_OUTPUT_DIRECTORY "${build_dir}/unstripped"
100 RUNTIME_OUTPUT_DIRECTORY "${build_dir}/unstripped"
101 ARCHIVE_OUTPUT_DIRECTORY "${build_dir}"
102)
103
104# Always use RelWithDebInfo flags for Release builds when using the build.pl's build rules (use -g -O2 instead of just -O3)
105# The debug info is then stripped out at the end of the build and put into libiomp5.dbg for Linux
106if(${RELEASE_BUILD} AND NOT ${MAC})
107 set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELWITHDEBINFO} )
108 set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
109 set(CMAKE_ASM_FLAGS_RELEASE ${CMAKE_ASM_FLAGS_RELWITHDEBINFO})
110endif()
111