|
| 1 | +#[[++ |
| 2 | + |
| 3 | +Copyright (C) 2020 Autodesk Inc. |
| 4 | + |
| 5 | +All rights reserved. |
| 6 | + |
| 7 | +Redistribution and use in source and binary forms, with or without |
| 8 | +modification, are permitted provided that the following conditions are met: |
| 9 | + * Redistributions of source code must retain the above copyright |
| 10 | + notice, this list of conditions and the following disclaimer. |
| 11 | + * Redistributions in binary form must reproduce the above copyright |
| 12 | + notice, this list of conditions and the following disclaimer in the |
| 13 | + documentation and/or other materials provided with the distribution. |
| 14 | + * Neither the name of the Autodesk Inc. nor the |
| 15 | + names of its contributors may be used to endorse or promote products |
| 16 | + derived from this software without specific prior written permission. |
| 17 | + |
| 18 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 19 | +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | +DISCLAIMED. IN NO EVENT SHALL AUTODESK INC. BE LIABLE FOR ANY |
| 22 | +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 | +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 | +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 | +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + |
| 29 | +]] |
| 30 | + |
| 31 | + |
| 32 | +cmake_minimum_required(VERSION 3.5) |
| 33 | + |
| 34 | +########################################################################################## |
| 35 | +### generic CMake boilerplate code |
| 36 | +########################################################################################## |
| 37 | + |
| 38 | +project(LibMCDriver_${DRIVERPROJECT}) |
| 39 | + |
| 40 | +string(TOLOWER ${DRIVERPROJECT} DRIVERSUFFIX) |
| 41 | +string(TOUPPER ${DRIVERPROJECT} DRIVERSUFFIX_UPPER) |
| 42 | + |
| 43 | +set (DRIVERNAME libmcdriver_${DRIVERSUFFIX}) |
| 44 | + |
| 45 | +set (EXPORTFLAG __LIBMCDRIVER_${DRIVERSUFFIX_UPPER}_EXPORTS) |
| 46 | + |
| 47 | +set (CMAKE_CXX_STANDARD 11) |
| 48 | + |
| 49 | +# The location of autogenerated interfaces |
| 50 | +set(CMAKE_CURRENT_HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../Framework/HeadersDev/CppDynamic) |
| 51 | +set(CMAKE_CURRENT_AUTOGENERATED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../Framework/InterfacesDev) |
| 52 | +set(CMAKE_CURRENT_OUTPUT_DIR ${PROJECT_BINARY_DIR}/../../Output) |
| 53 | + |
| 54 | +file(STRINGS ${PROJECT_BINARY_DIR}/../../githash.txt GLOBALGITHASH) |
| 55 | +message(STATUS "Global git hash: \"${GLOBALGITHASH}\"") |
| 56 | + |
| 57 | + |
| 58 | +file(GLOB LIBMCDRIVER_SRC |
| 59 | + ${CMAKE_CURRENT_SOURCE_DIR}/Interfaces/*.cpp |
| 60 | + ${CMAKE_CURRENT_SOURCE_DIR}/Implementation/*.cpp |
| 61 | + ${CMAKE_CURRENT_SOURCE_DIR}/Implementation/serial/*.cc |
| 62 | +) |
| 63 | + |
| 64 | +add_library(${DRIVERNAME} SHARED ${LIBMCDRIVER_SRC}) |
| 65 | +# Do not prefix the binary's name with "lib" on Unix systems: |
| 66 | +set_target_properties(${DRIVERNAME} PROPERTIES PREFIX "" IMPORT_PREFIX "" ) |
| 67 | +# The following two properties are crucial to reduce the number of undesirably exported symbols |
| 68 | +set_target_properties(${DRIVERNAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) |
| 69 | +set_target_properties(${DRIVERNAME} PROPERTIES VISIBILITY_INLINES_HIDDEN ON) |
| 70 | +# This makes sure symbols are exported |
| 71 | +target_compile_options(${DRIVERNAME} PRIVATE "-D${EXPORTFLAG}") |
| 72 | +target_compile_options(${DRIVERNAME} PRIVATE "-D__LIBMCDRIVER_EXPORTS") |
| 73 | +target_include_directories(${DRIVERNAME} PRIVATE ${CMAKE_CURRENT_AUTOGENERATED_DIR}) |
| 74 | +target_include_directories(${DRIVERNAME} PRIVATE ${CMAKE_CURRENT_HEADER_DIR}) |
| 75 | +target_include_directories(${DRIVERNAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Implementation) |
| 76 | +target_include_directories(${DRIVERNAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Interfaces) |
| 77 | + |
| 78 | +set_target_properties(${DRIVERNAME} |
| 79 | + PROPERTIES |
| 80 | + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_OUTPUT_DIR}" |
| 81 | + RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_OUTPUT_DIR}" |
| 82 | + RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_OUTPUT_DIR}" |
| 83 | + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_OUTPUT_DIR}" |
| 84 | + VS_DEBUGGER_COMMAND "${CMAKE_CURRENT_OUTPUT_DIR}/amc_server.exe" |
| 85 | + VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_OUTPUT_DIR}" |
| 86 | + OUTPUT_NAME "${GLOBALGITHASH}_driver_${DRIVERSUFFIX}" |
| 87 | +) |
| 88 | + |
| 89 | + |
| 90 | +########################################################################################## |
| 91 | +### Copy driver header files |
| 92 | +########################################################################################## |
| 93 | + |
| 94 | +file (GLOB headerfiles LIST_DIRECTORIES false "${CMAKE_CURRENT_SOURCE_DIR}/Headers/CppDynamic/*.h*") |
| 95 | +foreach(headerfile ${headerfiles}) |
| 96 | + |
| 97 | + get_filename_component(headerfilename ${headerfile} NAME) |
| 98 | + |
| 99 | + add_custom_command( |
| 100 | + TARGET ${DRIVERNAME} POST_BUILD |
| 101 | + COMMAND ${CMAKE_COMMAND} -E echo "copying ${headerfile}...") |
| 102 | + |
| 103 | + add_custom_command( |
| 104 | + TARGET ${DRIVERNAME} POST_BUILD |
| 105 | + COMMAND ${CMAKE_COMMAND} -E copy |
| 106 | + ${headerfile} |
| 107 | + ${CMAKE_CURRENT_BINARY_DIR}/../../DevPackage/Framework/HeadersDriver/CppDynamic/${headerfilename}) |
| 108 | + |
| 109 | + add_custom_command( |
| 110 | + TARGET ${DRIVERNAME} POST_BUILD |
| 111 | + COMMAND ${CMAKE_COMMAND} -E copy |
| 112 | + ${headerfile} |
| 113 | + ${CMAKE_CURRENT_BINARY_DIR}/../../Framework/HeadersDriver/CppDynamic/${headerfilename}) |
| 114 | + |
| 115 | +endforeach() |
| 116 | + |
| 117 | +add_custom_command( |
| 118 | + TARGET ${DRIVERNAME} POST_BUILD |
| 119 | + COMMAND ${CMAKE_COMMAND} -E echo "building driver resources") |
| 120 | + |
| 121 | +if(WIN32) |
| 122 | +add_custom_command( |
| 123 | + TARGET ${DRIVERNAME} POST_BUILD |
| 124 | + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../../DevPackage/Framework/buildresources.exe |
| 125 | + ${CMAKE_CURRENT_SOURCE_DIR}/Resources |
| 126 | + ${PROJECT_BINARY_DIR}/../../Output/${GLOBALGITHASH}_driver_${DRIVERSUFFIX}.data) |
| 127 | +endif() |
| 128 | + |
| 129 | +if(UNIX) |
| 130 | +add_custom_command( |
| 131 | + TARGET ${DRIVERNAME} POST_BUILD |
| 132 | + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../../DevPackage/Framework/buildresources.linux |
| 133 | + ${CMAKE_CURRENT_SOURCE_DIR}/Resources |
| 134 | + ${PROJECT_BINARY_DIR}/../../Output/${GLOBALGITHASH}_driver_${DRIVERSUFFIX}.data) |
| 135 | +endif() |
| 136 | + |
| 137 | + |
| 138 | +########################################################################################## |
| 139 | +### Add custom code below |
| 140 | +########################################################################################## |
| 141 | + |
| 142 | + |
| 143 | + |
0 commit comments