Skip to content

Add some cmake options useful for embedding - #303

Closed
amitin wants to merge 0 commit into
google:mainfrom
amitin:main
Closed

amitin wants to merge 0 commit into
google:mainfrom
amitin:main

Conversation

@amitin

@amitin amitin commented Mar 20, 2023

Copy link
Copy Markdown
Contributor

While following the recommended way to incorporate cpu_features into a cmake project some cpu_features lib build artefacts become included into the target project.
For example, list_cpu_features executable will be built and installed among project target binaries.

This pull request proposes to include some cmake options making cpu_features library embedding more flexible:

  1. BUILD_SAMPLE_APP
    This option controls if list_cpu_features will be built and included into the install target. Default is ON.
  2. INCLUDE_INSTALL
    This option allows to omit providing install targets, disabling installing cpu_features lib build artefacts into the main project install targets. Default in ON.
  3. INCLUDE_TESTS
    This option disables testing target for cpu_features at all. Since cpu_features uses standard cmake CTest BUILD_TESTING variable then it could interfere with the main project cmake settings. Having additional option solves this issue. Default is ON.

@toor1245

toor1245 commented Mar 21, 2023 •

Copy link
Copy Markdown
Contributor

I'm not sure about INCLUDE_TESTS, user can use ExternalProject_Add and pass BUILD_TESTSING with another paramater in CMAKE_ARGS like this:

include(ExternalProject)
ExternalProject_Add(cpu_features
  GIT_REPOSITORY    https://github.com/google/cpu_features.git
  GIT_TAG           main
  SOURCE_DIR        "${CMAKE_BINARY_DIR}/cpu_features-src"
  BINARY_DIR        "${CMAKE_BINARY_DIR}/cpu_features-build"
  CMAKE_ARGS
    -DBUILD_TESTING=OFF
)

About install, if I'm not mistake if you want to install only targets that are defined in the current project and not in external projects, you can use the EXCLUDE_FROM_ALL option in the add_subdirectory() command for the external project. https://cmake.org/cmake/help/latest/prop_tgt/EXCLUDE_FROM_ALL.html

@Mizux, what do you think?

@amitin

amitin commented Mar 22, 2023

Copy link
Copy Markdown
Contributor Author

Well, I did try using 'external project' cmake module before, but actually this pulls out more problems, for example, it's not possible to use 'find_package' until cpu_features install target's done.
So I followed the recommended way of embedding cpu_features.

@Mizux

Mizux commented Mar 22, 2023

Copy link
Copy Markdown
Collaborator

My 2 cents:

  1. BUILD_SAMPLE_APP: ok on the principle to be able to disable this executable

  2. INCLUDE_INSTALL: not sure is useful, which scenario need it ?
    maybe want to static link with libcpu_feature and integrate the sources using fetch or add_subdirectory ?

  3. INCLUDE_TESTS: not OK, we already have BUILD_TESTING you can set to disable tests also in another PR test will be disable by default if cpu_feature is not the cmake root project

side note

Now, Fetch() nicely interact with find_package() thanks to the 3.24 OVERRIDE_FIND_PACKAGE
see: https://cmake.org/cmake/help/latest/module/FetchContent.html#commands

Since variable are directory scoped you can add the FetchContent() in a subdir CMakeLists.txt and just before you add
set(BUILD_TESTING OFF) thus all FetchContent will be run with BUILD_TESTING=OFF (even if it set to ON for the super project)

Comment thread CMakeLists.txt Resolved
@amitin

amitin commented Mar 22, 2023

Copy link
Copy Markdown
Contributor Author

2. INCLUDE_INSTALL: not sure is useful, which scenario need it ?
maybe want to static link with libcpu_feature and integrate the sources using fetch or add_subdirectory ?

Attached is the sample app which exactly reflects what we have in our project. This illustrates the problems I'm trying to solve with this pull request.

3. INCLUDE_TESTS: not OK, we already have BUILD_TESTING you can set to disable tests also in another PR test will

Excellent! I'll remove this from my PR and will wait for that PR to land.

Now, Fetch() nicely interact with find_package() thanks to the 3.24 OVERRIDE_FIND_PACKAGE

Unfortunately, we can't currently use cmake 3.24, the latest version available to use is 3.13.

@gchatelet

gchatelet commented Aug 28, 2023 •

Copy link
Copy Markdown
Collaborator

Part of this PR has been submitted in:

@amitin

amitin commented Aug 28, 2023

Copy link
Copy Markdown
Contributor Author

Part of this PR has been submitted in #317. @amitin do you still think this PR is necessary?

Yes. That PR only partially solves the problem of embedding which we have to get solved.
My PR also includes an option to disable any 'install' targets, so we don't need to install cpu_features include files and static lib.
Additionally, it's not really clear why you didn't land my PR which I submitted six month ago but landed a new one.

@gchatelet

Copy link
Copy Markdown
Collaborator

Part of this PR has been submitted in #317. @amitin do you still think this PR is necessary?

Yes. That PR only partially solves the problem of embedding which we have to get solved. My PR also includes an option to disable any 'install' targets, so we don't need to install cpu_features include files and static lib.

AFAIU:

  1. is solved by Fix windows x86 and arm64 build and add an option to enable/disable target list_cpu_features #317
  2. remains to be solved
  3. is solved as per Add some cmake options useful for embedding #303 (comment)

I'll have a look at 2. tomorrow.

Additionally, it's not really clear why you didn't land my PR which I submitted six month ago but landed a new one.

My apologies for this, this PR went out of my radar and I started reviewing the most recent PRs first. It's unfortunate that #317 went in before yours.

@Mizux

Mizux commented Aug 28, 2023 •

Copy link
Copy Markdown
Collaborator

@amitin

amitin commented Aug 30, 2023 •

Copy link
Copy Markdown
Contributor Author

Opened:

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

Successfully merging this pull request may close these issues.

4 participants