-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
187 lines (150 loc) · 6.4 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
cmake_minimum_required(VERSION 3.1.0)
#Edit these fields for your own Plugin
######################################
# Set your plugin name
set(PLUGIN_NAME FENeoHookean)
# List the names of the FEBio libraries that you need to link to
# e.g. set(FEBio_LIB_NAMES fecore febiolib febiomech xml febioplot febiofluid febiomix)
set(FEBio_LIB_NAMES fecore)
# Place this CMakeLists.txt file in the directory containing your source and header
# files. It will automatically include all *.h files in this directory, and compile
# all *.cpp files in this directory.
######################################
project(${PLUGIN_NAME})
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_FILES_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Set a default build type if none was specified
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Find FEBio SDK or git repo automatically
if(WIN32)
set(TEMP_PATHS ${CMAKE_SOURCE_DIR}/.. ${CMAKE_SOURCE_DIR}/../.. $ENV{HOMEPATH}/ $ENV{HOMEPATH}/source/repos $ENV{HOMEPATH}/*)
else()
set(TEMP_PATHS ${CMAKE_SOURCE_DIR}/.. ${CMAKE_SOURCE_DIR}/../.. $ENV{HOME}/ $ENV{HOME}/*)
endif()
find_path(FEBio_SDK FECore/Archive.h
PATHS ${TEMP_PATHS}
PATH_SUFFIXES FEBio
DOC "Path to the FEBio SDK, or git repo.")
if(NOT FEBio_SDK)
if(WIN32)
set(TEMP_PATHS $ENV{PROGRAMFILES}/* $ENV{HOMEPATH}/*)
elseif(APPLE)
set(TEMP_PATHS /Applications/* $ENV{HOME}/*)
else()
set(TEMP_PATHS $ENV{HOME}/*)
endif()
find_path(FEBio_SDK "include/FECore/Archive.h"
PATHS ${TEMP_PATHS}
PATH_SUFFIXES sdk
DOC "Path to the FEBio SDK, or git repo.")
endif()
if(NOT FEBio_SDK)
set(FEBio_SDK "" CACHE PATH "Path to the FEBio SDK, or git repo.")
message(FATAL_ERROR "Unable to find path to FEBio SDK or git repo automatically. Please set FEBio_SDK to the path to your FEBio SDK or git repo.")
endif()
# Only update the include and lib directories if the FEBio_SDK path has been changed.
if(NOT OLD_SDK)
set(NEWPATH TRUE)
else()
string(COMPARE NOTEQUAL ${FEBio_SDK} ${OLD_SDK} NEWPATH)
endif()
if(NEWPATH)
# Is this the SDK?
string(REGEX MATCH "sdk" IS_SDK ${FEBio_SDK})
set(LIB_SUFFIXES "")
if(IS_SDK)
set(FEBio_INC "${FEBio_SDK}/include" CACHE PATH "Path to FEBio include directory." FORCE)
if(WIN32)
list(APPEND LIB_SUFFIXES "vs2017/Release" "vs2017/Debug" "lib")
else()
list(APPEND LIB_SUFFIXES "lib")
endif()
else()
set(FEBio_INC ${FEBio_SDK} CACHE PATH "Path to FEBio include directory." FORCE)
if(WIN32)
list(APPEND LIB_SUFFIXES "cmbuild22/lib/Release" "cmbuild/lib/Release" "cmbuild/lib/Debug" "cbuild/lib/Release" "cbuild/lib/Debug" "build/lib/Release" "build/lib/Debug")
else()
list(APPEND LIB_SUFFIXES "cbuild/lib" "cmbuild/lib" "build/lib" "cbuild/Release/lib" "cmbuild/Release/lib" "build/Release/lib" "cbuild/Debug/lib" "cmbuild/Debug/lib" "build/Debug/lib")
endif()
endif()
mark_as_advanced(FEBio_INC)
# Find lib path
find_library(FECORE
NAMES FECore fecore fecore_gcc64 fecore_lnx64
PATHS ${FEBio_SDK}
PATH_SUFFIXES ${LIB_SUFFIXES}
DOC "FEBio library path")
if(FECORE)
get_filename_component(FECORE_TEMP ${FECORE} DIRECTORY)
set(FEBio_LIB_DIR ${FECORE_TEMP} CACHE PATH "Path to the FEBio lib directory." FORCE)
mark_as_advanced(FEBio_LIB_DIR)
unset(FECORE_TEMP)
unset(FECORE CACHE)
else()
set(FEBio_LIB_DIR CACHE PATH "Path to the FEBio lib directory." FORCE)
message(SEND_ERROR "Unable to find FEBio Library path automatically. Set FEBio_LIB_DIR.")
unset(FECORE CACHE)
endif()
endif()
set(OLD_SDK ${FEBio_SDK} CACHE PATH "Don't edit. Old SDK path used to automatically make changes." FORCE)
mark_as_advanced(OLD_SDK)
#### Check if paths are valid and find libs ####
function(findLib libDir libOut libName)
# Optional arguments ARGV3-ARVG6 can be used as alernative names for the library
find_library(TEMP NAMES ${libName} ${ARGV3} ${ARGV4} ${ARGV5} ${ARGV6}
PATHS ${${libDir}} NO_DEFAULT_PATH)
if(TEMP)
set(${libOut} ${TEMP} PARENT_SCOPE)
unset(TEMP CACHE)
else()
if(WIN32)
message(SEND_ERROR "Could not find ${libName}.lib. Check ${libDir}.")
elseif(APPLE)
message(SEND_ERROR "Could not find lib${libName}.so, lib${libName}.a, or lib${libName}.dylib Check ${libDir}.")
else()
message(SEND_ERROR "Could not find lib${libName}.so, or lib${libName}.a. Check ${libDir}")
endif()
unset(TEMP CACHE)
endif()
endfunction()
foreach(name IN LISTS FEBio_LIB_NAMES)
findLib(FEBio_LIB_DIR FEBio_LIB ${name})
list(APPEND FEBio_LIBS ${FEBio_LIB})
unset(FEBio_LIB)
endforeach(name)
##### Set appropriate defines and includes #####
if(WIN32)
add_definitions(-DWIN32 -DFECORE_DLL /MP /openmp)
elseif(APPLE)
add_definitions(-D__APPLE__)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
else()
add_definitions(-DLINUX)
add_compile_options(-static-libstdc++ -static-libgcc -w -Wall -fPIC)
set(CMAKE_BUILD_RPATH_USE_LINK_PATH FALSE)
set(CMAKE_BUILD_RPATH $ORIGIN/../lib/)
endif()
# Extra compiler flags for intel compiler
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} -static-intel)
endif()
include_directories(${FEBio_INC})
##### Add library #####
file(GLOB HDR_${PLUGIN_NAME} "*.h")
file(GLOB SRC_${PLUGIN_NAME} "*.cpp")
add_library(${PLUGIN_NAME} SHARED ${HDR_${PLUGIN_NAME}} ${SRC_${PLUGIN_NAME}})
set_property(TARGET ${PLUGIN_NAME} PROPERTY AUTOGEN_BUILD_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/AutoGen/${PLUGIN_NAME}_autogen)
##### Link Libraries #####
target_link_libraries(${PLUGIN_NAME} ${FEBio_LIBS})