Logo AND Algorithmique Numérique Distribuée

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