]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STARLIGHT/starlight/cmake_modules/CommonMacros.cmake
STARLIGHT code and interface
[u/mrichter/AliRoot.git] / STARLIGHT / starlight / cmake_modules / CommonMacros.cmake
CommitLineData
da32329d
AM
1###########################################################################
2#
3# Copyright 2010
4#
5# This file is part of Starlight.
6#
7# Starlight is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# Starlight is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with Starlight. If not, see <http://www.gnu.org/licenses/>.
19#
20###########################################################################
21#
22# File and Version Information:
23# $Rev:: 27 $: revision of last commit
24# $Author:: bgrube $: author of last commit
25# $Date:: 2010-11-29 13:00:04 +0100 #$: date of last commit
26#
27# Description:
28# collection of useful cmake macros
29#
30#
31###########################################################################
32
33
34# takes list of file names and returns file name list with new extension
35# example:
36# switch_file_extension("${CC_LIST}" ".cc" ".h" H_LIST)
37function(switch_file_extension IN_FILE_LIST OLD_EXT NEW_EXT OUT_FILE_LIST)
38 set(NEW_FILE_LIST)
39 foreach(_OLD_FILE ${IN_FILE_LIST})
40 string(REGEX REPLACE "^(.*)${OLD_EXT}$" "\\1${NEW_EXT}" _NEW_FILE ${_OLD_FILE})
41 set(NEW_FILE_LIST ${NEW_FILE_LIST} ${_NEW_FILE})
42 endforeach()
43 set(${OUT_FILE_LIST} ${NEW_FILE_LIST})
44endfunction(switch_file_extension)
45
46
47# adds standard shared library
48# additional libraries that should be linked to can be given as optional arguments
49function(make_shared_library LIB_NAME SOURCES)
50 add_library(${LIB_NAME} SHARED ${SOURCES})
51 # proccess link libraries in additional arguments
52 foreach(_LIB ${ARGN})
53 target_link_libraries(${LIB_NAME} ${_LIB})
54 endforeach()
55endfunction(make_shared_library)
56
57
58# adds standard executable
59# additional libraries that should be linked to can be given as optional arguments
60function(make_executable EXE_NAME SOURCES)
61 add_executable(${EXE_NAME} ${SOURCES})
62 # proccess link libraries in additional arguments
63 foreach(_LIB ${ARGN})
64 target_link_libraries(${EXE_NAME} ${_LIB})
65 endforeach()
66endfunction(make_executable)
67
68
69macro(enforce_out_of_source_build)
70 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
71 message(FATAL_ERROR "Building this project in the source directory is not allowed. Please remove CMakeCache.txt, create a build directory, and run cmake there, for example:
72rm CMakeCache.txt
73mkdir build && cd build
74cmake ..")
75 endif()
76endmacro(enforce_out_of_source_build)