3.2.1.7 : La gestion de Linux et OSX

Voici le rpath_utils.cmake : Quand on compile sous OSX il faut faire particulièrement attention aux chemins d'exécution : RPATH (ou RUN PATH). Donc si on est sous OSX on définit tout ça :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if(APPLE)
	message(STATUS "Build on macosx")
	set(CMAKE_MACOSX_RPATH 1 CACHE BOOL "Global rpath" FORCE)
	
	# use, i.e. don't skip the full RPATH for the build tree
	set(CMAKE_SKIP_BUILD_RPATH  FALSE)

	# when building, don't use the install RPATH already
	# (but later on when installing)
	set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 

	set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

	# add the automatically determined parts of the RPATH
	# which point to directories outside the build tree to the install RPATH
	set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
else()
	message(STATUS "Build on Linux")
endif()


Sur certain OS comme Fedora le dossier lib n'est pas utilisé pour les bibiothèques 64 bits, et lib64 doit être utilisé à la place noteau delas d'être completement chiant et stupide, c'est toujours bien d'avoir un script qui gère cela correctement à notre place :
1
2
3
4
if(CREATE_RPM)
	set(LIBRARY_DIRECTORY "lib64")
	set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" "${CMAKE_INSTALL_PREFIX}/lib64")
endif()


Si on demande la création de paquets binaire, on active le mode adéquat :
1
2
3
if(CREATE_RPM OR CREATE_DEB)
	set(PACKAGE_CREATION_MODE yes CACHE BOOL "Say if we are in the package creation mode or not at the install")
endif()


Le fichier rpath_utils.cmake complet :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
if(APPLE)
	message(STATUS "Build on macosx")
	set(CMAKE_MACOSX_RPATH 1 CACHE BOOL "Global rpath" FORCE)
	
	# use, i.e. don't skip the full RPATH for the build tree
	set(CMAKE_SKIP_BUILD_RPATH  FALSE)

	# when building, don't use the install RPATH already
	# (but later on when installing)
	set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 

	set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

	# add the automatically determined parts of the RPATH
	# which point to directories outside the build tree to the install RPATH
	set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
else()
	message(STATUS "Build on Linux")
endif()

if(CREATE_RPM)
	set(LIBRARY_DIRECTORY "lib64")
	set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" "${CMAKE_INSTALL_PREFIX}/lib64")
endif()


if(CREATE_RPM OR CREATE_DEB)
	set(PACKAGE_CREATION_MODE yes CACHE BOOL "Say if we are in the package creation mode or not at the install")
endif()
Lien de téléchargement ici.