[CMake] Suggestion for CMake platform/compiler detection

Tanguy Krotoff tanguy.krotoff at wengo.fr
Fri Nov 17 05:59:05 EST 2006


Brandon J. Van Every wrote:
> People who feel neutral about Autoconf, or who are in fact pleased with 
> it, aren't going to up and do anything for Windows anytime soon.  For 
> those people, it will take a *long* time for migrations to happen via 
> CMake.

I do not agree, yes it will take time but if you provide a much better 
tool that the existant one (+ in some extend is compatible with the old 
one), developers will switch.

We can reduce migration time by simply providing a very nice and simple 
API for building software using CMake, and the first step is to fix 
little things like:

if (GCC) and not if (CMAKE_COMPILER_IS_GNUCXX)
if (ICC) and not if (CMAKE_C_COMPILER MATCHES "icc")

an API should be *consistent*, if you choose to have
if (MSVC)
if (MINGW)
then you should have if (GCC), if (ICC)...

And saying "there's coverage, it's just ad hoc, not canonized, and has 
an inconsistent interface.  At present this doesn't trouble me, 
personally" won't help
CMake users don't care about CMake, they only care about building their 
software and they don't want to google/read the doc because if (MSVC) 
works and if (GCC) or if (ICC) don't as they expected.

A more important issue, you can write:
add_definitions(${DEF})
include_directories(${INC})

but you cannot write:
add_compile_flags(${FLAGS})
add_link_flags(${FLAGS})
!!!!

No this would be too simple... so you have to check the doc, google and 
finally find out that it works in a totally different way!
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS ${FLAGS})


Your answer will probably be "not happy? send a patch!"

and here is my patch:
http://dev.openwengo.org/trac/openwengo/trac.cgi/wiki/OWBuild
http://dev.openwengo.org/trac/openwengo/trac.cgi/browser/wengophone-ng/trunk/cmake/Modules/owbuild

This permits me to create build scripts for cURL, PortAudio, libGaim... 
in 1h, check how simple they are !
Even somebody who never heard about CMake can understand them...

Since I have a very high level API, I can do very high level things like 
choosing from the cache if I want a shared or a static library (and 
don't tell me the problem is a simple -DMYPROJECT_EXPORTS), copy 
automatically files on the fly, integrate an inheritance system...

It's not fully finished yet, I have to write more doc + test deeply the 
macros

Now I'm scratching my head: do I extend my macros and add if 
(OS_WINDOWS), if (OS_MACOSX), if (OS_LINUX), if (CC_MSVC), if 
(CC_GCC)... or do I stick with if (APPLE), if (CMAKE_COMPILER_IS_GNUCXX) 
and if (CMAKE_C_COMPILER MATCHES "icc")??


CMake is a wonderful tool, very glad people are developing it but please 
create a simple, consistent and high-level API and then people will switch

-- 
Tanguy Krotoff <tanguy.krotoff at wengo.fr>
http://openwengo.org
-------------- next part --------------
ow_create_shared_library(curl)

ow_use_private_libraries(
	OPENSSL
)

ow_add_public_include_dirs(
	${CMAKE_CURRENT_SOURCE_DIR}/include
)

ow_add_private_include_dirs(
	${CMAKE_CURRENT_SOURCE_DIR}/lib
)

ow_add_private_definitions(
	-DBUILDING_LIBCURL
	-DCURL_DISABLE_FILE
	-DCURL_DISABLE_LDAP
	-DCURL_DISABLE_DICT
	-DCURL_DISABLE_TELNET
	-DCURL_DISABLE_TFTP
	-DUSE_SSLEAY
	-DUSE_OPENSSL
)

if (APPLE)
	find_package(ZLIB REQUIRED)

	ow_use_public_libraries(
		ZLIB
	)
endif (APPLE)

if (WIN32)
	ow_add_private_libraries(
		ws2_32
		winmm
	)
endif (WIN32)

ow_add_sources(
	lib/base64.c
	lib/connect.c
	lib/content_encoding.c
	lib/cookie.c
	#lib/dict.c
	lib/easy.c
	lib/escape.c
	#lib/file.c
	lib/formdata.c
	lib/ftp.c
	lib/getenv.c
	lib/getinfo.c
	lib/gtls.c
	lib/hash.c
	lib/hostares.c
	lib/hostasyn.c
	lib/hostip.c
	lib/hostip4.c
	lib/hostip6.c
	lib/hostsyn.c
	lib/hostthre.c
	lib/http.c
	lib/http_chunks.c
	lib/http_digest.c
	lib/http_negotiate.c
	lib/http_ntlm.c
	lib/if2ip.c
	lib/inet_ntop.c
	lib/inet_pton.c
	lib/krb4.c
	#lib/ldap.c
	lib/llist.c
	lib/md5.c
	lib/memdebug.c
	lib/mprintf.c
	lib/multi.c
	lib/netrc.c
	#lib/nwlib.c
	lib/parsedate.c
	lib/progress.c
	lib/security.c
	lib/select.c
	lib/sendf.c
	lib/share.c
	lib/speedcheck.c
	lib/sslgen.c
	lib/ssluse.c
	lib/strequal.c
	lib/strerror.c
	lib/strtok.c
	lib/strtoofft.c
	#lib/telnet.c
	#lib/tftp.c
	lib/timeval.c
	lib/transfer.c
	lib/url.c
	lib/version.c
)

ow_create_binary()
-------------- next part --------------
ow_create_static_library(gaim)

ow_use_public_libraries(
	GLIB2
)

ow_add_public_include_dirs(
	${CMAKE_CURRENT_SOURCE_DIR}/include
	${CMAKE_CURRENT_SOURCE_DIR}/src/libgaim
)

ow_add_private_include_dirs(
	${CMAKE_CURRENT_SOURCE_DIR}/src
	${CMAKE_CURRENT_SOURCE_DIR}/src/libgaim/protocols/oscar
)

ow_use_private_libraries(
	XML2
)

ow_add_private_libraries(
	resolv
	gnutls
)

ow_add_private_definitions(
	-DHAVE_CONFIG_H
	-DHAVE_GLIB
	-DGAIM_STATIC_PRPL
	-DHAVE_SSL
	-DHAVE_GNUTLS
)

ow_add_sources(
	src/libgaim/account.c
	src/libgaim/accountopt.c
	src/libgaim/blist.c
	src/libgaim/buddyicon.c
	src/libgaim/cipher.c
	src/libgaim/circbuffer.c
	src/libgaim/cmds.c
	src/libgaim/connection.c
	src/libgaim/conversation.c
	src/libgaim/core.c
	src/libgaim/debug.c
	src/libgaim/desktopitem.c
	src/libgaim/dnsquery.c
	src/libgaim/dnssrv.c
	src/libgaim/eventloop.c
	src/libgaim/ft.c
	src/libgaim/getopt.c
	src/libgaim/getopt1.c
	src/libgaim/idle.c
	src/libgaim/imgstore.c
	src/libgaim/log.c
	src/libgaim/mime.c
	src/libgaim/network.c
	src/libgaim/notify.c
	src/libgaim/ntlm.c
	src/libgaim/plugin.c
	src/libgaim/pluginpref.c
	src/libgaim/pounce.c
	src/libgaim/prefix.c
	src/libgaim/prefs.c
	src/libgaim/privacy.c
	src/libgaim/proxy.c
	src/libgaim/prpl.c
	src/libgaim/request.c
	src/libgaim/roomlist.c
	src/libgaim/savedstatuses.c
	src/libgaim/server.c
	src/libgaim/signals.c
	src/libgaim/sound.c
	src/libgaim/sslconn.c
	src/libgaim/status.c
	src/libgaim/stringref.c
	src/libgaim/stun.c
	src/libgaim/upnp.c
	src/libgaim/util.c
	src/libgaim/value.c
	src/libgaim/whiteboard.c
	src/libgaim/xmlnode.c
	src/libgaim/plugins/ssl/ssl.c
	src/libgaim/plugins/ssl/ssl-gnutls.c
	src/libgaim/protocols/jabber/auth.c
	src/libgaim/protocols/jabber/buddy.c
	src/libgaim/protocols/jabber/chat.c
	src/libgaim/protocols/jabber/disco.c
	src/libgaim/protocols/jabber/iq.c
	src/libgaim/protocols/jabber/jabber.c
	src/libgaim/protocols/jabber/jutil.c
	src/libgaim/protocols/jabber/message.c
	src/libgaim/protocols/jabber/oob.c
	src/libgaim/protocols/jabber/parser.c
	src/libgaim/protocols/jabber/presence.c
	src/libgaim/protocols/jabber/roster.c
	src/libgaim/protocols/jabber/si.c
	src/libgaim/protocols/jabber/xdata.c
	src/libgaim/protocols/msn/cmdproc.c
	src/libgaim/protocols/msn/command.c
	src/libgaim/protocols/msn/dialog.c
	src/libgaim/protocols/msn/directconn.c
	src/libgaim/protocols/msn/error.c
	src/libgaim/protocols/msn/group.c
	src/libgaim/protocols/msn/history.c
	src/libgaim/protocols/msn/httpconn.c
	src/libgaim/protocols/msn/msg.c
	src/libgaim/protocols/msn/msn.c
	src/libgaim/protocols/msn/nexus.c
	src/libgaim/protocols/msn/notification.c
	src/libgaim/protocols/msn/object.c
	src/libgaim/protocols/msn/page.c
	src/libgaim/protocols/msn/servconn.c
	src/libgaim/protocols/msn/session.c
	src/libgaim/protocols/msn/slp.c
	src/libgaim/protocols/msn/slpcall.c
	src/libgaim/protocols/msn/slplink.c
	src/libgaim/protocols/msn/slpmsg.c
	src/libgaim/protocols/msn/slpsession.c
	src/libgaim/protocols/msn/state.c
	src/libgaim/protocols/msn/switchboard.c
	src/libgaim/protocols/msn/sync.c
	src/libgaim/protocols/msn/table.c
	src/libgaim/protocols/msn/transaction.c
	src/libgaim/protocols/msn/user.c
	src/libgaim/protocols/msn/userlist.c
	src/libgaim/protocols/msn/msn-utils.c
	src/libgaim/protocols/oscar/bstream.c
	src/libgaim/protocols/oscar/family_admin.c
	src/libgaim/protocols/oscar/family_advert.c
	src/libgaim/protocols/oscar/family_alert.c
	src/libgaim/protocols/oscar/family_auth.c
	src/libgaim/protocols/oscar/family_bart.c
	src/libgaim/protocols/oscar/family_bos.c
	src/libgaim/protocols/oscar/family_buddy.c
	src/libgaim/protocols/oscar/family_chat.c
	src/libgaim/protocols/oscar/family_chatnav.c
	src/libgaim/protocols/oscar/family_feedbag.c
	src/libgaim/protocols/oscar/family_icbm.c
	src/libgaim/protocols/oscar/family_icq.c
	src/libgaim/protocols/oscar/family_invite.c
	src/libgaim/protocols/oscar/family_locate.c
	src/libgaim/protocols/oscar/family_odir.c
	src/libgaim/protocols/oscar/family_oservice.c
	src/libgaim/protocols/oscar/family_popup.c
	src/libgaim/protocols/oscar/family_stats.c
	src/libgaim/protocols/oscar/family_translate.c
	src/libgaim/protocols/oscar/family_userlookup.c
	src/libgaim/protocols/oscar/flap_connection.c
	src/libgaim/protocols/oscar/misc.c
	src/libgaim/protocols/oscar/msgcookie.c
	src/libgaim/protocols/oscar/odc.c
	src/libgaim/protocols/oscar/oft.c
	src/libgaim/protocols/oscar/oscar.c
	src/libgaim/protocols/oscar/oscar_data.c
	src/libgaim/protocols/oscar/peer.c
	src/libgaim/protocols/oscar/peer_proxy.c
	src/libgaim/protocols/oscar/rxhandlers.c
	src/libgaim/protocols/oscar/snac.c
	src/libgaim/protocols/oscar/tlv.c
	src/libgaim/protocols/oscar/util.c
	src/libgaim/protocols/yahoo/util.c
	src/libgaim/protocols/yahoo/yahoo.c
	src/libgaim/protocols/yahoo/yahoo_auth.c
	src/libgaim/protocols/yahoo/yahoo_crypt.c
	src/libgaim/protocols/yahoo/yahoo_doodle.c
	src/libgaim/protocols/yahoo/yahoo_filexfer.c
	src/libgaim/protocols/yahoo/yahoo_friend.c
	src/libgaim/protocols/yahoo/yahoo_packet.c
	src/libgaim/protocols/yahoo/yahoo_picture.c
	src/libgaim/protocols/yahoo/yahoo_profile.c
	src/libgaim/protocols/yahoo/yahoochat.c
	src/libgaim/protocols/yahoo/ycht.c
)

ow_create_binary()
-------------- next part --------------
ow_create_static_library(portaudio)

ow_add_public_include_dirs(
	${CMAKE_CURRENT_SOURCE_DIR}/pa_common
)

ow_add_private_definitions(
	-DPA_LITTLE_ENDIAN
	-DPA_NO_ASIO
	-DPA_NO_WDMKS
	-DPA_NO_DS
)

ow_add_sources(
	pa_common/pa_allocation.c
	pa_common/pa_converters.c
	pa_common/pa_cpuload.c
	pa_common/pa_dither.c
	pa_common/pa_front.c
	pa_common/pa_process.c
	pa_common/pa_skeleton.c
	pa_common/pa_stream.c
	pa_common/pa_trace.c
	pa_win/pa_win_util.c
	pa_win/pa_win_hostapis.c
	pa_win/pa_x86_plain_converters.c
)

if (WITH_PORTAUDIO_DSOUND)
	ow_add_sources(
		pa_win_ds/dsound_wrapper.c
		pa_win_ds/pa_win_ds.c
	)
else (WITH_PORTAUDIO_DSOUND)
	ow_add_sources(
		pa_win_wmme/pa_win_wmme.c
	)
endif (WITH_PORTAUDIO_DSOUND)

ow_create_binary()


More information about the CMake mailing list