Skip to content

Commit ac9a831

Browse files
committed
Build tests directly from library sources to avoid export/import conflict on windows when using object files
Fix inclusion of conda-prefixed directories in package search
1 parent 3df9b53 commit ac9a831

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

CMakeLists.txt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -779,18 +779,27 @@ if(BUILD_TESTS AND BUILD_CXX)
779779
list(APPEND TEST_LIST ${TEST_PATH})
780780
endif()
781781
endforeach()
782-
# Build executable directly from compiled object files so that
782+
# Build executable directly from source files so that
783783
# non-exported symbols can still be tested by unit tests
784-
add_executable(testRunner ${TEST_LIST} $<TARGET_OBJECTS:${CXX_LIBRARY_NAME}>)
785-
target_compile_options(
786-
testRunner PUBLIC ${ePhoto_COMPILE_OPTIONS}
787-
)
788-
# target_link_options(
789-
# testRunner PUBLIC $<TARGET_PROPERTY:${CXX_LIBRARY_NAME},LINK_OPTIONS>
790-
# )
791-
target_include_directories(
792-
testRunner PUBLIC ${ePhoto_INCLUDE_DIRECTORIES}
793-
)
784+
add_executable(testRunner ${TEST_LIST} ${ePhoto_SOURCES})
785+
if(ePhoto_DEPENDENCIES)
786+
add_dependencies(testRunner ${ePhoto_DEPENDENCIES})
787+
endif()
788+
if(ePhoto_COMPILE_OPTIONS)
789+
target_compile_options(
790+
testRunner PUBLIC ${ePhoto_COMPILE_OPTIONS}
791+
)
792+
endif()
793+
if(ePhoto_COMPILE_DEFINITIONS)
794+
target_compile_definitions(
795+
testRunner PUBLIC ${ePhoto_COMPILE_DEFINITIONS}
796+
)
797+
endif()
798+
if(ePhoto_INCLUDE_DIRECTORIES)
799+
target_include_directories(
800+
testRunner PUBLIC ${ePhoto_INCLUDE_DIRECTORIES}
801+
)
802+
endif()
794803
target_link_libraries(
795804
testRunner ${ePhoto_PUBLIC_LIBRARIES} ${ePhoto_PRIVATE_LIBRARIES}
796805
${ePhoto_PRIVATE_LIBRARIES_C}

cmake/SearchTools.cmake

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,24 +213,29 @@ function(find_package_pkgconfig name)
213213

214214
if (CONDA_PREFIX)
215215
if (WIN32)
216-
set(PC_${name}_INCLUDE_DIRS "${CONDA_PREFIX}/Library/include ${PC_${name}_INCLUDE_DIRS}")
217-
set(PC_${name}_LIBRARY_DIRS "${CONDA_PREFIX}/Library/lib ${CONDA_PREFIX}/Library/bin ${PC_${name}_LIBRARY_DIRS}")
216+
set(CONDA_INCLUDE_DIRS "${CONDA_PREFIX}/Library/include")
217+
set(CONDA_LIBRARY_DIRS "${CONDA_PREFIX}/Library/lib"
218+
"${CONDA_PREFIX}/Library/bin")
218219
else()
219-
set(PC_${name}_INCLUDE_DIRS "${CONDA_PREFIX}/include ${PC_${name}_INCLUDE_DIRS}")
220-
set(PC_${name}_LIBRARY_DIRS "${CONDA_PREFIX}/lib ${PC_${name}_LIBRARY_DIRS}")
220+
set(CONDA_INCLUDE_DIRS "${CONDA_PREFIX}/include")
221+
set(CONDA_LIBRARY_DIRS "${CONDA_PREFIX}/lib")
221222
endif()
223+
list(PREPEND PC_${name}_INCLUDE_DIRS ${CONDA_INCLUDE_DIRS})
224+
list(PREPEND PC_${name}_LIBRARY_DIRS ${CONDA_LIBRARY_DIRS})
222225
endif()
223226

224227
## use the hint from above to find where '*.h' is located
225228
find_path(${name}_INCLUDE_DIR
226229
NAMES ${ARGS_HEADER}
227-
PATHS ${PC_${name}_INCLUDE_DIRS})
230+
PATHS ${PC_${name}_INCLUDE_DIRS}
231+
)
228232

229233
## use the hint from above to find the location of lib*
230234
find_library(tmp_library
231235
NAMES ${ARGS_LIBNAMES}
232236
PATHS ${PC_${name}_LIBRARY_DIRS}
233-
NO_CACHE)
237+
NO_CACHE
238+
)
234239

235240
if(NOT tmp_library STREQUAL tmp_library-NOTFOUND)
236241
set(${name}_LIBRARY ${tmp_library})
@@ -239,7 +244,8 @@ function(find_package_pkgconfig name)
239244
foreach(dir IN LISTS PC_${name}_LIBRARY_DIRS)
240245
execute_process(
241246
COMMAND ls ${dir}
242-
COMMAND_ECHO STDOUT)
247+
COMMAND_ECHO STDOUT
248+
)
243249
endforeach()
244250
endif()
245251
if ((NOT ${name}_INCLUDE_DIR STREQUAL ${name}_INCLUDE_DIR-NOTFOUND) AND

0 commit comments

Comments
 (0)