Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7813357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:49:55+00:00 2026-06-02T04:49:55+00:00

I want to not add boost.cxx if cmake find_package found no boost installed. Does

  • 0

I want to not add boost.cxx if cmake find_package found no boost installed. Does find_package return something that I can wrap in condition to compile boost.cxx or not. Here is my current cmake file:

add_executable (complex complex.cxx lexer.cxx boost.cxx ../../src/lili.cxx ../../src/lilu.cxx)

# Make sure the compiler can find all include files
include_directories (../../src) 
include_directories (.)

# Make sure the linker can find all needed libraries
# rt: clock_gettime()
target_link_libraries(complex rt)

# Install example application
install (TARGETS complex
         RUNTIME DESTINATION bin)

IF(UNIX)
    find_package(Boost COMPONENTS system filesystem REQUIRED)

    ## Compiler flags
    if(CMAKE_COMPILER_IS_GNUCXX)
        set(CMAKE_CXX_FLAGS "-O2")
        set(CMAKE_EXE_LINKER_FLAGS "-lsqlite3 -lrt -lpthread")
    endif()

    target_link_libraries(complex 
      ${Boost_FILESYSTEM_LIBRARY}
      ${Boost_SYSTEM_LIBRARY}
      #${PROTOBUF_LIBRARY}
    )
ENDIF(UNIX)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:49:58+00:00Added an answer on June 2, 2026 at 4:49 am

    The FindXXX scripts are supposed to set a variable <Packagename>_FOUND to TRUEif the package was found. So in your case, it will set Boost_FOUND if boost was found.

    When compiling your Boost.cxx, I assume that you will need Boost headers as well, so you should adjust your include directories as well.*

    look for Boost before creating your executable. Furhtermore, you need to set your include directories before adding the executable.

    IF(UNIX)
        find_package(Boost COMPONENTS system filesystem REQUIRED)
        # IF( Boost_FOUND ) # checking this variable isnt even necessary, since you added
                            # REQUIRED to your call to FIND_PACKAGE
            SET( BOOST_SRC_FILES boost.cxx )
            INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} ) # you could move this down as well
                                                         # as ${Boost_INCLUDE_DIRS} will be
                                                         # empty if Boost was not found
        # ENDIF()
    ENDIF()
    
    add_executable (complex complex.cxx lexer.cxx ${BOOST_SRC_FILES} ../../src/lili.cxx ../../src/lilu.cxx)
    
    # Make sure the compiler can find all include files
    include_directories (../../src) 
    include_directories (.)
    # INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} ) # alternative location to 
                                                   # add include dirs, see above
    
    # Make sure the linker can find all needed libraries
    # rt: clock_gettime()
    target_link_libraries(complex rt)
    
    # Install example application
    install (TARGETS complex
             RUNTIME DESTINATION bin)
    
    IF(UNIX)
    
        ## Compiler flags
        if(CMAKE_COMPILER_IS_GNUCXX)
            set(CMAKE_CXX_FLAGS "-O2")
            set(CMAKE_EXE_LINKER_FLAGS "-lsqlite3 -lrt -lpthread")
        endif()
    
        target_link_libraries(complex 
          ${Boost_FILESYSTEM_LIBRARY}
          ${Boost_SYSTEM_LIBRARY}
          #${PROTOBUF_LIBRARY}
        )
    ENDIF(UNIX)
    

    Afternote: Since you use the REQUIRED flag when looking for Boost (since you only need it on Unix platform) it is even sufficient to use the optional-source-files-in-a-variable trick.

    (*) Thanks to your question, I just found out that it doesn’t matter whether include_directories(...) is called before or after creating the target with ADD_EXECUTABLE or ADD_LIBRARY since the directories are added to all targets in the same project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add colections to List, but only if Advertisements does not already
What if I want not only to add events for all future added, but
I want to add a person to a community and im not sure how
I want to add a revision counter to my rails app. Not the number
I want to add many UIBarButtonItem 's to a UINavigationbar , not just right
Expanding on recent_posts_on_self below, I want to add an all_recent_posts_on_self method but I'm not
customers does not want to allow user to use back or forward button. Just
How can I specify where MSVC searches for include files? I want to add
I am having a problem with using Boost Logging library, that if I add
So I found a need in using something like Boost.Extension to keep my apps

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.