It seems that we export too many targets. (#1385)

* It seems that we export too many targets.

* Adding missing word.

* Let us try this.

* Restoring dead line.

* Some fixes.

* Update src/CMakeLists.txt

Co-authored-by: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com>

* Update cmake/simdjson-config.nothread.cmake.in

Co-authored-by: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com>

* Update cmake/simdjson-config.cmake.in

Co-authored-by: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com>

* Update CMakeLists.txt

Co-authored-by: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com>

* Update CMakeLists.txt

Co-authored-by: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com>

* Removing useless file

* Simplifying the PR somewhat.

Co-authored-by: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com>
This commit is contained in:
Daniel Lemire 2021-01-20 13:20:49 -05:00 committed by GitHub
parent 2a714f4e37
commit 1005c62e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 9 deletions

View File

@ -43,6 +43,14 @@ if(NOT(SIMDJSON_JUST_LIBRARY))
endif()
install(FILES singleheader/simdjson.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
option(SIMDJSON_ENABLE_THREADS "Link with thread support" ON)
include(CMakePackageConfigHelpers)
configure_package_config_file("${PROJECT_SOURCE_DIR}/cmake/simdjson-config.cmake.in"
"${PROJECT_BINARY_DIR}/simdjson-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/simdjson"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
#
# Compile tools / tests / benchmarks
#

View File

@ -0,0 +1,9 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
if(@SIMDJSON_ENABLE_THREADS@)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_dependency(Threads)
endif()
# Import targets.
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")

View File

@ -202,8 +202,6 @@ if(SIMDJSON_ENABLE_THREADS)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
target_link_libraries(simdjson-flags INTERFACE Threads::Threads)
target_link_libraries(simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT})
target_compile_options(simdjson-flags INTERFACE ${CMAKE_THREAD_LIBS_INIT})
target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_THREADS_ENABLED=1) # This will be set in the code automatically.
endif()
@ -237,4 +235,6 @@ CHECK_SYMBOL_EXISTS(fork unistd.h HAVE_POSIX_FORK)
CHECK_SYMBOL_EXISTS(wait sys/wait.h HAVE_POSIX_WAIT)
install(TARGETS simdjson-flags EXPORT simdjson-config)
install(TARGETS simdjson-internal-flags EXPORT simdjson-config)
# I do not think we want to export our internal flags!
# install(TARGETS simdjson-internal-flags EXPORT simdjson-config)

View File

@ -8,7 +8,12 @@
add_library(simdjson-include-source INTERFACE)
target_link_libraries(simdjson-include-source INTERFACE simdjson-headers)
target_include_directories(simdjson-include-source INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
install(TARGETS simdjson-include-source EXPORT simdjson-config)
# If a CMake user installs simdjson and then does...
# find_package(simdjson CONFIG REQUIRED)
# find_package(Threads REQUIRED)
# target_link_libraries(test PRIVATE simdjson-include-source)
# It is not clear what it should do? Does the user get access to the src files?
# install(TARGETS simdjson-include-source EXPORT simdjson-config)
#
# For callers who intend to compile simdjson.cpp themselves.
@ -19,7 +24,14 @@ install(TARGETS simdjson-include-source EXPORT simdjson-config)
add_library(simdjson-source INTERFACE)
target_sources(simdjson-source INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/simdjson.cpp)
target_link_libraries(simdjson-source INTERFACE simdjson-include-source)
install(TARGETS simdjson-source EXPORT simdjson-config)
# Note that simdjson.cpp is *not* installed so installing simdjson-include-source is not great.
# If a CMake user installs simdjson and then does...
# find_package(simdjson CONFIG REQUIRED)
# find_package(Threads REQUIRED)
# target_link_libraries(test PRIVATE simdjson-source)
# It might fail with Cannot find source file: simdjson.cpp
# See issue https://github.com/simdjson/simdjson/issues/1383
# install(TARGETS simdjson-source EXPORT simdjson-config)
#
# simdjson is the distributed library compiled with flags.
@ -31,7 +43,15 @@ install(TARGETS simdjson-source EXPORT simdjson-config)
if(SIMDJSON_BUILD_STATIC)
MESSAGE( STATUS "Building a static library." )
add_library(simdjson STATIC "")
###
# In the case of a static library, if you do "target_link_libraries(simdjson PRIVATE simdjson-source simdjson-internal-flags)"
# without also calling "install(TARGETS simdjson-source EXPORT simdjson-config)" you get an error
# to the effect that you are trying to install 'simdjson' which depends on 'simdjson-source' while
# not installing 'simdjson-source', so it fails. So we bypass entirely simdjson-source since we do
# not want to install them.
####
add_library(simdjson STATIC simdjson.cpp)
target_include_directories(simdjson PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
else()
MESSAGE( STATUS "Building a dynamic library." )
add_library(simdjson SHARED "")
@ -40,10 +60,12 @@ else()
MESSAGE( STATUS "Building a Windows DLL using Visual Studio, exporting all symbols automatically." )
set_target_properties(simdjson PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
endif()
###
# Somehow, for a dynamic library, the next line is entirely fine (but not for a static one).
###
target_link_libraries(simdjson PRIVATE simdjson-source simdjson-internal-flags)
endif()
target_link_libraries(simdjson PUBLIC simdjson-headers simdjson-flags) # Only expose the headers, not sources
target_link_libraries(simdjson PRIVATE simdjson-source simdjson-internal-flags)
##
## In systems like R, libraries must not use stderr or abort to be acceptable.
@ -119,7 +141,7 @@ install(TARGETS simdjson
)
install(EXPORT simdjson-config
FILE simdjson-config.cmake
FILE simdjson-targets.cmake
NAMESPACE simdjson::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/simdjson
)