changeset 108:4672eba7b1ed v0.10-rc3

cmake: generate and use GNU version scripts when necessary Instead of assuming that we're always using the Illumos linker when handling mapfiles, use the GNU ld specific way of passing version scripts when we detect that we're using GNU ld. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 30 Apr 2016 18:15:37 -0400
parents 3d59e3c778f3
children 5797865a0b3d
files .gitignore cmake/mapfile.cmake
diffstat 2 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/.gitignore	Sat Apr 30 18:10:56 2016 -0400
+++ b/.gitignore	Sat Apr 30 18:15:37 2016 -0400
@@ -5,6 +5,7 @@
 cmake_install.cmake
 install_manifest.txt
 Testing
+mapfile-vers.gnu
 
 sexpr.lex.c
 sexpr.tab.c
--- a/cmake/mapfile.cmake	Sat Apr 30 18:10:56 2016 -0400
+++ b/cmake/mapfile.cmake	Sat Apr 30 18:15:37 2016 -0400
@@ -21,9 +21,27 @@
 #
 
 macro(target_apply_mapfile tgt mapfile)
-	# This is assuming an illumos-style -M linker option & mapfile format
+	if (HAVE_GNU_LD)
+		set(ld_script "${CMAKE_CURRENT_BINARY_DIR}/${mapfile}.gnu")
+		set(ld_flag "'-Wl,${ld_script}'")
+		add_custom_command(
+			OUTPUT "${ld_script}"
+			COMMAND echo "VERSION {" > "${ld_script}"
+			COMMAND cat "${CMAKE_CURRENT_SOURCE_DIR}/${mapfile}" >> "${ld_script}"
+			COMMAND echo "'};'" >> "${ld_script}"
+			DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${mapfile}"
+			COMMENT "Generating ${mapfile}.gnu for ${tgt}"
+		)
+		add_custom_target("${tgt}-${mapfile}" DEPENDS "${ld_script}")
+		add_dependencies("${tgt}" "${tgt}-${mapfile}")
+	else()
+		# This is assuming an illumos-style -M linker option &
+		# mapfile format
+		set(ld_script "${CMAKE_CURRENT_SOURCE_DIR}/${mapfile}")
+		set(ld_flag "-Wl,-M '${ld_script}'")
+	endif()
 	set_target_properties("${tgt}" PROPERTIES
-		LINK_FLAGS "-Wl,-M '${CMAKE_CURRENT_SOURCE_DIR}/${mapfile}'"
-		LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${mapfile}"
+		LINK_FLAGS "${ld_flag}"
+		LINK_DEPENDS "${ld_script}"
 	)
 endmacro()