Skip to content

Commit 857b364

Browse files
committedFeb 12, 2020
update config to make it work on conda or not
1 parent 3dfa8f7 commit 857b364

File tree

8 files changed

+74
-34
lines changed

8 files changed

+74
-34
lines changed
 

‎CMakeLists.txt

+9-5
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,18 @@ find_package(Qt5Core CONFIG REQUIRED)
5454
find_package(Qt5Concurrent CONFIG REQUIRED)
5555
find_package(PlantGL REQUIRED)
5656

57-
if (USE_CONDA)
58-
set(BOOST_ROOT ${CONDA_ENV})
59-
endif()
60-
6157
set(Boost_NO_SYSTEM_PATHS ON)
6258
set(Boost_USE_MULTITHREAD ON)
6359
set(Boost_USE_STATIC_LIBS OFF)
6460
set(BUILD_SHARED_LIBS ON)
6561

66-
find_package(Boost COMPONENTS system python REQUIRED)
62+
if (USE_CONDA)
63+
set(boost_python python)
64+
else()
65+
set(boost_python python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR})
66+
endif()
67+
68+
find_package(Boost COMPONENTS system ${boost_python} REQUIRED)
6769

6870
# --- Include Directories
6971

@@ -81,3 +83,5 @@ endif()
8183

8284
add_subdirectory("src/cpp")
8385
add_subdirectory("src/wrapper")
86+
87+
install_share("share" "lpy")

‎cmake/Anaconda.cmake

+27-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ if (DEFINED ENV{CONDA_PREFIX})
44
message(STATUS "Anaconda environment detected: " $ENV{CONDA_PREFIX})
55

66

7-
if (DEFINED ENV{BUILD_PREFIX})
8-
file(TO_CMAKE_PATH $ENV{BUILD_PREFIX} TMP_CONDA_ENV)
7+
if (DEFINED ENV{PREFIX})
8+
file(TO_CMAKE_PATH $ENV{PREFIX} TMP_CONDA_ENV)
99
else()
1010
file(TO_CMAKE_PATH $ENV{CONDA_PREFIX} TMP_CONDA_ENV)
1111
endif()
@@ -29,6 +29,10 @@ endif()
2929
if (DEFINED ENV{CONDA_BUILD})
3030
message(STATUS "Conda build detected. " $ENV{CONDA_BUILD})
3131

32+
if (WIN32)
33+
set(Python_ROOT_DIR "${PREFIX}")
34+
endif()
35+
3236
# specify the cross compiler
3337
set(CMAKE_C_COMPILER $ENV{CC})
3438
set(CMAKE_LINKER $ENV{LD})
@@ -37,9 +41,6 @@ if (DEFINED ENV{CONDA_BUILD})
3741
set(CMAKE_RANLIB $ENV{RANLIB})
3842
set(CMAKE_STRIP $ENV{STRIP})
3943
set(CMAKE_INSTALL_NAME_TOOL $ENV{INSTALL_NAME_TOOL})
40-
#CMAKE_MAKE_PROGRAM
41-
#CMAKE_OBJCOPY
42-
#CMAKE_OBJDUMP
4344

4445
if (APPLE)
4546
set(CMAKE_OSX_ARCHITECTURES $ENV{OSX_ARCH})
@@ -52,8 +53,10 @@ if (DEFINED ENV{CONDA_BUILD})
5253
# where is the target environment
5354
set(CMAKE_FIND_ROOT_PATH $ENV{PREFIX} $ENV{BUILD_PREFIX} $ENV{BUILD_PREFIX}/$ENV{HOST}/sysroot $ENV{CONDA_BUILD_SYSROOT})
5455

56+
message("CMAKE_FIND_ROOT_PATH :" ${CMAKE_FIND_ROOT_PATH})
57+
5558
# search for programs in the build host directories
56-
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
59+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
5760
# for libraries and headers in the target directories
5861
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
5962
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
@@ -64,5 +67,23 @@ else()
6467
set(USE_CONDA_BUILD OFF)
6568
endif()
6669

70+
function(pgl_default_install)
71+
if(USE_CONDA_BUILD)
72+
set(CMAKE_INSTALL_PREFIX $ENV{PREFIX} CACHE PATH "..." FORCE)
73+
elseif()
74+
set(CMAKE_INSTALL_PREFIX ${CONDA_ENV} CACHE PATH "..." FORCE)
75+
else()
76+
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/build-cmake CACHE PATH "..." FORCE)
77+
endif()
78+
message(STATUS "Default install prefix to " ${CMAKE_INSTALL_PREFIX})
79+
endfunction()
80+
81+
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
82+
pgl_default_install()
83+
elseif (NOT DEFINED CMAKE_INSTALL_PREFIX)
84+
pgl_default_install()
85+
else()
86+
message(STATUS "Install Prefix: " ${CMAKE_INSTALL_PREFIX})
87+
endif()
6788

6889

‎cmake/FindPlantGL.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if (NOT PLANTGL_LIBRARY_DIR)
5050

5151
if (PlantGL_FIND_REQUIRED)
5252
# PlantGL not found
53-
message(SEND_ERROR "Unable to find PlantGL libraries repository.")
53+
message(SEND_ERROR "Unable to find PlantGL libraries repository. Set PLANTGL_ROOT.")
5454
endif()
5555
endif()
5656

‎cmake/pywrapper.cmake

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ function(pgllib_link_python libwrapname)
1010
else()
1111
message(STATUS "Do not link with Python directly : " ${libwrapname})
1212
endif()
13+
endfunction()
1314

15+
function(pgllib_link_boost libwrapname)
1416
# Disable Boost Auto-Link
15-
#target_compile_definitions(${libwrapname} PRIVATE BOOST_ALL_NO_LIB)
17+
target_compile_definitions(${libwrapname} PRIVATE BOOST_ALL_NO_LIB)
1618

17-
#target_link_libraries(${libwrapname} Boost::system Boost::thread Boost::python )
19+
target_link_libraries(${libwrapname} Boost::system Boost::${boost_python} Boost::dynamic_linking Boost::disable_autolinking)
1820

1921
endfunction()
2022

21-
22-
2323
function(pglwrapper_install libwrapname)
2424
set_target_properties(${libwrapname} PROPERTIES PREFIX "")
2525

@@ -33,3 +33,7 @@ function(pglwrapper_install libwrapname)
3333

3434
install(TARGETS ${libwrapname} DESTINATION "${CMAKE_SOURCE_DIR}/src/openalea/lpy")
3535
endfunction()
36+
37+
function(install_share sharedirectory project)
38+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${sharedirectory}/ DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${project}")
39+
endfunction()

‎setup.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
#print (pkg_name+': version = '+version)
3737

3838

39-
# cmake build directory
40-
build_prefix = "build-cmake"
41-
4239
def compile_interface():
4340
cwd = os.getcwd()
4441
os.chdir(pj(lpydir,'gui'))
@@ -56,6 +53,25 @@ def compile_interface():
5653

5754
from setuptools import setup
5855

56+
57+
# Scons build directory
58+
build_prefix= "build-cmake"
59+
60+
if 'CONDA_PREFIX' in os.environ or 'PREFIX' in os.environ :
61+
deploy_args = {}
62+
else:
63+
currentdir = os.path.dirname(__file__)
64+
deploy_args = dict(
65+
# Specific options of openalea.deploy
66+
lib_dirs = {'lib' : pj(currentdir, build_prefix, 'lib'),},
67+
bin_dirs = {'bin': pj(currentdir, build_prefix, 'bin'),},
68+
inc_dirs = { 'include' : pj(currentdir, build_prefix, 'include') },
69+
share_dirs = { 'share' : 'share'},
70+
postinstall_scripts = ['pgl_postinstall',],
71+
namespace_packages = [namespace],
72+
create_namespaces = False,
73+
)
74+
5975
setup(
6076
name=name,
6177
version=version,
@@ -66,9 +82,6 @@ def compile_interface():
6682
url=url,
6783
license=license,
6884

69-
namespace_packages = [namespace],
70-
create_namespaces = False,
71-
7285
# pure python packages
7386
packages = [
7487
namespace,
@@ -83,7 +96,7 @@ def compile_interface():
8396
package_dir = { '' : 'src',},
8497

8598
package_data={
86-
"": ["share/*","share/*/*","share/*/*/*","share/*/*/*/*", '*.pyd', '*.so', '*.dylib', '*.lpy','*.ui','*.qrc'],
99+
"": ['*.pyd', '*.so', '*.dylib', '*.lpy','*.ui','*.qrc'],
87100
},
88101

89102
# Add package platform libraries if any
@@ -96,6 +109,7 @@ def compile_interface():
96109
"wralea": ["lpy = openalea.lpy_wralea",],
97110
'gui_scripts': ['lpy = openalea.lpy.gui.lpystudio:main',],
98111
'console_scripts': ['cpfg2lpy = openalea.lpy.cpfg_compat.cpfg2lpy:main',],
99-
}
112+
},
100113

114+
**deploy_args
101115
)

‎src/cpp/CMakeLists.txt

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ add_library(lpy SHARED ${SRC_FILES})
88

99
target_link_libraries(lpy ${PLANTGL_LIBRARIES})
1010
target_link_libraries(lpy Qt5::Core Qt5::Concurrent)
11-
pgllib_link_python(lpy)
12-
13-
# Disable Boost Auto-Link
14-
target_compile_definitions(lpy PRIVATE BOOST_ALL_NO_LIB)
1511

16-
target_link_libraries(lpy Boost::python)
12+
pgllib_link_python(lpy)
13+
pgllib_link_boost(lpy)
1714

1815
# --- Preprocessor
1916

‎src/openalea/lpy/gui/generate_ui.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
if not release:
77
print("Generate Ui - imported")
8-
import compile_ui as ui
8+
try:
9+
import compile_ui as ui
10+
except ImportError as ie:
11+
from . import compile_ui as ui
912
print("Generate Ui")
1013
ui.check_rc_generation(join(ldir, 'lpyresources.qrc'))
1114
ui.check_ui_generation(join(ldir, 'lpymainwindow.ui'))

‎src/wrapper/CMakeLists.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ add_library(__lpy_kernel__ SHARED ${SRC_FILES})
99
target_link_libraries(__lpy_kernel__ lpy)
1010
target_link_libraries(__lpy_kernel__ ${PLANTGL_LIBRARIES})
1111
pgllib_link_python(__lpy_kernel__)
12+
pgllib_link_boost(__lpy_kernel__)
1213

13-
# Disable Boost Auto-Link
14-
target_compile_definitions(__lpy_kernel__ PRIVATE BOOST_ALL_NO_LIB)
15-
16-
target_link_libraries(__lpy_kernel__ Boost::system Boost::python)
1714

1815
# --- Dependencies
1916

0 commit comments

Comments
 (0)
Please sign in to comment.