How to produce a -config.cmake file

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to produce a -config.cmake file

Dorier, Matthieu

Hi,


I'm using cmake to build a library (damaris). Once installed, I would like users to be able to find it and its dependencies using find_package(damaris). If I understand correctly, the way to do that is to have cmake create and install a "damaris-config.cmake" file.


Is there a tutorial somewhere on how to do that?


Here is some more information:

the library depends on

- Boost (using the default FindBoost.cmake installed with cmake)

- XercesC (using a custom FindXercesC.cmake located in my source tree)

- XSD (using a custom FindXSD.cmake as well)

Additionally, it may have been built with the following optional dependencies:

- CppUnit (using a custom FindCppUnit.cmake)

- HDF5 (using the default FindHDF5.cmake shipped with cmake)

- VisIt (using a custom FindVisIt.cmake)

- ParaView (relying on the ParaViewConfig.cmake produced when installing ParaView).


Thanks,


Matthieu


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

How to append a string on list inside a function

Romain LEGUAY
Hello everyone,

I try to append a string (target name) on a list inside a function called in other CMakeLists.

I have the following project’s tree:

├── CMakeLists.txt
├── test
    ├── CMakeLists.txt
    └── app
        ├── CMakeLists.txt
        ├── appA
        │   ├── CMakeLists.txt
        │   └── main.cpp
        └── appB
            ├── CMakeLists.txt
            └── main.cpp

Inside the test/CMakeLists.txt, I defined an internal variable like this:
        set(allTestsList "" CACHE INTERNAL "All executable tests.'')
And my function:
        function(addTest targetName)
    # create the executable with all the souces
                add_executable(${targetName} ${ARGN})
    list(APPEND allTestsList ${targetName})
    message("inside addTestFunction. allTestsList: " ${allTestsList})
        endfunction()

I call this function inside the test/app/appA and test/app/appB CMakeLists.txt like this:
        addTest(appA main.cpp)
        addTest(appB main.cpp)

I expected to have as final result:
inside addTestFunction. allTestsList: appA;appB

But I only have:
inside addTestFunction. allTestsList: appB

I suspect that a new variable is created at each call of the function.

Is it possible to use a global variable? (I tried to use PARENT_SCOPE with no success).

Thank you,

Romain


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to produce a -config.cmake file

CMake mailing list
In reply to this post by Dorier, Matthieu

Matthieu,

 

I think are asking about the CMakePackageConfigHelpers CMake module (https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html) that defines the macro ‘configure_package_config_file’.

 

You can probably find several tutorials or examples by searching github or stackoverflow, etc. for ‘CMakePackageConfigHelpers‘.  It is also covered in some detail in the e-book “Professional CMake” by Craig Scott (requires a purchase).

 

-kt

 

From: CMake <[hidden email]> On Behalf Of Dorier, Matthieu
Sent: Thursday, September 27, 2018 2:42 AM
To: [hidden email]
Subject: [CMake] How to produce a -config.cmake file

 

Hi,

 

I'm using cmake to build a library (damaris). Once installed, I would like users to be able to find it and its dependencies using find_package(damaris). If I understand correctly, the way to do that is to have cmake create and install a "damaris-config.cmake" file.

 

Is there a tutorial somewhere on how to do that?

 

Here is some more information:

the library depends on

- Boost (using the default FindBoost.cmake installed with cmake)

- XercesC (using a custom FindXercesC.cmake located in my source tree)

- XSD (using a custom FindXSD.cmake as well)

Additionally, it may have been built with the following optional dependencies:

- CppUnit (using a custom FindCppUnit.cmake)

- HDF5 (using the default FindHDF5.cmake shipped with cmake)

- VisIt (using a custom FindVisIt.cmake)

- ParaView (relying on the ParaViewConfig.cmake produced when installing ParaView).

 

Thanks,

 

Matthieu


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to append a string on list inside a function

Marc CHEVRIER
In reply to this post by Romain LEGUAY
Using a cache variable seems not required. A function creates a new scope and inherit a copy of all variables defined in the upper scope.
So, by adding a set command using PARENT_SCOPE in your function you can update the variable in the parent scope:
      function(addTest targetName)
                # create the executable with all the souces
                add_executable(${targetName} ${ARGN})
                list(APPEND allTestsList ${targetName})
                set (allTestsList  ${allTestsList} PARENT_SCOPE) 
                message("inside addTestFunction. allTestsList: " ${allTestsList})
        endfunction()  

Le jeu. 27 sept. 2018 à 12:43, Romain LEGUAY <[hidden email]> a écrit :
Hello everyone,

I try to append a string (target name) on a list inside a function called in other CMakeLists.

I have the following project’s tree:

├── CMakeLists.txt
├── test
    ├── CMakeLists.txt
    └── app
        ├── CMakeLists.txt
        ├── appA
        │   ├── CMakeLists.txt
        │   └── main.cpp
        └── appB
            ├── CMakeLists.txt
            └── main.cpp

Inside the test/CMakeLists.txt, I defined an internal variable like this:
        set(allTestsList "" CACHE INTERNAL "All executable tests.'')
And my function:
        function(addTest targetName)
                # create the executable with all the souces
                add_executable(${targetName} ${ARGN})
                list(APPEND allTestsList ${targetName})
                message("inside addTestFunction. allTestsList: " ${allTestsList})
        endfunction()

I call this function inside the test/app/appA and test/app/appB CMakeLists.txt like this:
        addTest(appA main.cpp)
        addTest(appB main.cpp)

I expected to have as final result:
inside addTestFunction. allTestsList: appA;appB

But I only have:
inside addTestFunction. allTestsList: appB

I suspect that a new variable is created at each call of the function.

Is it possible to use a global variable? (I tried to use PARENT_SCOPE with no success).

Thank you,

Romain


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to produce a -config.cmake file

Dorier, Matthieu
In reply to this post by CMake mailing list

Thanks, those pointers helped a lot!


Matthieu


From: Thompson, KT <[hidden email]>
Sent: Thursday, September 27, 2018 3:30:33 PM
To: Dorier, Matthieu; [hidden email]
Subject: RE: How to produce a -config.cmake file
 

Matthieu,

 

I think are asking about the CMakePackageConfigHelpers CMake module (https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html) that defines the macro ‘configure_package_config_file’.

 

You can probably find several tutorials or examples by searching github or stackoverflow, etc. for ‘CMakePackageConfigHelpers‘.  It is also covered in some detail in the e-book “Professional CMake” by Craig Scott (requires a purchase).

 

-kt

 

From: CMake <[hidden email]> On Behalf Of Dorier, Matthieu
Sent: Thursday, September 27, 2018 2:42 AM
To: [hidden email]
Subject: [CMake] How to produce a -config.cmake file

 

Hi,

 

I'm using cmake to build a library (damaris). Once installed, I would like users to be able to find it and its dependencies using find_package(damaris). If I understand correctly, the way to do that is to have cmake create and install a "damaris-config.cmake" file.

 

Is there a tutorial somewhere on how to do that?

 

Here is some more information:

the library depends on

- Boost (using the default FindBoost.cmake installed with cmake)

- XercesC (using a custom FindXercesC.cmake located in my source tree)

- XSD (using a custom FindXSD.cmake as well)

Additionally, it may have been built with the following optional dependencies:

- CppUnit (using a custom FindCppUnit.cmake)

- HDF5 (using the default FindHDF5.cmake shipped with cmake)

- VisIt (using a custom FindVisIt.cmake)

- ParaView (relying on the ParaViewConfig.cmake produced when installing ParaView).

 

Thanks,

 

Matthieu


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake