Completely reengineered version of CMake build system (Johny)
[u/mrichter/AliRoot.git] / cmake / CMakelinux.cmake
1 #--------------------------------------------------------------------------------#
2 # Linux CMake System configuration file for the AliRoot Build System             #
3 #                                                                                # 
4 # Author: Johny Jose (johny.jose@cern.ch)                                        #
5 #                                                                                #
6 #--------------------------------------------------------------------------------#
7
8
9 cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
10
11 #Retrieve Compiler Version
12
13 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
14
15   execute_process (COMMAND ${CMAKE_C_COMPILER} -dumpversion | cut -d. -f1 
16                    OUTPUT_VARIABLE CCMAJORV
17                    OUTPUT_STRIP_TRAILING_WHITESPACE) 
18   execute_process (COMMAND ${CMAKE_C_COMPILER} -dumpversion | cut -d. -f2
19                    OUTPUT_VARIABLE CCMINORV
20                    OUTPUT_STRIP_TRAILING_WHITESPACE)
21
22 endif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
23
24 # Global Optimization
25 set(OPT "-O -g")
26 set(NOOPT "-g")
27
28 set(CXXOPT ${OPT})
29 set(CXXNOPT ${NOOPT})
30 set(COPT ${OPT})
31 set(FOPT ${OPT})
32
33 #CERNLIB defines
34 set(CLIBDEFS "-DCERNLIB_LINUX -DCERNLIB_BLDLIB -DCERNLIB_CZ")
35 set(CLIBCXXOPTS)
36 set(CLIBCOPT)
37 set(CLIBFOPT ${CLIBDEFS})
38
39 set(CXXWARN "-Wall -Wno-long-long -W -Weffc++ -Wshadow -Woverloaded-virtual -ansi")
40
41 if(CCMAJORV STREQUAL "2")
42
43   set(CXXFLAGS "${OPT} -fPIC -pipe")
44   set(CXXFLAGSNO "${NOOPT} -fPIC -pipe")
45
46 elseif(CCMAJORV STREQUAL "3")
47
48   set(CXXFLAGS "${OPT} -fPIC -pipe -fmessage-length=0")
49   add_definitions(-Dlinux)
50   set(CXXFLAGSNO "${NOOPT} -fPIC -pipe -fmessage-length=0")
51
52 elseif(CCMAJORV STREQUAL "4")
53   
54   set(CXXFLAGS "${OPT} -fPIC -pipe -fmessage-length=0")
55   add_definitions(-Dlinux)
56   set(CXXFLAGSNO "${NOOPT} -fPIC -pipe -fmessage-length=0")
57
58 else ()
59
60   set(CXXFLAGS "${OPT} -pipe -fmessage-length=0")
61   add_definitions(-Dlinux)
62   set(CXXFLAGSNO "${NOOPT} -pipe -fmessage-length=0") 
63
64 endif(CCMAJORV STREQUAL "2")
65
66 set(CFLAGS      "${OPT} -Wall -Werror -fPIC -pipe -Wno-long-long -pedantic-errors -ansi")
67 set(FFLAGS "${CLIBFOPT} ${FOPT} -fPIC -fno-second-underscore")
68
69 set(SYSLIBS "-ldl -lcrypt -L/usr/X11R6/lib -lX11")
70
71 if(${CMAKE_Fortran_COMPILER} MATCHES "g95")
72   
73   add_definitions(-DFORTRAN_G95)
74   execute_process(COMMAND ${CMAKE_Fortran_COMPILER} --print-search-dirs 
75                   OUTPUT_VARIABLE SHLIB
76                   OUTPUT_STRIP_TRAILING_WHITESPACE)
77   string(REGEX MATCH "^.*install:[^\n]*" SHLIB ${SHLIB})
78   string(REGEX REPLACE "^.*install: " "" SHLIB ${SHLIB})
79   set(SHLIB "-L${SHLIB} -lf95")
80
81 elseif(${CMAKE_Fortran_COMPILER} MATCHES "gfortran")
82   
83   set(FFLAGS "-DFORTRAN_GFORTRAN ${FFLAGS}")
84   execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -m32 -print-file-name=libgfortran.so
85                   OUTPUT_VARIABLE _shlib
86                   OUTPUT_STRIP_TRAILING_WHITESPACE)
87   execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -m32 -print-file-name=libgfortranbegin.a
88                   OUTPUT_VARIABLE SHLIB
89                   OUTPUT_STRIP_TRAILING_WHITESPACE)
90   set(SHLIB "${_shlib} ${SHLIB}")
91   set(SYSLIBS "${SYSLIBS} ${SHLIB}")
92
93 else()
94
95   set(SHLIB "-lg2c")
96   set(SYSLIBS "-lg2c")
97   
98 endif(${CMAKE_Fortran_COMPILER} MATCHES "g95")
99
100 set(LDFLAGS "${OPT}")
101 set(SOFLAGS "${OPT} -shared -Wl")
102 set(ALLIB)
103
104
105