취미는 놀기

Visual studio solution build of CMake 본문

개발 (Develop)/Tip

Visual studio solution build of CMake

취미는놀기 2020. 8. 18. 12:19

CMake 3.18을 통한 Visual Studio Solution 빌드

(Visual studio solution build of CMake)

 

1. CMake install

https://cmake.org/download/

 

Download | CMake

Current development distribution Each night binaries are created as part of the testing process. Other than passing all of the tests in CMake, this version of CMake should not be expected to work in a production environment. It is being produced so that us

cmake.org

 

 

 

cmake msi downlaod

2. cmake command

 

[Windows key] + [R] , cmd

 

cmake --help

 

많이 사용되는 command 입니다.

many use commnd = -B, -G, --build, --install --config

 

 

cmake --help

그리고 Visual studio solution version 은 아래에 있습니다.

Version generate에 따라 insert msg가 달라집니다.

 

  Visual Studio 16 2019        = Generates Visual Studio 2019 project files.
                                 Use -A option to specify architecture.
* Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
                                 Optional [arch] can be "Win64" or "IA64".
  Visual Studio 9 2008 [arch]  = Generates Visual Studio 2008 project files.
                                 Optional [arch] can be "Win64" or "IA64".

 

cmake --help

3. CMake source tree

cmake source tree

4. CMake source for line by line description

#Windwos
#cmake -G
#cmd : cmake -H. -B_builds -G "Visual Studio 12 2013 Win64"
#build for Release
#cmd : cmake --build _builds --config Release
#build for Debug
#cmd : cmake --build _builds --config Debug
# CMake version
cmake_minimum_required(VERSION 3.18)
# visual studio project name, language CXX = C++
project(test LANGUAGES CXX)

################################################################################
# Target Souce
################################################################################
#Visual studio solution source file lists
#Only cpp file, XX.c trace XX.cpp !
set(SOURCE
	"abc.cpp"
	"def.cpp"
	"gef.cpp"
	"aa.cpp"
	"bb.cpp"
	"cc.cpp"
)
source_group("source file" FILES ${SOURCE})

#Visual studio solution header file lists
set(HEADER
	"abc.h"
	"def.h"
	"gef.h"
	"aa.h"
	"bb.h"
	"cc.h"
)	source_group("header file" FILES ${HEADER})

set(ALL_FILES
	${SOURCE}
	${HEADER}
)

################################################################################
# Build Type
################################################################################
#set(CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Configuration type" FORCE)

################################################################################
# Target
################################################################################
#RUNFILE = .exe
#add_executable(${PROJECT_NAME} ${ALL_FILES})

#SHARED Lib = .dll
add_library(${PROJECT_NAME} SHARED
  ${ALL_FILES})

##STATIC Lib = .lib
#	add_library(${PROJECT_NAME} STATIC
#	 ${ALL_FILES})
#
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)

set_target_properties(${PROJECT_NAME} PROPERTIES
	INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE"
)
################################################################################
# Include directories //AdditionalIncludeDirectories(test.vcxproj read)
################################################################################
target_include_directories(${PROJECT_NAME} PUBLIC
	"${CMAKE_CURRENT_SOURCE_DIR}/..;"
	"${CMAKE_CURRENT_SOURCE_DIR}/../dependency/sqlite/include;"
)

################################################################################
# Compile definitions //PreprocessorDefinitions(test.vcxproj read)
################################################################################
target_compile_definitions(${PROJECT_NAME} PRIVATE
	"_CRT_SECURE_NO_WARNINGS;"
)

################################################################################
# Compile and link options
################################################################################
target_compile_options(${PROJECT_NAME} PRIVATE
	$<$<CONFIG:Release>:
		/O2;
		/Oi;
		/MT;
		/Gy
	>
	/sdl;
	/W3;
	${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT};
	${DEFAULT_CXX_EXCEPTION_HANDLING}
)
target_link_options(${PROJECT_NAME} PRIVATE
	$<$<CONFIG:Release>:
		/OPT:REF;
		/OPT:ICF
	>
)

################################################################################
# Post build events // Not working 
################################################################################
#add_custom_command(
#	TARGET ${PROJECT_NAME}
#	POST_BUILD
#	COMMANDS
#	COMMAND mkdir "$<SHELL_PATH:${OUTPUT_DIRECTORY}>\\build"
#	COMMAND copy "$<SHELL_PATH:${OUTPUT_DIRECTORY}>${TARGET_NAME}$ENV{TargetExt}" "$<SHELL_PATH:${OUTPUT_DIRECTORY}>\\build\\"
#
#)


################################################################################
# Dependencies Files// AdditionalDependencies (test.vcxproj read)
################################################################################
set(ADDITIONAL_LIBRARY_DEPENDENCIES
	"$<$<CONFIG:Release>:"
		"kernel32;"
		"user32;"
		"gdi32;"
		"winspool;"
		"comdlg32;"
		"advapi32;"
		"shell32;"
		"ole32;"
		"oleaut32;"
		"uuid;"
		"odbc32;"
		"odbccp32;"
		"sqlite3"
	">"
)
target_link_libraries(${PROJECT_NAME} PUBLIC "${ADDITIONAL_LIBRARY_DEPENDENCIES}")

################################################################################
# Dependencie Directories// AdditionalDependencies (test.vcxproj read)
################################################################################
# //AdditionalLibraryDirectories (test.vcxproj read)
target_link_directories(${PROJECT_NAME} PUBLIC
	"$<$<CONFIG:Release>:"
		"${CMAKE_CURRENT_SOURCE_DIR}/../x64/Release;"
		"${CMAKE_CURRENT_SOURCE_DIR}/../dependency/sqlite/lib/WINDOWS/64;"
	">"
)

################################################################################
# Install
################################################################################
#install is source post build, (CODE,TARGET FILES)

if(BIT64)
  set(OS_ARCH_STR "64")
else()
  set(OS_ARCH_STR "32")
endif()

#Target Install test.dll and test.lib
#Target Result = test.lib and test.dll
install(TARGETS test DESTINATION  ${CMAKE_CURRENT_SOURCE_DIR}/../x64/Release/)

#FILES copy destination
#FILES DLL = result test.lib move to destination
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../x64/Release/test.dll DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../install)

#WSL bash command using
install(CODE "execute_process(COMMAND bash ./../test.sh -u -o ${OS_NAME} -a ${OS_ARCH_STR})")
message(STATUS "bash ./../test.sh -o ${OS_NAME} -a ${OS_ARCH_STR}")

5. CMake Generate

cmd> cmake -H. -B_builds -G "Visual Studio 12 2013 Win64"

 

6. CMake Build

Config = Release

cmd> cmake -H. -B_builds -G "Visual Studio 12 2013 Win64"cmake --build _builds --config Release

 

Config = Debug

cmd> cmake -H. -B_builds -G "Visual Studio 12 2013 Win64"cmake --build _builds --config Debug

'개발 (Develop) > Tip' 카테고리의 다른 글

HP-UX  (0) 2020.07.02
[google test] 설치 및 간단 test  (0) 2019.02.14
Comments