1

I'm currently using one CMakeLists.txt file that will execute an external CMakeLists.txt (and dependency).

For this I use the ExternalProject_Add command, but I can't find a way to specify where the ".sln" file will be generated.

Here is the command I use :

include(ExternalProject)
set(LIBRARY_SOURCE_DIR C:/Library)
ExternalProject_Add(Library
  SOURCE_DIR        "${LIBRARY_SOURCE_DIR}"
  CMAKE_ARGS
      -DCMAKE_BUILD_TARGET_ANDROID:BOOL=ON
      -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} 
      -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} 
      -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
      -DCMAKE_CONFIGURATION_TYPES=${CMAKE_CONFIGURATION_TYPES}
      -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
      -G@CMAKE_GENERATOR@
  BUILD_COMMAND     ""
)

So, I looking for a way to directly specify it in this call. Any idea ?

I also tried, but no way:

  PREFIX            LibraryBuild
  SOURCE_DIR        "${LIBRARY_SOURCE_DIR}"
  BINARY_DIR        "${LIBRARY_SOURCE_DIR}/LibraryBuild"
  INSTALL_DIR       "${LIBRARY_SOURCE_DIR}/LibraryBuild"
  BUILD_COMMAND     "cmake --build ./LibraryBuild"
  CMAKE_ARGS
      -DCMAKE_RUNTIME_OUTPUT_DIRECTORY="./LibraryBuild"
      -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="./LibraryBuild"
      -DCMAKE_EXECUTABLE_OUTPUT_DIRECTORY="./LibraryBuild"
      "./LibraryBuild"
      -DCMAKE_CURRENT_BINARY_DIR="./LibraryBuild"
      -DCMAKE_GENERATOR="Visual Studio 15 2017 Win64"
RAM
  • 2,257
  • 2
  • 19
  • 41
CDZ
  • 813
  • 1
  • 11
  • 27
  • Have you tried the `BINARY_DIR` option? (Listed under the build step for some reason). – Angew is no longer proud of SO Mar 30 '17 at 11:59
  • Thanks, yes I tried BINARY_DIR but it does not help. – CDZ Mar 30 '17 at 12:02
  • Remove that line: `-DCMAKE_CURRENT_BINARY_DIR="./LibraryBuild"`. Variable *CMAKE_CURRENT_BINARY_DIR* should be assumed as *read-only*. But you may add `-DCMAKE_INSTALL_PREFIX=` line: CMake doesn't do that automatically. Where `.sln` file is generated in your case? – Tsyvarev Mar 30 '17 at 12:22
  • Thanks. I tried but no luck ! So, everything is generated in the same folder than the main cmakelists.txt file ! – CDZ Mar 30 '17 at 12:37

1 Answers1

0

Do give it a BINARY_DIR, but do NOT give it a BUILD_COMMAND. Giving it an empty BUILD_COMMAND means "do nothing" for the build step and using "cmake --build ./LibraryBuild" does not work unless cmake is in your PATH, and with a Visual Studio solution, you also need to specify "--config Release" or "--config Debug".

If you leave off BUILD_COMMAND entirely for CMake-driven projects, CMake will produce a correct default build command for the CMAKE_GENERATOR used.

Also, I would strongly encourage you to use different values for BINARY_DIR and INSTALL_DIR. They should not overlap. I would recommend you make the INSTALL_DIR a subdirectory or a sibling directory of BINARY_DIR if it's not a canonical install (i.e. under "/usr" or "C:/Program Files...")

DLRdave
  • 13,876
  • 4
  • 53
  • 70
  • Thanks a lot, but it does not work. I only set BINARY_DIR and the .sln file and other files are generated in the cmakelists.txt folder ! – CDZ Mar 30 '17 at 14:28
  • This sounds like you have an accidental in-source build (CMakeCache.txt file and other CMake generated files **in the source tree**) -- if you set BINARY_DIR and start from a fresh source tree which does not contain CMakeCache.txt, then it should work. – DLRdave Mar 30 '17 at 19:18
  • Also, I have try with a sample, just a main and a lib. But it seems that the lib CMakeLists.txt file is not called ! The project is created, but it does not point to the source code by example and the "message" are not displayed in the console too ! The download link : https://www.dropbox.com/s/eto84gwtw2rx8oe/CMakeTest.zip?dl=0 – CDZ Mar 31 '17 at 08:59
  • BTW, I have try to debug ExternalProject.cmake and I got the following values from the function "ExternalProject_Add_Step". I don't see where the args are by example, CMAKE_ARGS is empty ! – CDZ Mar 31 '17 at 12:29
  • ` stamp_file=C:/Test/PhotonLibrary-prefix/src/PhotonLibrary-stamp/$(Configuration)/PhotonLibrary-build comment=Performing build step for 'PhotonLibrary' command=C:/Program Files/CMake/bin/cmake.exe --build C:/Test/../TestLib --config Release touch=C:/Program Files/CMake/bin/cmake.exe-EtouchC:/Test/PhotonLibrary-prefix/src/PhotonLibrary-stamp/$(Configuration)/PhotonLibrary-build depends=C:/Test/PhotonLibrary-prefix/src/PhotonLibrary-stamp/$(Configuration)/PhotonLibrary-configure work_dir=C:/Test/../TestLib CMAKE_CONFIGURATION_TYPES =DebugReleaseMinSizeRelRelWithDebInfo ` – CDZ Mar 31 '17 at 12:30