Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b0b8837cf0230182a8b823cfb04dc9a05d28a5d0
[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_FULL_LIBDIR}")
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("${CMAKE_SYSTEM}" MATCHES "Linux")
30   add_library(sthread SHARED ${STHREAD_SRC})
31   set_property(TARGET sthread
32                 APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
33   target_link_libraries(sthread simgrid)
34 else()
35   set(EXTRA_DIST ${EXTRA_DIST} ${STHREAD_SRC})
36 endif()
37
38 if(enable_model-checking)
39   add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC})
40   target_link_libraries(simgrid-mc simgrid)
41   set_target_properties(simgrid-mc
42                         PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
43   set_property(TARGET simgrid-mc
44                APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
45   install(TARGETS simgrid-mc # install that binary without breaking the rpath on Mac
46     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/)
47   add_dependencies(tests-mc simgrid-mc)
48   if("${CMAKE_SYSTEM}" MATCHES "Linux")
49     add_dependencies(tests-mc sthread)
50   endif()
51 endif()
52
53 # Compute the dependencies of SimGrid
54 #####################################
55 # search for dlopen
56 if("${CMAKE_SYSTEM_NAME}" MATCHES "kFreeBSD|Linux|SunOS")
57   find_library(DL_LIBRARY dl)
58 endif()
59 mark_as_advanced(DL_LIBRARY)
60
61 if (HAVE_BOOST_CONTEXTS)
62   target_link_libraries(simgrid ${Boost_CONTEXT_LIBRARY})
63 endif()
64
65 if (HAVE_BOOST_STACKTRACE_BACKTRACE)
66   target_link_libraries(simgrid ${Boost_STACKTRACE_BACKTRACE_LIBRARY})
67 endif()
68
69 if (HAVE_BOOST_ADDR2LINE_BACKTRACE)
70   target_link_libraries(simgrid ${Boost_STACKTRACE_ADDR2LINE_LIBRARY})
71 endif()
72
73 if(CMAKE_USE_PTHREADS_INIT)
74   target_link_libraries(simgrid ${CMAKE_THREAD_LIBS_INIT})
75 endif()
76
77 if(HAVE_PAPI)
78   SET(SIMGRID_DEP "${SIMGRID_DEP} -lpapi")
79 endif()
80
81 if(HAVE_GRAPHVIZ)
82   if(HAVE_CGRAPH_LIB)
83     SET(SIMGRID_DEP "${SIMGRID_DEP} -lcgraph")
84   else()
85     if(HAVE_AGRAPH_LIB)
86       SET(SIMGRID_DEP "${SIMGRID_DEP} -lagraph -lcdt")
87     endif()
88   endif()
89 endif()
90
91 if(NOT ${DL_LIBRARY} STREQUAL "")
92   SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
93 endif()
94
95 if(HAVE_POSIX_GETTIME)
96   SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt")
97 endif()
98
99 if("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
100   set(SIMGRID_DEP "${SIMGRID_DEP} -lprocstat")
101 endif()
102
103 # Compute the dependencies of SMPI
104 ##################################
105
106 if(enable_smpi)
107   add_executable(smpimain src/smpi/smpi_main.c)
108   target_link_libraries(smpimain simgrid)
109   set_target_properties(smpimain
110     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
111   install(TARGETS smpimain # install that binary without breaking the rpath on Mac
112     RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/simgrid)
113   add_dependencies(tests smpimain)
114
115   add_executable(smpireplaymain src/smpi/smpi_replay_main.cpp)
116   target_compile_options(smpireplaymain PRIVATE -fpic)
117   target_link_libraries(smpireplaymain simgrid -fpic -shared)
118   set_target_properties(smpireplaymain
119     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/simgrid)
120   install(TARGETS smpireplaymain # install that binary without breaking the rpath on Mac
121     RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/simgrid)
122   add_dependencies(tests smpireplaymain)
123
124   if(SMPI_FORTRAN)
125     if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
126       SET(SIMGRID_DEP "${SIMGRID_DEP} -lgfortran")
127     elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
128       SET(SIMGRID_DEP "${SIMGRID_DEP} -lifcore")
129     elseif(CMAKE_Fortran_COMPILER_ID MATCHES "PGI|Flang")
130       SET(SIMGRID_DEP "${SIMGRID_DEP} -lflang")
131       if("${CMAKE_SYSTEM}" MATCHES "FreeBSD")
132         set(SIMGRID_DEP "${SIMGRID_DEP} -lexecinfo")
133         if ("${CMAKE_SYSTEM_VERSION}" STRGREATER_EQUAL "12")
134             set(SIMGRID_DEP "${SIMGRID_DEP} -lpgmath")
135         endif()
136         if ("${CMAKE_SYSTEM_VERSION}" MATCHES "12\.1")
137             set(SIMGRID_DEP "${SIMGRID_DEP} -lomp")
138         endif()
139       endif()
140     endif()
141   endif()
142
143 endif()
144
145 if(enable_smpi AND APPLE)
146   set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main")
147 endif()
148
149 # See https://github.com/HewlettPackard/foedus_code/blob/master/foedus-core/cmake/FindGccAtomic.cmake
150 FIND_LIBRARY(GCCLIBATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1
151   HINTS
152     $ENV{HOME}/local/lib64
153     $ENV{HOME}/local/lib
154     /usr/local/lib64
155     /usr/local/lib
156     /opt/local/lib64
157     /opt/local/lib
158     /usr/lib64
159     /usr/lib
160     /lib64
161     /lib
162 )
163
164 # Fix a FTBFS on armel, mips, mipsel and friends (Debian's #872881)
165 if(CMAKE_COMPILER_IS_GNUCC AND GCCLIBATOMIC_LIBRARY)
166     set(SIMGRID_DEP   "${SIMGRID_DEP}   -Wl,--as-needed -latomic -Wl,--no-as-needed")
167 endif()
168 mark_as_advanced(GCCLIBATOMIC_LIBRARY)
169
170 if(enable_model-checking AND (NOT LINKER_VERSION VERSION_LESS "2.30"))
171     set(SIMGRID_DEP   "${SIMGRID_DEP}   -Wl,-znorelro -Wl,-znoseparate-code")
172 endif()
173
174 target_link_libraries(simgrid   ${SIMGRID_DEP})
175
176 # Dependencies from maintainer mode
177 ###################################
178 if(enable_maintainer_mode)
179   add_dependencies(simgrid smpi_generated_headers_call_location_tracing)
180 endif()
181 if(enable_maintainer_mode AND BISON_EXE AND LEX_EXE)
182   add_dependencies(simgrid automaton_generated_src)
183 endif()