Logo AND Algorithmique Numérique Distribuée

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