0

I'm making a CMAKE file with an external project. I'm following the example here: CMake ExternalProject_Add() and FindPackage()

However, I have a problem. When I call cmake, I use cmake -G "MinGW Makefiles" ... Unfortunately the -G parameter doesn't seem to be passed into the rescan target. How can I relay applicable Cmake commands to any rescan?

I think this is the line I need to change

 add_custom_target(Rescan ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} DEPENDS Eigen3)

Here is the CMakeLists.txt:

find_package( Dep1 )

include (ExternalProject)
ExternalProject_Add (
                   Dep1
                   SVN_REPOSITORY https://svn.company.nl/svn/Dep1-trunk
                   SVN_REVISION -rHEAD
                   TIMEOUT 10
)

if (NOT Dep1_FOUND )
  add_custom_target(Rescan ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} DEPENDS Dep1)
else (NOT Dep1_FOUND)
  add_custom_target(Rescan)
endif (NOT Dep1_FOUND)

#build app
add_executable( Testapp main.cpp )
add_dependencies( Testapp Rescan )

if (${Dep1_FOUND})
  target_include_directories( Testapp PUBLIC ${Dep1_INCLUDE_DIR} )
  target_link_libraries( Testapp ${Dep1_LIBRARY} )
endif (${Dep1_FOUND})

#Install package
install(TARGETS Testapp EXPORT ${PROJECT_NAME}Targets
  RUNTIME DESTINATION bin
)
Community
  • 1
  • 1
Stewart
  • 4,356
  • 2
  • 27
  • 59

1 Answers1

1

Sure, just call

add_custom_target(Rescan ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} ${CMAKE_SOURCE_DIR} DEPENDS Eigen3)

See documentation for CMAKE_GENERATOR variable.

arrowd
  • 33,231
  • 8
  • 79
  • 110
  • This helps thanks. However if someone uses -T or -A would I need to handle each case or is there something that will let me pass everything into cmake? – Stewart Dec 01 '16 at 10:14
  • 1
    The respective variables are `CMAKE_GENERATOR_TOOLSET` and `CMAKE_GENERATOR_PLATFORM`. – arrowd Dec 01 '16 at 11:35
  • This answer helps with the -T and -A cases, but what about cases I haven't considered yet? For example, what if someone passes a custom `CMAKE_INSTALL_PREFIX`? I'm sure I am missing a lot of possibilities. Is there a generic way to pass everything? – Stewart Dec 01 '16 at 13:50
  • @Stewart Generally, CMake picks up all cache variables from CMakeCache.txt during reconfiguring. But you seem to have another issue. You want to pass all CMake variables from your build directory into another separate build dir, am I right? – arrowd Dec 01 '16 at 15:13
  • Since I need to build with `-G "MinGW Makefiles"`, I'm sure other people have other quirks, or preferences. It would be fantastic if CMake picks up all cache variables, but I noticed that without adding `-G ${CMAKE_GENERATOR}` to my `${CMAKE_COMMAND}`, my build failed. My problem is solved (hence the solved status), however in the interest of preventing other problems in the future, I'm probing about how to fix this in the most generic way possible. – Stewart Dec 01 '16 at 15:24