CMakeListsGenerator.xtend 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package be.uantwerpen.ansymo.semanticadaptation.testframework
  2. class CMakeListsGenerator {
  3. def static String generateToolChainCmake() {
  4. '''
  5. # the name of the target operating system
  6. SET(CMAKE_SYSTEM_NAME Windows)
  7. SET(WIN32 true)
  8. # which compilers to use for C and C++
  9. SET(CMAKE_C_COMPILER /mingw64/bin/gcc)
  10. SET(CMAKE_CXX_COMPILER /mingw64/bin/g++)
  11. #SET(CMAKE_RC_COMPILER i486-mingw32-windres)
  12. # here is the target environment located
  13. #SET(CMAKE_FIND_ROOT_PATH /usr/i486-mingw32)
  14. # adjust the default behaviour of the FIND_XXX() commands:
  15. # search headers and libraries in the target environment, search
  16. # programs in the host environment
  17. #set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  18. #set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  19. #set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  20. '''
  21. }
  22. def static String addHcf() {
  23. '''
  24. #
  25. # install hcf frameowrk
  26. #
  27. set(HCF_DIR hcf)
  28. if(EXISTS ${HCF_DIR})
  29. execute_process(COMMAND git pull WORKING_DIRECTORY ${HCF_DIR})
  30. execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY ${HCF_DIR})
  31. else()
  32. execute_process(COMMAND git clone --depth 1 git@github.com:into-cps/hybridCosimulation-framework.git ${HCF_DIR} )
  33. execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY ${HCF_DIR})
  34. endif()
  35. add_subdirectory(${HCF_DIR}/semantic-adaptation)
  36. #
  37. #
  38. #
  39. '''
  40. }
  41. def static String generateCMakeListsHcfDummy() {
  42. '''
  43. #
  44. # #%~
  45. # The Overture Abstract Syntax Tree
  46. # %%
  47. # Copyright (C) 2017 - 2014 Aarhus University
  48. # %%
  49. # This program is free software: you can redistribute it and/or modify
  50. # it under the terms of the GNU General Public License as
  51. # published by the Free Software Foundation, either version 3 of the
  52. # License, or (at your option) any later version.
  53. #
  54. # This program is distributed in the hope that it will be useful,
  55. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  56. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  57. # GNU General Public License for more details.
  58. #
  59. # You should have received a copy of the GNU General Public
  60. # License along with this program. If not, see
  61. # <http://www.gnu.org/licenses/gpl-3.0.html>.
  62. # #~%
  63. #
  64. cmake_minimum_required (VERSION 3.5.2)
  65. # this (3.5.2) is the first version where External Project uses --recursive
  66. project (dummy C CXX)
  67. # HOW to
  68. #
  69. # cmake -DCMAKE_TOOLCHAIN_FILE=msys-toolchain.cmake -DCMAKE_BUILD_TYPE=Debug .
  70. # make
  71. #
  72. # to list dependencies use:
  73. # objdump -p binaries/win64/window-sa.dll | grep 'DLL Name:'
  74. #
  75. if (WIN32)
  76. #windows, becuase windows just cannot figure out to do it correct.
  77. # must be a bug in msys mingw gcc 6.3
  78. # it doesnt read the rsp files.
  79. set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 0)
  80. set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 0)
  81. set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
  82. set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
  83. endif()
  84. «addHcf»
  85. include(CheckCXXCompilerFlag)
  86. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  87. CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
  88. if(COMPILER_SUPPORTS_CXX11)
  89. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  90. elseif(COMPILER_SUPPORTS_CXX0X)
  91. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  92. else()
  93. message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  94. endif()
  95. '''
  96. }
  97. def static String generateCMakeLists(String projectName) {
  98. '''
  99. #
  100. # #%~
  101. # The Overture Abstract Syntax Tree
  102. # %%
  103. # Copyright (C) 2017 - 2014 Aarhus University
  104. # %%
  105. # This program is free software: you can redistribute it and/or modify
  106. # it under the terms of the GNU General Public License as
  107. # published by the Free Software Foundation, either version 3 of the
  108. # License, or (at your option) any later version.
  109. #
  110. # This program is distributed in the hope that it will be useful,
  111. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  112. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  113. # GNU General Public License for more details.
  114. #
  115. # You should have received a copy of the GNU General Public
  116. # License along with this program. If not, see
  117. # <http://www.gnu.org/licenses/gpl-3.0.html>.
  118. # #~%
  119. #
  120. cmake_minimum_required (VERSION 3.5.2)
  121. # this (3.5.2) is the first version where External Project uses --recursive
  122. project («projectName» C CXX)
  123. # HOW to
  124. #
  125. # cmake -DCMAKE_TOOLCHAIN_FILE=msys-toolchain.cmake -DCMAKE_BUILD_TYPE=Debug .
  126. # make
  127. #
  128. # to list dependencies use:
  129. # objdump -p binaries/win64/window-sa.dll | grep 'DLL Name:'
  130. #
  131. if (WIN32)
  132. #windows, becuase windows just cannot figure out to do it correct.
  133. # must be a bug in msys mingw gcc 6.3
  134. # it doesnt read the rsp files.
  135. set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 0)
  136. set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 0)
  137. set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
  138. set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
  139. endif()
  140. «addHcf»
  141. include(CheckCXXCompilerFlag)
  142. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  143. CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
  144. if(COMPILER_SUPPORTS_CXX11)
  145. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  146. elseif(COMPILER_SUPPORTS_CXX0X)
  147. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  148. else()
  149. message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  150. endif()
  151. add_definitions(-DFMI_COSIMULATION)
  152. file(GLOB CPP_FILES sources/*.cpp)
  153. file(GLOB CPP_MAIN_FILES sources/main*.cpp)
  154. list(REMOVE_ITEM CPP_FILES ${CPP_MAIN_FILES})
  155. ## library ##
  156. #determine the library path
  157. set(FMI_BIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/binaries")
  158. if(WIN32 OR MINGW)
  159. set(FMI_BIN_DIR "${FMI_BIN_DIR}/win")
  160. # not sure why this doesnt work on MSYS so we just reset it
  161. SET (CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
  162. endif()
  163. if(APPLE)
  164. set(FMI_BIN_DIR "${FMI_BIN_DIR}/darwin")
  165. endif()
  166. if(UNIX AND NOT APPLE)
  167. # for Linux, BSD, Solaris, Minix
  168. set(FMI_BIN_DIR "${FMI_BIN_DIR}/linux")
  169. endif()
  170. if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
  171. set(FMI_BIN_DIR "${FMI_BIN_DIR}64")
  172. else ()
  173. set(FMI_BIN_DIR "${FMI_BIN_DIR}32")
  174. endif ()
  175. message("FMI output is ${FMI_BIN_DIR}")
  176. #SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
  177. file(MAKE_DIRECTORY ${FMI_BIN_DIR})
  178. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
  179. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
  180. #set(CMAKE_LIBRARY_OUTPUT_DIRECTORY bb)
  181. #set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
  182. add_library(${PROJECT_NAME} SHARED ${CPP_FILES})
  183. target_link_libraries(${PROJECT_NAME} PUBLIC hcf)
  184. set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
  185. SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
  186. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
  187. ## Main executable ##
  188. add_executable(${PROJECT_NAME}_main ${CPP_MAIN_FILES} ${CPP_FILES})
  189. target_link_libraries(${PROJECT_NAME}_main PUBLIC hcf)
  190. # I need this: -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic
  191. if (WIN32)
  192. #windows
  193. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
  194. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
  195. endif()
  196. '''
  197. }
  198. }