Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid to compare addr with random value with gfortran.
[simgrid.git] / buildtools / Cmake / MakeLib.cmake
1 ### Make Libs
2
3 ###############################
4 # Declare the library content #
5 ###############################
6
7 # Actually declare our libraries
8 add_library(simgrid SHARED ${simgrid_sources})
9 set_target_properties(simgrid PROPERTIES VERSION ${libsimgrid_version})
10
11 if(enable_lib_static)
12   add_library(simgrid_static STATIC ${simgrid_sources})
13 endif()
14
15 if(enable_java)
16   include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeJava.cmake)
17 endif()
18
19 add_dependencies(simgrid maintainer_files)
20
21 # Compute the dependencies of SimGrid
22 #####################################
23 set(SIMGRID_DEP "-lm")
24
25 if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
26   set(SIMGRID_DEP "${SIMGRID_DEP} -lstdc++")
27 elseif(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" 
28     AND NOT ${CMAKE_SYSTEM_VERSION} VERSION_LESS 10.0
29     AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
30   # FreeBSD from 10.0 provide a internal C++ stack (unused by gcc)
31   set(SIMGRID_DEP "${SIMGRID_DEP} -lc++")
32 endif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
33
34 if(pthread)
35   if(${CONTEXT_THREADS})
36     SET(SIMGRID_DEP "${SIMGRID_DEP} -pthread")
37   endif()
38 endif()
39
40 if(HAVE_LUA)
41   ADD_CUSTOM_TARGET(link_simgrid_lua ALL
42     DEPENDS     simgrid
43     ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
44     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
45     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
46     )
47   add_custom_command(
48     OUTPUT      ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE}
49     ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE}
50     ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE}
51     COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} # if it exists, creating the link fails. So cleanup before hand
52     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/lua/
53     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/lua/simgrid.${LIB_EXE} #for test
54
55     COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} # if it exists, creating the link fails. So cleanup before hand
56     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/msg/masterslave/
57     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/msg/masterslave/simgrid.${LIB_EXE} #for test
58
59     COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} # if it exists, creating the link fails. So cleanup before hand
60     COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/examples/simdag/
61     COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/lib/libsimgrid.${LIB_EXE} ${CMAKE_BINARY_DIR}/examples/simdag/simgrid.${LIB_EXE} #for test
62     )
63   SET(SIMGRID_DEP "${SIMGRID_DEP} -l${LIB_LUA_NAME}")
64 endif()
65
66 if(HAVE_GRAPHVIZ)
67   if(HAVE_CGRAPH_LIB)
68     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
69   else()
70     if(HAVE_AGRAPH_LIB)
71       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
72     endif()
73   endif()
74 endif()
75
76 if(HAVE_LIBSIGC++)
77   SET(SIMGRID_DEP "${SIMGRID_DEP} -lsigc-2.0")    
78 endif()
79
80 if(HAVE_GTNETS)
81   SET(SIMGRID_DEP "${SIMGRID_DEP} -lgtnets")
82 endif()
83
84 if(HAVE_MC)
85   # The availability of libunwind was checked in CompleteInFiles.cmake
86   #   (that includes FindLibunwind.cmake), so simply load it now.
87   
88   SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind")
89   # This supposes that the host machine is either an AMD or a X86.
90   # This is deeply wrong, and should be fixed by manually loading -lunwind-PLAT (FIXME)
91   if(PROCESSOR_x86_64)
92     SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86_64")
93   else()    
94     SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86")
95   endif()
96 endif()
97
98 if(MMALLOC_WANT_OVERRIDE_LEGACY AND HAVE_GNU_LD)
99   SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
100 endif()
101
102 if(HAVE_NS3)
103   if(${NS3_VERSION_MINOR} EQUAL 10)
104     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3")
105     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_NS3_3_10")
106     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_NS3_3_10")
107   else()
108     SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3.${NS3_VERSION_MINOR}-core -lns3.${NS3_VERSION_MINOR}-csma -lns3.${NS3_VERSION_MINOR}-point-to-point -lns3.${NS3_VERSION_MINOR}-internet -lns3.${NS3_VERSION_MINOR}-applications")
109   endif()
110 endif()
111
112 if(HAVE_POSIX_GETTIME)
113   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
114 endif()
115
116 if(HAVE_BACKTRACE_IN_LIBEXECINFO)
117   SET(SIMGRID_DEP "${SIMGRID_DEP} -lexecinfo")
118 endif(HAVE_BACKTRACE_IN_LIBEXECINFO)
119
120 # Compute the dependencies of SMPI
121 ##################################
122 if(enable_smpi AND APPLE)
123   set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
124 endif()
125
126 target_link_libraries(simgrid   ${SIMGRID_DEP})
127
128 # Pass dependencies to static libs
129 ##################################
130 if(enable_lib_static)
131   target_link_libraries(simgrid_static  ${SIMGRID_DEP})
132   add_dependencies(simgrid_static maintainer_files)
133   set_target_properties(simgrid_static PROPERTIES OUTPUT_NAME simgrid)
134 endif()
135
136 # Dependencies from maintainer mode
137 ###################################
138 if(enable_maintainer_mode AND PYTHON_EXE)
139   add_dependencies(simgrid simcalls_generated_src)
140 endif()
141 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
142   add_dependencies(simgrid automaton_generated_src)
143 endif()