CMakeLists.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #
  2. # #%~
  3. # The Overture Abstract Syntax Tree
  4. # %%
  5. # Copyright (C) 2017 - 2014 Aarhus University
  6. # %%
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public
  18. # License along with this program. If not, see
  19. # <http://www.gnu.org/licenses/gpl-3.0.html>.
  20. # #~%
  21. #
  22. cmake_minimum_required (VERSION 3.5.2)
  23. # this (3.5.2) is the first version where External Project uses --recursive
  24. project (Controller C CXX)
  25. # HOW to
  26. #
  27. # cmake -DCMAKE_TOOLCHAIN_FILE=msys-toolchain.cmake -DCMAKE_BUILD_TYPE=Debug .
  28. # make
  29. #
  30. # to list dependencies use:
  31. # objdump -p binaries/win64/window-sa.dll | grep 'DLL Name:'
  32. #
  33. include_directories(fmi2)
  34. if (WIN32)
  35. #windows, becuase windows just cannot figure out to do it correct.
  36. # must be a bug in msys mingw gcc 6.3
  37. # it doesnt read the rsp files.
  38. set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 0)
  39. set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 0)
  40. set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
  41. set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
  42. endif()
  43. include(CheckCXXCompilerFlag)
  44. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  45. CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
  46. if(COMPILER_SUPPORTS_CXX11)
  47. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  48. elseif(COMPILER_SUPPORTS_CXX0X)
  49. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  50. else()
  51. message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  52. endif()
  53. file(GLOB C_FILES sources/*.c)
  54. ## library ##
  55. #determine the library path
  56. set(FMI_BIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/binaries")
  57. if(WIN32 OR MINGW)
  58. set(FMI_BIN_DIR "${FMI_BIN_DIR}/win")
  59. # not sure why this doesnt work on MSYS so we just reset it
  60. SET (CMAKE_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
  61. endif()
  62. if(APPLE)
  63. set(FMI_BIN_DIR "${FMI_BIN_DIR}/darwin")
  64. endif()
  65. if(UNIX AND NOT APPLE)
  66. # for Linux, BSD, Solaris, Minix
  67. set(FMI_BIN_DIR "${FMI_BIN_DIR}/linux")
  68. endif()
  69. if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
  70. set(FMI_BIN_DIR "${FMI_BIN_DIR}64")
  71. else ()
  72. set(FMI_BIN_DIR "${FMI_BIN_DIR}32")
  73. endif ()
  74. message("FMI output is ${FMI_BIN_DIR}")
  75. file(MAKE_DIRECTORY ${FMI_BIN_DIR})
  76. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
  77. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${FMI_BIN_DIR})
  78. add_library(${PROJECT_NAME} SHARED ${C_FILES})
  79. set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
  80. SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
  81. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
  82. # I need this: -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic
  83. if (WIN32)
  84. #windows
  85. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
  86. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic")
  87. endif()
  88. add_custom_target(pack COMMAND
  89. ${CMAKE_COMMAND} -E tar "cfv" ${PROJECT_NAME}.fmu --format=zip
  90. "${CMAKE_CURRENT_SOURCE_DIR}/modelDescription.xml"
  91. "${FMI_BIN_DIR}"
  92. )