-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
152 lines (118 loc) · 6.17 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
cmake_minimum_required(VERSION 3.01)
project(libpolymake_julia)
find_package(JlCxx REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
SET(POLYMAKE_MIN_VERSION "4.0")
find_package(Polymake REQUIRED ${POLYMAKE_MIN_VERSION})
include(CheckCXXCompilerFlag)
include(GNUInstallDirs)
# override c++ compat, the interface doesn't really need c++20 and
# the c++ library in some sys-roots doesn't support full c++20
set_target_properties(JlCxx::cxxwrap_julia PROPERTIES INTERFACE_COMPILE_FEATURES "")
set(CMAKE_CXX_STANDARD 17)
SET( CMAKE_CXX_COMPILER "${Polymake_CXX}")
# this is to allow filtering of the -fopenmp flag when building natively
# on macos (only the cross-compiler for macos in BB supports -fopenmp)
if(POLYMAKE_DISABLE_OPENMP)
string(REPLACE "-fopenmp" "" Polymake_CFLAGS ${Polymake_CFLAGS})
string(REPLACE "-fopenmp" "" Polymake_LDFLAGS ${Polymake_LDFLAGS})
endif()
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ${Polymake_CFLAGS}" )
SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${Polymake_LDFLAGS}" )
SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Polymake_LDFLAGS}" )
# this works around a design issue in polymake where the corresponding symbol is
# defined in a bundled extension and thus not available at link-time
# this can be removed once flint is a core-dependency of polymake
if(APPLE)
SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-U,__ZN2pm18QuadraticExtensionINS_8RationalEE9normalizeEv" )
else()
SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--undefined,__ZN2pm18QuadraticExtensionINS_8RationalEE9normalizeEv" )
endif()
# to avoid lib64 dirs as binarybuilder uses lib everywhere
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_INSTALL_LIBDIR "lib")
# avoid gcc 9 internal compiler error,
# see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90998
if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.3)
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-conversion" )
endif()
if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
message( FATAL_ERROR "gcc version must be at least 7 to build the polymake CxxWrap interface." )
endif()
set(TYPE_GENERATOR ${CMAKE_CURRENT_SOURCE_DIR}/src/polymake/type_setup.pl)
set(GENERATOR_STAGING_DIR ${CMAKE_CURRENT_BINARY_DIR}/tmp/)
set(GENERATOR_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(GENERATOR_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${TYPE_GENERATOR})
file(REMOVE_RECURSE ${GENERATOR_STAGING_DIR})
file(MAKE_DIRECTORY ${GENERATOR_STAGING_DIR})
execute_process(COMMAND perl ${CMAKE_CURRENT_SOURCE_DIR}/src/polymake/type_setup.pl ${GENERATOR_STAGING_DIR} COMMAND_ERROR_IS_FATAL ANY)
file(MAKE_DIRECTORY ${GENERATOR_OUTPUT_DIR}/src)
file(MAKE_DIRECTORY ${GENERATOR_OUTPUT_DIR}/jl)
file(MAKE_DIRECTORY ${GENERATOR_OUTPUT_DIR}/include/jlpolymake/generated)
# Remove stale files from final generator output directory
file(GLOB_RECURSE CURR_GENERATED_FILES RELATIVE "${GENERATOR_OUTPUT_DIR}/"
"${GENERATOR_OUTPUT_DIR}/src/*"
"${GENERATOR_OUTPUT_DIR}/jl/*"
"${GENERATOR_OUTPUT_DIR}/include/jlpolymake/generated/*")
foreach(FILE ${CURR_GENERATED_FILES})
if(NOT EXISTS "${GENERATOR_STAGING_DIR}/${FILE}")
file(REMOVE "${GENERATOR_OUTPUT_DIR}/${FILE}")
endif()
endforeach()
## Copy modified files from staging to final generator output directory
file(GLOB_RECURSE GENERATED_FILES RELATIVE "${GENERATOR_STAGING_DIR}/"
"${GENERATOR_STAGING_DIR}/src/*"
"${GENERATOR_STAGING_DIR}/jl/*"
"${GENERATOR_STAGING_DIR}/include/jlpolymake/generated/*")
foreach(FILE ${GENERATED_FILES})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${GENERATOR_STAGING_DIR}/${FILE}" "${GENERATOR_OUTPUT_DIR}/${FILE}" COMMAND_ERROR_IS_FATAL ANY)
endforeach()
set(JLPOLYMAKE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(JLPOLYMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(JLPOLYMAKE_GENERATED ${CMAKE_CURRENT_BINARY_DIR}/include)
file(GLOB GENERATED_CPP
${CMAKE_CURRENT_BINARY_DIR}/src/unbox_pv*.cpp
${CMAKE_CURRENT_BINARY_DIR}/src/wrap_types*.cpp
)
set(JLPOLYMAKE_TARGET polymake_julia)
include_directories(${JlCxx_DIR}/../../../include/)
set(GENERATED_HEADERS
${JLPOLYMAKE_GENERATED}/jlpolymake/generated/get_type_names.h
${JLPOLYMAKE_GENERATED}/jlpolymake/generated/map_inserts.h
${JLPOLYMAKE_GENERATED}/jlpolymake/generated/option_set_take.h
${JLPOLYMAKE_GENERATED}/jlpolymake/generated/call_function_feed_argument.h
${JLPOLYMAKE_GENERATED}/jlpolymake/generated/type_declarations_extern.h
${JLPOLYMAKE_GENERATED}/jlpolymake/generated/type_declarations.h
)
file(GLOB JLPOLYMAKE_HEADERS "${JLPOLYMAKE_INCLUDE_DIR}/jlpolymake/*.h")
file(GLOB JLPOLYMAKE_SRC "${JLPOLYMAKE_SOURCE_DIR}/*.cpp")
add_library(${JLPOLYMAKE_TARGET} SHARED ${JLPOLYMAKE_SRC} ${GENERATED_CPP})
target_link_libraries(${JLPOLYMAKE_TARGET} JlCxx::cxxwrap_julia "${Polymake_LIBS}" "${EXTRA_LIBRARIES}")
set(TYPE_TRANSLATOR ${CMAKE_CURRENT_BINARY_DIR}/jl/type_translator.jl)
set(GEN_DEPS_TREE ${CMAKE_CURRENT_SOURCE_DIR}/src/polymake/generate_deps_tree.jl)
set_target_properties(${JLPOLYMAKE_TARGET} PROPERTIES
PUBLIC_HEADER "${JLPOLYMAKE_HEADERS}")
add_custom_target(generated_files ALL DEPENDS ${GENERATED_HEADERS} ${GENERATED_CPP})
add_dependencies(${JLPOLYMAKE_TARGET} generated_files)
target_include_directories(${JLPOLYMAKE_TARGET} PUBLIC
JLCxx::cxxwrap_julia
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${JLPOLYMAKE_INCLUDE_DIR}>
$<BUILD_INTERFACE:${JLPOLYMAKE_GENERATED}>
"$<BUILD_INTERFACE:${Polymake_INCLUDE_DIRS}>"
)
install(TARGETS
${JLPOLYMAKE_TARGET}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/jlpolymake
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/jlpolymake)
install(FILES ${TYPE_TRANSLATOR} ${GEN_DEPS_TREE}
DESTINATION ${CMAKE_INSTALL_DATADIR}/libpolymake_julia
)
install(FILES ${GENERATED_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/jlpolymake/generated/
COMPONENT Headers)