Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to properly install using ExternalProject_Add while also having fast_float #133

Open
ealione opened this issue Nov 17, 2024 · 0 comments

Comments

@ealione
Copy link

ealione commented Nov 17, 2024

I have installed fast_float like this:

set(FASTFLOAT_BASE fastfloat-external CACHE STRING "Base tag for fast_float")
set(FASTFLOAT_BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}/${FASTFLOAT_BASE})
set(FASTFLOAT_GIT_URL "https://github.com/fastfloat/fast_float.git" CACHE STRING "URL to the fast_float source archive")
set(FASTFLOAT_TAG "v6.1.6" CACHE STRING "fast_float version tag")
set(FASTFLOAT_INSTALL_DIR "${FASTFLOAT_BASE_DIR}/install" CACHE PATH "Path to fast_float install directory")

ExternalProject_Add(${FASTFLOAT_BASE}
        PREFIX ${FASTFLOAT_BASE_DIR}
        GIT_REPOSITORY ${FASTFLOAT_GIT_URL}
        GIT_TAG ${FASTFLOAT_TAG}
        INSTALL_DIR "${FASTFLOAT_INSTALL_DIR}"
        GIT_PROGRESS ON
        LOG_DOWNLOAD ON
        LOG_CONFIGURE ON
        LOG_BUILD ON
        GIT_SHALLOW 1
        UPDATE_DISCONNECTED TRUE
        CONFIGURE_COMMAND ""
        BUILD_COMMAND ""
        UPDATE_COMMAND ""
        INSTALL_COMMAND ""
)

# Create interface library
add_library(fastfloat INTERFACE)
add_dependencies(fastfloat ${FASTFLOAT_BASE})
target_include_directories(fastfloat SYSTEM INTERFACE
        ${FASTFLOAT_INSTALL_DIR}/include
)

# Install headers
install(
        DIRECTORY ${FASTFLOAT_INSTALL_DIR}/include/
        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
        COMPONENT core
        FILES_MATCHING
        PATTERN "*.h"
)

This works fine, but later when I also try to add scnlib I can no longer include fast_fload on my project, since it can't be found.

ExternalProject_Add(scnlib-external
        GIT_REPOSITORY    https://github.com/eliaskosunen/scnlib.git
        GIT_TAG          v3.0.1
        GIT_SHALLOW      TRUE
        CMAKE_ARGS       -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
        -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
        -DSCN_TESTS=OFF
        -DSCN_EXAMPLES=OFF
        -DSCN_BENCHMARKS=OFF
        -DSCN_DOCS=OFF
        -DSCN_USE_EXTERNAL_FAST_FLOAT=OFF  # Ensure we use the bundled fast_float
        BUILD_COMMAND    ${CMAKE_COMMAND} --build <BINARY_DIR>
        INSTALL_COMMAND  ${CMAKE_COMMAND} --install <BINARY_DIR>
        UPDATE_COMMAND   ""
)

# Get the source and binary directories
ExternalProject_Get_Property(scnlib-external SOURCE_DIR BINARY_DIR INSTALL_DIR)

# Create the main library
add_library(scnlib-lib INTERFACE)
add_dependencies(scnlib-lib scnlib-external)

# Set include directories including fast_float
target_include_directories(scnlib-lib
        INTERFACE
        ${INSTALL_DIR}/include
        ${SOURCE_DIR}/vendor/fast_float/include  # Add fast_float include path
)

# Set up the correct library paths
if(WIN32)
    set(SCN_LIB_PATH "${INSTALL_DIR}/lib/scn.lib")
else()
    set(SCN_LIB_PATH "${INSTALL_DIR}/lib/libscn.a")
endif()

# Add the library file to the interface library
target_link_libraries(scnlib-lib
        INTERFACE
        ${SCN_LIB_PATH}
)

# Create alias targets to match original scnlib targets
add_library(scn::scn ALIAS scnlib-lib)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant