Skip to content

Commit 4e70828

Browse files
committed
Make so install stuff is only called if building as a top-level project.
This is in respect to trying to fix macOS CI build: #34 (comment)
1 parent ecf3d0e commit 4e70828

File tree

1 file changed

+61
-57
lines changed

1 file changed

+61
-57
lines changed

Diff for: CMakeLists.txt

+61-57
Original file line numberDiff line numberDiff line change
@@ -440,75 +440,79 @@ endif( SpecUtils_BUILD_FUZZING_TESTS )
440440

441441
set_property( TARGET SpecUtils PROPERTY POSITION_INDEPENDENT_CODE ON )
442442

443-
# Specify installation rules
444-
include(GNUInstallDirs)
445443

444+
get_directory_property(hasParent PARENT_DIRECTORY)
445+
if( NOT hasParent )
446+
# Specify installation rules
447+
include(GNUInstallDirs)
446448

447-
# Install the library
448-
install(TARGETS SpecUtils
449-
EXPORT SpecUtilsTargets
450-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # For shared libraries on UNIX-like systems
451-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # For static libraries and import libraries on Windows
452-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # For DLLs
453-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
454-
)
455449

456-
set( SpecUtils_config_OUT ${CMAKE_CURRENT_BINARY_DIR}/SpecUtils_config.h )
457-
configure_file(
458-
${CMAKE_CURRENT_SOURCE_DIR}/SpecUtils/SpecUtils_config.h.in
459-
${SpecUtils_config_OUT}
460-
)
461-
LIST(APPEND headers ${SpecUtils_config_OUT})
462-
# Install the headers
463-
install(FILES ${headers} ${CMAKE_BINARY_DIR}/SpecUtilsExport.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SpecUtils)
450+
# Install the library
451+
install(TARGETS SpecUtils
452+
EXPORT SpecUtilsTargets
453+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # For shared libraries on UNIX-like systems
454+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # For static libraries and import libraries on Windows
455+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # For DLLs
456+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
457+
)
464458

465-
# Create and install the CMake package configuration files
466-
include(CMakePackageConfigHelpers)
459+
set( SpecUtils_config_OUT ${CMAKE_CURRENT_BINARY_DIR}/SpecUtils_config.h )
460+
configure_file(
461+
${CMAKE_CURRENT_SOURCE_DIR}/SpecUtils/SpecUtils_config.h.in
462+
${SpecUtils_config_OUT}
463+
)
464+
LIST(APPEND headers ${SpecUtils_config_OUT})
465+
# Install the headers
466+
install(FILES ${headers} ${CMAKE_BINARY_DIR}/SpecUtilsExport.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SpecUtils)
467467

468-
write_basic_package_version_file(
469-
"${CMAKE_CURRENT_BINARY_DIR}/SpecUtilsConfigVersion.cmake"
470-
VERSION ${PROJECT_VERSION}
471-
COMPATIBILITY AnyNewerVersion
472-
)
468+
# Create and install the CMake package configuration files
469+
include(CMakePackageConfigHelpers)
473470

474-
configure_package_config_file(
475-
"${CMAKE_CURRENT_SOURCE_DIR}/SpecUtilsConfig.cmake.in"
476-
"${CMAKE_CURRENT_BINARY_DIR}/SpecUtilsConfig.cmake"
477-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SpecUtils
478-
)
471+
write_basic_package_version_file(
472+
"${CMAKE_CURRENT_BINARY_DIR}/SpecUtilsConfigVersion.cmake"
473+
VERSION ${PROJECT_VERSION}
474+
COMPATIBILITY AnyNewerVersion
475+
)
479476

480-
install(FILES
481-
"${CMAKE_CURRENT_BINARY_DIR}/SpecUtilsConfig.cmake"
482-
"${CMAKE_CURRENT_BINARY_DIR}/SpecUtilsConfigVersion.cmake"
483-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SpecUtils
484-
)
477+
configure_package_config_file(
478+
"${CMAKE_CURRENT_SOURCE_DIR}/SpecUtilsConfig.cmake.in"
479+
"${CMAKE_CURRENT_BINARY_DIR}/SpecUtilsConfig.cmake"
480+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SpecUtils
481+
)
485482

486-
install(EXPORT SpecUtilsTargets
487-
FILE SpecUtilsTargets.cmake
488-
NAMESPACE SpecUtils::
489-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SpecUtils
490-
)
483+
install(FILES
484+
"${CMAKE_CURRENT_BINARY_DIR}/SpecUtilsConfig.cmake"
485+
"${CMAKE_CURRENT_BINARY_DIR}/SpecUtilsConfigVersion.cmake"
486+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SpecUtils
487+
)
491488

492-
set(CPACK_PACKAGE_NAME "SpecUtils")
489+
install(EXPORT SpecUtilsTargets
490+
FILE SpecUtilsTargets.cmake
491+
NAMESPACE SpecUtils::
492+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SpecUtils
493+
)
493494

495+
set(CPACK_PACKAGE_NAME "SpecUtils")
494496

495-
if( SpecUtils_SHARED_LIB )
496-
set( SpecUtils_PACKAGE_POSTFIX "SharedLib" )
497-
else( SpecUtils_SHARED_LIB )
498-
set( SpecUtils_PACKAGE_POSTFIX "StaticLib" )
499-
endif( SpecUtils_SHARED_LIB )
500497

501-
if( DEFINED ${PROJECT_NAME}_USE_MSVC_MultiThreadDLL )
502-
if( ${PROJECT_NAME}_USE_MSVC_MultiThreadDLL )
503-
set( SpecUtils_PACKAGE_POSTFIX "${SpecUtils_PACKAGE_POSTFIX}-SharedRuntime" )
504-
else()
505-
set( SpecUtils_PACKAGE_POSTFIX "${SpecUtils_PACKAGE_POSTFIX}-StaticRuntime" )
498+
if( SpecUtils_SHARED_LIB )
499+
set( SpecUtils_PACKAGE_POSTFIX "SharedLib" )
500+
else( SpecUtils_SHARED_LIB )
501+
set( SpecUtils_PACKAGE_POSTFIX "StaticLib" )
502+
endif( SpecUtils_SHARED_LIB )
503+
504+
if( DEFINED ${PROJECT_NAME}_USE_MSVC_MultiThreadDLL )
505+
if( ${PROJECT_NAME}_USE_MSVC_MultiThreadDLL )
506+
set( SpecUtils_PACKAGE_POSTFIX "${SpecUtils_PACKAGE_POSTFIX}-SharedRuntime" )
507+
else()
508+
set( SpecUtils_PACKAGE_POSTFIX "${SpecUtils_PACKAGE_POSTFIX}-StaticRuntime" )
509+
endif()
506510
endif()
507-
endif()
508511

509-
# Lets just use the MAJOR.MINOR version of the compiler in the name.
510-
string(REGEX MATCH "^[0-9]+\\.[0-9]+" COMPILER_VERSION_SHORT "${CMAKE_CXX_COMPILER_VERSION}")
512+
# Lets just use the MAJOR.MINOR version of the compiler in the name.
513+
string(REGEX MATCH "^[0-9]+\\.[0-9]+" COMPILER_VERSION_SHORT "${CMAKE_CXX_COMPILER_VERSION}")
511514

512-
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-${COMPILER_VERSION_SHORT}-${SpecUtils_PACKAGE_POSTFIX}")
513-
set(CPACK_GENERATOR "ZIP")
514-
include(CPack)
515+
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-${COMPILER_VERSION_SHORT}-${SpecUtils_PACKAGE_POSTFIX}")
516+
set(CPACK_GENERATOR "ZIP")
517+
include(CPack)
518+
endif( NOT hasParent )

0 commit comments

Comments
 (0)