Logo AND Algorithmique Numérique Distribuée

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