forked from febiosoftware/FEBioHeat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
177 lines (143 loc) · 5.92 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
cmake_minimum_required(VERSION 3.1.0)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(FEBioHeat)
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()
#cmake_path(CONVERT ${OLD_SDK} TO_CMAKE_PATH_LIST STD_OLD_SDK)
#cmake_path(CONVERT ${FEBio_SDK} TO_CMAKE_PATH_LIST STD_FEBIO_SDK)
#string(COMPARE NOTEQUAL ${STD_FEBIO_SDK} ${STD_OLD_SDK} NEWPATH)
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")
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 libName libDir libOut)
string(TOLOWER ${libName} lname)
find_library(TEMP
NAMES ${libName} ${lname} ${lname}_gcc64 ${lname}_lnx64
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 ${libName}.")
elseif(APPLE)
message(SEND_ERROR "Could not find ${libName}.so, ${libName}.a, or ${libName}.dylib Check ${libDir}.")
else()
message(SEND_ERROR "Could not find ${libName}.so, or ${libName}.a. Check ${libDir}")
endif()
unset(TEMP CACHE)
endif()
endfunction()
if(FEBio_LIB_DIR)
findLib(FECore FEBio_LIB_DIR FECORE)
findLib(FEBioMech FEBio_LIB_DIR FEBIOMECH)
endif()
##### 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)
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_FEBioHeat "FEBioHeat/*.h")
file(GLOB SRC_FEBioHeat "FEBioHeat/*.cpp")
add_library(FEBioHeat SHARED ${HDR_FEBioHeat} ${SRC_FEBioHeat})
set_property(TARGET FEBioHeat PROPERTY AUTOGEN_BUILD_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/AutoGen/FEBioHeat_autogen)
##### Link Libraries #####
target_link_libraries(FEBioHeat ${FECORE})