Re: [CMake] CMake with two C++ compilers
Hi John, Two different compilers in the same project for the same language is messy, but in your case it's directly supproted as a special case for cuda using the CMAKE_CUDA_HOST_COMPILER CMake variable or the CUDAHOSTCXX environment variable. -- Chuck Atkins Staff R Engineer, Scientific Computing Kitware, Inc. On Wed, May 8, 2019 at 7:27 AM JR Cary wrote: > Is there a standard way to deal with 2 C++ compilers? Getting both > there versions, etc.? > > I need one compiler for compiling ordinary C++ code and a different > one to use as the host compiler for CUDA. > > Thx..John Cary > -- > > 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
Re: [CMake] Basic question how to find -lm include and lib dir with find_package or otherwise
Usually you don't need to use the full path to libm, and it's only needed sometimes depending on your compiler and toolchain. I typically use something like the following to deal with both the implicit and explicit scenarios: include(CheckCSourceCompiles) set(LIBM_TEST_SOURCE "#include\nfloat f; int main(){sqrt(f);return 0;}") check_c_source_compiles("${LIBM_TEST_SOURCE}" HAVE_MATH) if(HAVE_MATH) set(LIBM_LIBRARIES) else() set(CMAKE_REQUIRED_LIBRARIES m) check_c_source_compiles("${LIBM_TEST_SOURCE}" HAVE_LIBM_MATH) unset(CMAKE_REQUIRED_LIBRARIES) if(NOT HAVE_LIBM_MATH) message(FATAL_ERROR "Unable to use C math library functions") endif() set(LIBM_LIBRARIES m) endif() target_link_libraries(fooTarget PRIVATE ${LIBM_LIBRARIES}) -- Chuck Atkins Staff R Engineer, Scientific Computing Kitware, Inc. On Fri, Mar 15, 2019 at 7:46 AM frodak17 wrote: > > > On Thu, Mar 14, 2019 at 8:53 PM workbe...@gmx.at wrote: > >> Hi everyone, >> >> i'm searching for a way to find the right include dir so that -lm can be >> found, the is not find_package for this, is /usr/lib and /usr/include a >> default because he find it without me adding any include or lib path for >> the build. >> >> >> > It seems strange that you need to do this. In my experience 'm' is just > the math portion of the 'c' library. Depending on which host and toolset > you are using there can be multiple version of the 'm' library depending on > target architecture and other options used. The linker should just use the > correct 'm' library just as it uses the correct 'c' library. It could be > in /usr/lib depending on how the compiler was packaged for your host. > -- > > 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
Re: [CMake] cmake cannot find source file (new to cmake)
> > When I ran "cmake .." in bin, cmake complained that it could not find > source file src1.h in add_executable. What is wrong here? > Hi Lei, Alex hit several of these points, but to wrap it up together: A couple of things... - There's no need for a CMakeLists.txt in a directory if it's not actually going to do anything. i.e. if you're not adding targets or executing any other CMake code then just traversing the directories doesn't serve any particular purpose. - The list of source files that a target uses to build don't have to necessarily be full paths, they can be absolute or relative paths, but the relative paths need to be relative to where the target is created, i.e. the add_executable(...) call. So in your case, the target is "exec" in the "src" folder so all paths to source files, if relative paths and not absolute paths, need to be relative to the src directory. - include_directories is the older style CMake and will apply to all targets created after it. Use target_include_directories instead for the more modern target-centric approach of having commands only apply to the appropriate target instead of globally. - Rather than use a list of sources, you can also use the target_sources command to programmatically add source files to a target based on necessary logic. The same restriction applies though that the sources added need to be relative to the target location or an absolute path. - The preferred project layout for CMake is to really have out-of-source builds. So instead having bin as a sub-directory of your project, just eliminate that level entirely. You can certainly create your structure however you want but that's the suggested and preferred way of organising. Combining these things, you could have nested CMakeLists.txt in which the subdirectories are explicitly adding the sources: - Top Level: - CMakeLists.txt cmake_minimum_required(VERSION 3.8) project(proj) add_executable(exec) add_subdirectory(common) add_subdirectory(dir1) - common/ - src1.h - CMakeLists.txt target_include_directories(exec PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_sources(exec PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src1.h) - dir1/ - src1.c - src2.c - CMakeLists.txt target_sources(exec PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src1.c ${CMAKE_CURRENT_SOURCE_DIR}/src2.c ) Or a much simpler single file where no nested CMakeLists.txt are needed since they wouldn't be doing anything: - Top Level: - CMakeLists.txt cmake_minimum_required(VERSION 3.8) project(proj) add_executable(exec common/src1.h dir1/src1.c dir1/src2.c ) target_include_directories(exec common) - common/ - src1.h - dir1/ - src1.c - src2.c Both are valid, the first is overkill for this simple example but illustrates a way of doing things that can be helpful with much more complex projects. Either way, you also have a build directory completely detached and outside your source tree instead of a sub-directory. - Chuck -- 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