Jim Ma
Jim Ma

Reputation: 729

CMake: how to specify different CMakeFileList?

We created 3 different CMakeFileList files (CMakeFileList.engine, CMakeFileList.data and CMakeFileList.fep) for different build options within the same project. Does CMake support specifying CMakeFileList file as an argument? If not, what's the best way to accomplish our task by leveraging cmake? Any suggestion is appreciated.

Upvotes: 0

Views: 543

Answers (2)

EmDroid
EmDroid

Reputation: 6046

In general I've done such kind of things by using the option() cmake command and providing just a single CMakeLists.txt file (what to build is decided inside according to the options, i.e. you can then also build everything in a single cmake/make run).

Example:

# the defaults (can be overridden on the command line)
option(BUILD_ENGINE "Build the Engine" ON)
option(BUILD_DATA "Build the Data" ON)
option(BUILD_FEP "Build the Fep" OFF)

if (BUILD_ENGINE)
    # commands to build the Engine target or include(CMakeFileList.engine)
endif()

if (BUILD_DATA)
    # commands to build the Data target or include(CMakeFileList.data)
endif()

if (BUILD_FEP)
    # commands to build the Fep target or include(CMakeFileList.fep)
endif()

Then you can have everything in a single CMakeLists.txt and build what is needed each time, might it be multiple packages (if different than the defaults, you can switch on/off on the cmake command line). Or include the separate cmake lists as well (and just to make sure that they will work together if everything needs to be build).

Upvotes: 2

Tsyvarev
Tsyvarev

Reputation: 66153

Create main CMakeLists.txt file and conditionally use command include for use component-specific parts:

set(BUILD_TARGET "" CACHE STRING "Target to build")

if(BUILD_TARGET STREQUAL "engine")
    include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeFileList.engine)
elseif(BUILD_TARGET STREQUAL "data")
    include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeFileList.data)
elseif(BUILD_TARGET STREQUAL "fep")
    include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeFileList.fep)
else()
    message(FATAL_ERROR "Incorrect BUILD_TARGET")
endif()

Upvotes: 0

Related Questions