Skip to content

Commit 028a828

Browse files
committed
searching libs via cmake
1 parent b4ab954 commit 028a828

File tree

13 files changed

+185
-152
lines changed

13 files changed

+185
-152
lines changed

CMakeLists.txt

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,23 @@ set(CMAKE_VERBOSE_MAKEFILE on)
66
set(Python_FIND_VIRTUALENV FIRST)
77
set(Python_FIND_STRATEGY LOCATION)
88

9-
find_package(Python REQUIRED COMPONENTS Interpreter Development NumPy)
10-
119
add_library(${TARGET_NAME} SHARED ${ALL_SRC})
1210

1311
foreach(FOLDER_NAME IN ITEMS layer0 layer1 layer2 layer3 layer4 layer5 ov)
1412
include(${CMAKE_CURRENT_SOURCE_DIR}/${FOLDER_NAME}/sources.cmake)
1513
endforeach()
1614

15+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
16+
include(Dependencies)
17+
include(Helpers)
18+
1719
target_link_options(${TARGET_NAME} PRIVATE
1820
"$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,dynamic_lookup>"
1921
)
2022

2123
target_compile_options(${TARGET_NAME} PRIVATE
2224
${ALL_COMP_ARGS}
23-
24-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:
25-
-Werror=return-type
26-
-Wunused-variable
27-
-Wno-switch
28-
-Wno-narrowing
29-
-Wno-char-subscripts
30-
$<$<CONFIG:Debug>:-Og>
31-
$<$<NOT:$<CONFIG:Debug>>:-O3>
32-
>
33-
$<$<CXX_COMPILER_ID:MSVC>:/MP>
34-
$<$<CXX_COMPILER_ID:MSVC>:/std:c++17>
35-
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Z7>
36-
37-
# optimization currently causes a clang segfault on OS X 10.9 when
38-
# compiling layer2/RepCylBond.cpp
39-
$<$<PLATFORM_ID:Darwin>:-fno-strict-aliasing>
25+
${PYMOL_COMPILE_OPTIONS}
4026
)
4127

4228
execute_process(
@@ -45,23 +31,6 @@ execute_process(
4531
OUTPUT_STRIP_TRAILING_WHITESPACE
4632
)
4733

48-
function(set_output_path lib path)
49-
set_target_properties(${lib} PROPERTIES
50-
PREFIX ""
51-
SUFFIX "${PYTHON_MODULE_SUFFIX}"
52-
OUTPUT_NAME "${lib}"
53-
LIBRARY_OUTPUT_DIRECTORY "${path}"
54-
RUNTIME_OUTPUT_DIRECTORY "${path}"
55-
)
56-
57-
foreach(CONFIG IN ITEMS RELEASE DEBUG RELWITHDEBINFO MINSIZEREL)
58-
set_target_properties(${lib} PROPERTIES
59-
LIBRARY_OUTPUT_DIRECTORY_${CONFIG} "${path}"
60-
RUNTIME_OUTPUT_DIRECTORY_${CONFIG} "${path}"
61-
)
62-
endforeach()
63-
endfunction()
64-
6534
set_output_path(${TARGET_NAME} "${Python_SITEARCH}/pymol")
6635

6736
target_compile_features(${TARGET_NAME} PRIVATE cxx_std_17)
@@ -72,6 +41,7 @@ target_include_directories(${TARGET_NAME} PUBLIC
7241
${ALL_INC_DIR}
7342
${Python_INCLUDE_DIRS}
7443
${Python_NumPy_INCLUDE_DIRS}
44+
${PYMOL_INC_DIRS}
7545
)
7646

7747
target_link_directories(${TARGET_NAME} PUBLIC
@@ -81,22 +51,13 @@ target_link_directories(${TARGET_NAME} PUBLIC
8151
target_link_libraries(${TARGET_NAME}
8252
${ALL_LIB}
8353
${ALL_EXT_LINK}
84-
# pyconfig.py forces linking against pythonXY.lib on MSVC
85-
$<$<CXX_COMPILER_ID:MSVC>:${Python_LIBRARIES}>
86-
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/DEBUG>
54+
${PYMOL_LIBS}
8755
)
8856

8957
target_compile_definitions(${TARGET_NAME} PUBLIC
9058
${ALL_DEF}
91-
_PYMOL_LIBPNG
92-
_PYMOL_FREETYPE
59+
${PYMOL_DEF_MACROS}
9360
_PYMOL_NUMPY
94-
$<$<CXX_COMPILER_ID:MSVC>:WIN32>
95-
$<$<PLATFORM_ID:Darwin>:PYMOL_CURVE_VALIDATE>
96-
97-
# bounds checking in STL containers
98-
# if DEBUG and not Windows compiler
99-
$<$<AND:$<CONFIG:Debug>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:_GLIBCXX_ASSERTIONS>
10061
)
10162

10263
add_subdirectory(contrib/champ)

cmake/Dependencies.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
include_guard()
2+
3+
set(PYMOL_DEF_MACROS "")
4+
set(PYMOL_INC_DIRS "")
5+
set(PYMOL_LIBS "")
6+
set(PYMOL_COMPILE_OPTIONS "")
7+
8+
if(DEFINED ENV{CONDA_PREFIX})
9+
10+
set(CONDA_PREFIX $ENV{CONDA_PREFIX})
11+
message(STATUS "Found Conda prefix: ${CONDA_PREFIX}")
12+
13+
if(WIN32)
14+
set(CONDA_LIBRARY_DIR ${CONDA_PREFIX}/Library/lib)
15+
set(CONDA_INCLUDE_DIR ${CONDA_PREFIX}/Library/include)
16+
set(CONDA_CMAKE_DIR ${CONDA_PREFIX}/Library/lib/cmake)
17+
else()
18+
set(CONDA_LIBRARY_DIR ${CONDA_PREFIX}/lib)
19+
set(CONDA_INCLUDE_DIR ${CONDA_PREFIX}/include)
20+
set(CONDA_CMAKE_DIR ${CONDA_PREFIX}/lib/cmake)
21+
endif()
22+
23+
list(APPEND CMAKE_PREFIX_PATH ${CONDA_PREFIX} ${CONDA_CMAKE_DIR})
24+
list(APPEND CMAKE_LIBRARY_PATH ${CONDA_LIBRARY_DIR})
25+
list(APPEND CMAKE_INCLUDE_PATH ${CONDA_INCLUDE_DIR})
26+
27+
endif()
28+
29+
find_package(Python REQUIRED COMPONENTS Interpreter Development NumPy)
30+
include(dependencies/Freetype)
31+
include(dependencies/Png)
32+
33+
include(dependencies/GL)
34+
if(PYMOL_LIBXML2)
35+
include(dependencies/XML2)
36+
endif()
37+
if(PYMOL_USE_OPENMP)
38+
include(dependencies/OpenMP)
39+
endif()
40+
if(PYMOL_TESTING)
41+
include(dependencies/Testing)
42+
endif()

cmake/Helpers.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
include_guard()
2+
3+
function(set_output_path lib path)
4+
set_target_properties(${lib} PROPERTIES
5+
PREFIX ""
6+
SUFFIX "${PYTHON_MODULE_SUFFIX}"
7+
OUTPUT_NAME "${lib}"
8+
LIBRARY_OUTPUT_DIRECTORY "${path}"
9+
RUNTIME_OUTPUT_DIRECTORY "${path}"
10+
)
11+
12+
foreach(CONFIG IN ITEMS RELEASE DEBUG RELWITHDEBINFO MINSIZEREL)
13+
set_target_properties(${lib} PROPERTIES
14+
LIBRARY_OUTPUT_DIRECTORY_${CONFIG} "${path}"
15+
RUNTIME_OUTPUT_DIRECTORY_${CONFIG} "${path}"
16+
)
17+
endforeach()
18+
endfunction()
19+

cmake/dependencies/Freetype.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
find_package(Freetype REQUIRED)
2+
3+
list(APPEND PYMOL_LIBS Freetype::Freetype)
4+
list(APPEND PYMOL_DEF_MACROS "_PYMOL_FREETYPE")

cmake/dependencies/GL.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
if(NOT GLUT)
2+
list(APPEND PYMOL_DEF_MACROS "_PYMOL_NO_MAIN")
3+
endif()
4+
5+
find_package(GLEW REQUIRED)
6+
list(APPEND PYMOL_LIBS GLEW::GLEW)
7+
8+
if(APPLE)
9+
if(PYMOL_OSX_FRAMEWORKS)
10+
list(APPEND PYMOL_LINK_OPTIONS "-framework OpenGL")
11+
if(GLUT)
12+
list(APPEND PYMOL_LINK_OPTIONS "-framework GLUT")
13+
endif()
14+
list(APPEND PYMOL_DEF_MACROS "_PYMOL_OSX")
15+
else()
16+
list(APPEND PYMOL_LIBS "GL")
17+
if(GLUT)
18+
list(APPEND PYMOL_LIBS "glut")
19+
endif()
20+
endif()
21+
22+
elseif(WIN32)
23+
list(APPEND PYMOL_LIBS "Advapi32" "Ws2_32" "glew32" "opengl32")
24+
25+
if(PYMOL_GLUT)
26+
list(APPEND PYMOL_LIBS "freeglut")
27+
endif()
28+
29+
else()
30+
list(APPEND PYMOL_LIBS "GL")
31+
if(GLUT)
32+
list(APPEND PYMOL_LIBS "glut")
33+
endif()
34+
endif()

cmake/dependencies/OpenMP.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
find_package(OpenMP)
2+
list(APPEND PYMOL_DEF_MACROS "PYMOL_OPENMP")
3+
4+
if(APPLE)
5+
list(APPEND PYMOL_COMPILE_OPTIONS "-Xpreprocessor" "-fopenmp")
6+
list(APPEND PYMOL_LIBS "omp")
7+
8+
elseif(WIN32)
9+
list(APPEND PYMOL_COMPILE_OPTIONS "/openmp")
10+
11+
else()
12+
list(APPEND PYMOL_COMPILE_OPTIONS "-fopenmp")
13+
list(APPEND PYMOL_LINK_OPTIONS "-fopenmp")
14+
15+
endif()

cmake/dependencies/Optians.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
option(PYMOL_GLUT "Disable GLUT" OFF)
2+
option(PYMOL_LIBXML2 "Enable LIBXML2 support" OFF)
3+
option(PYMOL_OSX_FRAMEWORKS "Enable XQuartz instead of native frameworks" ON)
4+
option(PYMOL_USE_OPENMP "Enable OpenMP support" ON)
5+
option(PYMOL_TESTING "Build C-level tests" OFF)

cmake/dependencies/Png.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
find_package(PNG REQUIRED)
2+
3+
list(APPEND PYMOL_LIBS PNG::PNG)
4+
list(APPEND PYMOL_DEF_MACROS "_PYMOL_LIBPNG")

cmake/dependencies/Testing.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
find_package(Catch2 REQUIRED)
2+
3+
include(include(${PROJECT_SOURCE_DIR}/layerCTest/sources.cmake))
4+
list(APPEND PYMOL_LIBS Catch2::Catch2)
5+
list(APPEND PYMOL_DEF_MACROS "_PYMOL_CTEST")

cmake/dependencies/XML2.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
find_package(LibXml2 REQUIRED)
2+
3+
# COLLADA support
4+
list(APPEND PYMOL_DEF_MACROS "_HAVE_LIBXML")
5+
list(APPEND PYMOL_LIBS LibXml2::LibXml2)

0 commit comments

Comments
 (0)