[CMake] Beginners Guide to Cmake and Modern Cmake

2018-07-26 Thread Space
Dear Cmake world,

I am wanting to learn how to use Cmake correctly and I would like to
implement Modern Cmake (the latest version and techniques). 

Currently I have a project that was intended for use on windows machine but
I want to run/develop it on Mac and am also interested to make it overall
cross platform. On Mac I'll use Visual Studio Code and Xcode (preferably
VSC).

Here is a link to the GitHub for the current project of interest:
https://github.com/AcademyOfInteractiveEntertainment/aieBootstrap

Dependencies are:
glfw
glm
imgui
stb
openGL (gl_core_4_4.c/h)

I have visited the cmake.org site and looked at the tutorials, they teach
old cmake 2.8 but shouldn't there be material that teaches the Modern way. 

I know about the documentation that has made an effort to show some of the
modern practices but to a person, new to cmake, my brain just shuts down to
the reference styled documents, and yes, but thats what the documentation
is; a reference list.

I then found the webinars, but much disappoint, they are dated back to March
2012 ( a great effort for its time but left me confused; not modern). 

We are now end of July 2018. It would be great to see a webinar completely
refreshed, which is directed at the complete beginner and makes an effort to
teach Modern Cmake in todays world. It would also be nice to understand how
to bridge the gap between old 2.8 cmake and the latest cmake. For example:
Making proper use of find_package etc...

I hope this is an interesting topic to be reviewed,

regards,

Space





--
Sent from: http://cmake.3232098.n2.nabble.com/
-- 

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] Fwd: GLOB_RECURSE

2018-07-26 Thread Michael Hennebry
I finally found the ellipses.

On Wed, Jul 25, 2018 at 9:48 PM, J. Caleb Wherry  wrote:
> Latest CMake documentation can be found here:

> https://cmake.org/cmake/help/latest/command/file.html?highlight=glob_recurse#glob-recurse

That is what I was using, albeit badly.

> As for your issue, you are misunderstanding the purpose of RELATIVE. That
> means the paths you get path will be relative to that path, not that it
> searches from that path. So you are just searching for “*.cpp” and “*.c” in
> the CURRENT directory. That is why you are getting files in all the subdirs.
> As @frodak pointed out in his first example, you need to remove the RELATIVE
> and put the dir name you want like “./dir/*.cpp”.

Ah.  The top level directories are not list separately.

> Once you do that, you should be good to go. All of the above is explained
> pretty clearly in the linked docs.

Yes, they are.
My "interpretation" was too heavily influenced by an example even
worse than mine.

Thanks.
-- 

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] How do I use install() with targets that might not be built?

2018-07-26 Thread Francis Giraldeau
To customize the build and install, I would suggest to use an
install(TRAGET) wrapper for each target. It allows to define an option for
each of them.

* The list of targets must be recorded in a global property.
* The install option is constructed using the target name
* call generate_install_config() after all targets to get a template that
you can customize and use as cmake initial cache

You might be able to adapt this to your needs.

Cheers,



set_property(GLOBAL PROPERTY target_list)

# add_install_option must be a macro, if put in a function, the option does
# not exists right after being declared.
macro(add_install_option target)
string(TOUPPER ${target} TGT)
option(CONFIG_INSTALL_${TGT} "Install ${TGT}" ON)
get_property(tmp GLOBAL PROPERTY target_list)
list(APPEND tmp CONFIG_INSTALL_${TGT})
set_property(GLOBAL PROPERTY target_list ${tmp})
endmacro()

function(install_target_wrapper target)
  add_install_option(${target})
  if(CONFIG_INSTALL_${TGT})
  # message("CONFIG_INSTALL_${TGT}=${CONFIG_INSTALL_${TGT}}")
  install(TARGETS ${target}
  RUNTIME DESTINATION bin
  LIBRARY DESTINATION lib
  COMPONENT application
  )
  endif()
endfunction()

function(generate_install_config)
set(CONF "${CMAKE_BINARY_DIR}/InstallConfig.cmake")
file(WRITE "${CONF}" "# Automatically generated install config file.
Copy this file and edit to customize the installation.\n")
file(APPEND "${CONF}" "# Use to populate the initial cmake cache: cmake
-C InstallConfigForCustomer.cmake\n")
file(APPEND "${CONF}" "# EDIT VARIABLES BELOW\n")
get_property(tmp GLOBAL PROPERTY target_list)
list(SORT tmp)
foreach(ITEM ${tmp})
file(APPEND ${CONF} "set(${ITEM}_VALUE ${${ITEM}})\n")
endforeach()
file(APPEND "${CONF}" "#\n# DO NOT EDIT BELOW\n#\n")
foreach(ITEM ${tmp})
file(APPEND ${CONF} "set(${ITEM} \${${ITEM}_VALUE} CACHE BOOL
\"Install ${ITEM}\" FORCE)\n")
endforeach()
list(LENGTH tmp tmp_len)
message("-- Number of targets: ${tmp_len}")
endfunction()


Le mer. 25 juil. 2018 à 02:09, Jason Heeris  a
écrit :

> My project consists of a lot of "module" style targets (static libraries,
> more or less), but only a few top-level targets that a user would actually
> want to build. The "all" target is empty, that is, every target has
> "EXCLUDE_FROM_ALL" set. The user will, at compile time, decide to build
> whichever target they need. A single target may depend on a couple of
> others, so the end result of a single target being built might be eg. an
> exe file plus a dll plus a couple of other things.
>
> But I also want to provide installation capabilities, so users don't have
> to hunt down exes and libs scattered throughout CMake's build tree. I might
> want to create installers using CPack at some point too.
>
> How do I do this if all of my targets are EXCLUDE_FROM_ALL? According to
> the documentation, even if I use the OPTIONAL flag in install(), the
> behaviour is undefined. Better not do that.
>
> The only other option I see is to create custom commands (POST_BUILD
> style) for every target that copies it to some designated output directory.
> But then I can't take advantage of CMake's other installation capabilities,
> and I think that would be invisible to CPack.
>
> Is there some other way?
>
> I'm using CMake 3.12 on Windows 10/Ubuntu 18.04, if that's relevant.
>
> Cheers,
> Jason
> --
>
> 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
>
-- 
Francis Giraldeau
-- 

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


[CMake] order of includes seems wrong (or please help me understand)

2018-07-26 Thread Mario Emmenlauer

Dear CMake users and developers,

I've just discovered a build problem that comes from a wrong order of
includes. I would know the correct order, but I am unable to instruct
CMake to use the order I need.

Here is a toy example that I tested with cmake 3.12.0:



cmake_minimum_required(VERSION 3.8)
project(MyLib VERSION 1.0.0)
find_package(XXX REQUIRED)
find_package(YYY REQUIRED)
add_library(${PROJECT_NAME} include/MyLib.hh src/MyLib.cc)
target_include_directories(${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
PUBLIC
$
$
${XXX_INCLUDE_DIRS} ${YYY_INCLUDE_DIRS})
target_link_libraries(MyLib PUBLIC ${XXX_LIBRARIES} ${YYY_LIBRARIES})
# here come more commands for build flags etc.

enable_testing()
add_executable(MyTest test/src/MyTest.cc test/src/MyTest.hh)
target_include_directories(MyTest PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/test/src
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
${GTEST_INCLUDE_DIRS})
target_link_libraries(MyTest PRIVATE MyLib ${GTEST_MAIN_LIBRARIES})
# here come more commands for build flags etc.



I configure cmake with -DCMAKE_PREFIX_PATH=${MY_PREFIX_PATH}. When
I build the project, the order of includes for MyLib is fine. But
for MyTest, the following are the first two includes:
   -IMyTest_autogen/include
   -I${MY_PREFIX_PATH}/include

I think the second include should come much later, only *after*
${CMAKE_CURRENT_SOURCE_DIR}/include, but it comes before. Therefore,
if older headers exists in ${MY_PREFIX_PATH}/include, they will be
used instead of ${CMAKE_CURRENT_SOURCE_DIR}/include!

I found that I can fix the problem by adding 'BEFORE' to all
target_include_directories(). However I'm puzzled why this helps.
Before anything I call target_include_directories(), and before other
includes I have ${CMAKE_CURRENT_SOURCE_DIR}/src,
${CMAKE_CURRENT_BINARY_DIR} and ${CMAKE_CURRENT_SOURCE_DIR}/include.
So what does 'BEFORE' mean in this case? Aren't these the first
includes any ways?

Thanks for any help, and Cheers,

Mario Emmenlauer


--
BioDataAnalysis GmbH, Mario Emmenlauer  Tel. Buero: +49-89-74677203
Balanstr. 43   mailto: memmenlauer * biodataanalysis.de
D-81669 München  http://www.biodataanalysis.de/
-- 

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