From: Yonghong Song Date: Wed, 23 Aug 2017 20:40:47 +0000 (-0700) Subject: fix lua-bcc build issue with cmake try_compile X-Git-Tag: submit/tizen_4.0/20171018.110122~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=75e2f3798947f4f77e91b6b3af8e7bd969663f65;p=platform%2Fupstream%2Fbcc.git fix lua-bcc build issue with cmake try_compile Certain versions of recent gcc (e.g., gcc 6.3.0 on ubuntu17.04) has pie enabled by default at linker (collect2) stage. The compilation flag "-no-pie" is available to negate this linker option. Add -no-pie to compilation flag only if it is available. Earlier gcc compiler may not have this option but it does not have linker pie on-by-default either. Tested with ubuntu 17.04 and my local gcc 4.8.5 (not accepting -no-pie). Signed-off-by: Yonghong Song --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 858e12a6..b23261cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ include(cmake/GetGitRevisionDescription.cmake) include(cmake/version.cmake) include(GNUInstallDirs) include(CheckCXXCompilerFlag) +include(cmake/FindCompilerFlag.cmake) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) diff --git a/cmake/FindCompilerFlag.cmake b/cmake/FindCompilerFlag.cmake new file mode 100644 index 00000000..8a6fbd46 --- /dev/null +++ b/cmake/FindCompilerFlag.cmake @@ -0,0 +1,15 @@ +# Copyright (c) 2017 Facebook, Inc. +# Licensed under the Apache License, Version 2.0 (the "License") + +if (CMAKE_C_COMPILER_ID MATCHES "Clang") + set(COMPILER_NOPIE_FLAG "-nopie") +else() + set(CMAKE_REQUIRED_FLAGS "-no-pie") + CHECK_CXX_SOURCE_COMPILES("int main() {return 0;}" + HAVE_NO_PIE_FLAG) + if (HAVE_NO_PIE_FLAG) + set(COMPILER_NOPIE_FLAG "-no-pie") + else() + set(COMPILER_NOPIE_FLAG "") + endif() +endif() diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt index 09e456d4..076706bb 100644 --- a/src/lua/CMakeLists.txt +++ b/src/lua/CMakeLists.txt @@ -24,11 +24,9 @@ if (LUAJIT_LIBRARIES AND LUAJIT) set_target_properties(bcc-lua PROPERTIES LINKER_LANGUAGE C) target_link_libraries(bcc-lua ${LUAJIT_LIBRARIES}) target_link_libraries(bcc-lua -Wl,--whole-archive bcc-static -Wl,--no-whole-archive) - if (CMAKE_C_COMPILER_ID MATCHES "Clang") - target_link_libraries(bcc-lua -nopie) - else() - target_link_libraries(bcc-lua --no-pie) - endif() + if (NOT COMPILER_NOPIE_FLAG EQUAL "") + target_link_libraries(bcc-lua ${COMPILER_NOPIE_FLAG}) + endif() install(TARGETS bcc-lua RUNTIME DESTINATION bin) endif()