Logo AND Algorithmique Numérique Distribuée

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