Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'tracemgrsplit' into 'master'
[simgrid.git] / tools / cmake / MakeLib.cmake
1 ### Make Libs
2
3 # On macOS, specify that rpath is useful to look for the dependencies
4 # See https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling and Java.cmake
5 set(CMAKE_MACOSX_RPATH TRUE)
6 if(APPLE)
7   SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # When installed, use system path
8   set(CMAKE_SKIP_BUILD_RPATH FALSE)         # When executing from build tree, take the lib from the build path if exists
9   set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # When executing from build tree, take the lib from the system path if exists
10
11   # add the current location of libsimgrid-java.dynlib as a location for libsimgrid.dynlib
12   # (useful when unpacking the native libraries from the jarfile)
13   set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
14 endif()
15
16 ###############################
17 # Declare the library content #
18 ###############################
19
20 # Actually declare our libraries
21 add_library(simgrid SHARED ${simgrid_sources})
22 set_target_properties(simgrid PROPERTIES VERSION ${libsimgrid_version})
23 # The library can obviously use the internal headers
24 set_property(TARGET simgrid
25              APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
26
27 add_dependencies(simgrid maintainer_files)
28
29 if(enable_model-checking)
30   add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC})
31   target_link_libraries(simgrid-mc simgrid)
32   set_target_properties(simgrid-mc
33                         PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
34   set_property(TARGET simgrid-mc
35                APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
36   install(TARGETS simgrid-mc # install that binary without breaking the rpath on Mac
37     RUNTIME DESTINATION bin/)
38   add_dependencies(tests simgrid-mc)
39 endif()
40
41
42 # Compute the dependencies of SimGrid
43 #####################################
44 # search for dlopen
45 if("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD|Linux|SunOS")
46   find_library(DL_LIBRARY dl)
47 endif()
48 mark_as_advanced(DL_LIBRARY)
49
50 if (HAVE_BOOST_CONTEXTS)
51   set(SIMGRID_DEP "${SIMGRID_DEP} ${Boost_CONTEXT_LIBRARY}")
52 endif()
53
54 if(CMAKE_USE_PTHREADS_INIT)
55   set(SIMGRID_DEP "${SIMGRID_DEP} ${CMAKE_THREAD_LIBS_INIT}")
56 endif()
57
58 if(SIMGRID_HAVE_LUA)
59   ADD_CUSTOM_TARGET(link_simgrid_lua ALL
60     DEPENDS     simgrid
61     )
62   SET(SIMGRID_DEP "${SIMGRID_DEP} ${LUA_LIBRARY} ${DL_LIBRARY}")
63 endif()
64
65 if(HAVE_PAPI)
66   SET(SIMGRID_DEP "${SIMGRID_DEP} -lpapi")
67 endif()
68
69 if(HAVE_GRAPHVIZ)
70   if(HAVE_CGRAPH_LIB)
71     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
72   else()
73     if(HAVE_AGRAPH_LIB)
74       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
75     endif()
76   endif()
77 endif()
78
79 if(SIMGRID_HAVE_MC AND NOT ${DL_LIBRARY} STREQUAL "")
80   SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
81 endif()
82
83 if(HAVE_POSIX_GETTIME)
84   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
85 endif()
86
87 if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
88   set(SIMGRID_DEP "${SIMGRID_DEP} -lprocstat")
89 endif()
90
91 # Compute the dependencies of SMPI
92 ##################################
93
94 if(enable_smpi)
95   if(NOT ${DL_LIBRARY} STREQUAL "")
96     set(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}") # for privatization
97   endif()
98
99   add_executable(smpimain src/smpi/smpi_main.c)
100   target_link_libraries(smpimain simgrid)
101   set_target_properties(smpimain
102     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
103   install(TARGETS smpimain # install that binary without breaking the rpath on Mac
104     RUNTIME DESTINATION lib/simgrid)
105   add_dependencies(tests smpimain)
106
107   add_executable(smpireplaymain src/smpi/smpi_replay_main.cpp)
108   target_compile_options(smpireplaymain PRIVATE -fpic)
109   target_link_libraries(smpireplaymain simgrid -shared)
110   set_target_properties(smpireplaymain
111     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
112   install(TARGETS smpireplaymain # install that binary without breaking the rpath on Mac
113     RUNTIME DESTINATION lib/simgrid)
114   add_dependencies(tests smpireplaymain)
115
116   if(SMPI_FORTRAN)
117     if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
118       SET(SIMGRID_DEP "${SIMGRID_DEP} -lgfortran")
119     elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
120       SET(SIMGRID_DEP "${SIMGRID_DEP} -lifcore")
121     elseif(CMAKE_Fortran_COMPILER_ID MATCHES "PGI|Flang")
122       SET(SIMGRID_DEP "${SIMGRID_DEP} -lflang")
123       if("${CMAKE_SYSTEM}" MATCHES "FreeBSD")
124         set(SIMGRID_DEP "${SIMGRID_DEP} -lexecinfo")
125         if ("${CMAKE_SYSTEM_VERSION}" MATCHES "12")
126             set(SIMGRID_DEP "${SIMGRID_DEP} -lpgmath")
127         endif()
128       endif()
129     endif()
130   endif()
131
132 endif()
133
134 if(enable_smpi AND APPLE)
135   set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
136 endif()
137
138 # See https://github.com/HewlettPackard/foedus_code/blob/master/foedus-core/cmake/FindGccAtomic.cmake
139 FIND_LIBRARY(GCCLIBATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1
140   HINTS
141     $ENV{HOME}/local/lib64
142     $ENV{HOME}/local/lib
143     /usr/local/lib64
144     /usr/local/lib
145     /opt/local/lib64
146     /opt/local/lib
147     /usr/lib64
148     /usr/lib
149     /lib64
150     /lib
151 )
152
153 # Fix a FTBFS on armel, mips, mipsel and friends (Debian's #872881)
154 if(CMAKE_COMPILER_IS_GNUCC AND GCCLIBATOMIC_LIBRARY)
155     set(SIMGRID_DEP   "${SIMGRID_DEP}   -Wl,--as-needed -latomic -Wl,--no-as-needed")
156 endif()
157 mark_as_advanced(GCCLIBATOMIC_LIBRARY)
158
159 if(enable_model-checking AND (NOT LINKER_VERSION VERSION_LESS "2.30"))
160     set(SIMGRID_DEP   "${SIMGRID_DEP}   -Wl,-znoseparate-code")
161 endif()
162
163 target_link_libraries(simgrid   ${SIMGRID_DEP})
164
165 # Dependencies from maintainer mode
166 ###################################
167 if(enable_maintainer_mode)
168   add_dependencies(simgrid smpi_generated_headers_call_location_tracing)
169 endif()
170 if(enable_maintainer_mode AND PYTHON_EXE)
171   add_dependencies(simgrid simcalls_generated_src)
172 endif()
173 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
174   add_dependencies(simgrid automaton_generated_src)
175 endif()