Jim Cownie | 4cc4bb4 | 2014-10-07 16:25:50 +0000 | [diff] [blame] | 1 | # |
| 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 Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 12 | ############################################################################### |
Andrey Churbanov | 19be978 | 2015-01-16 13:05:23 +0000 | [diff] [blame] | 13 | # This file contains additional build rules that correspond to build.pl's rules. |
Jonathan Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 14 | # Building libomp.dbg is linux only, Windows will build libompmd.dll.pdb |
Jonathan Peyton | 7979a07 | 2015-05-20 22:33:24 +0000 | [diff] [blame] | 15 | # This file is only active if ${LIBOMP_USE_BUILDPL_RULES} is true. |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 16 | # |
| 17 | # ######### BUILD DEPENDENCIES ########## |
| 18 | # |
Jonathan Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 19 | # exports/.../libomp.so exports/.../libomp.dbg |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 20 | # [copy] | | [copy] |
| 21 | # | | |
Jonathan Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 22 | # ./libomp.so ./libomp.dbg |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 23 | # [copy] / OR \____________ [copy] | [copy] |
| 24 | # / \ | |
Jonathan Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 25 | # ./unstripped/libomp.so ./stripped/libomp.so ./unstripped/libomp.dbg |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 26 | # / \ / |
| 27 | # / [linking] \[strip] /[strip and store] |
| 28 | # / \ / |
Jonathan Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 29 | # ${objs} (maybe compiled with -g) ./unstripped/libomp.so (library with debug info in it) |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 30 | # | |
| 31 | # | [linking] |
| 32 | # | |
| 33 | # ${objs} (always compiled with -g) |
| 34 | # |
Jonathan Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 35 | # For icc Linux builds, we always include debugging information via -g and create libomp.dbg |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 36 | # so that Intel(R) Parallel Amplifier can use the .dbg file. |
Jonathan Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 37 | # For icc Windows builds, we always include debugging information via -Zi and create libomp.pdb |
| 38 | # in a fashion similar to libomp.dbg |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 39 | # For icc Mac builds, we don't bother with the debug info. |
| 40 | |
| 41 | # We build library in unstripped directory |
| 42 | file(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. |
| 47 | if(${LINUX} AND ${RELEASE_BUILD}) |
| 48 | set(dbg_file ${lib_item}.dbg) |
| 49 | endif() |
| 50 | |
| 51 | ################################ |
| 52 | # --- Create $(lib_file).dbg --- |
| 53 | if(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 Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 80 | DEPENDS omp |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 81 | ) |
| 82 | |
| 83 | else() |
| 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}") |
| 88 | endif() |
| 89 | |
| 90 | # Windows specific command to move around debug info files post-build |
| 91 | if(NOT "${pdb_file}" STREQUAL "" AND ${RELEASE_BUILD}) |
Jonathan Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 92 | add_custom_command(TARGET omp POST_BUILD |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 93 | COMMAND ${CMAKE_COMMAND} -E rename ${pdb_file} ${pdb_file}.nonstripped |
| 94 | COMMAND ${CMAKE_COMMAND} -E rename ${pdb_file}.stripped ${pdb_file} |
| 95 | ) |
| 96 | endif() |
| 97 | |
Jonathan Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 98 | # Have icc build libomp in unstripped directory |
| 99 | set_target_properties(omp PROPERTIES |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 100 | 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 Peyton | 227e1ae | 2015-06-01 03:05:13 +0000 | [diff] [blame] | 106 | # The debug info is then stripped out at the end of the build and put into libomp.dbg for Linux |
Jim Cownie | 3b81ce6 | 2014-08-05 09:32:28 +0000 | [diff] [blame] | 107 | if(${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}) |
| 111 | endif() |
| 112 | |